make.sh: Determine how much memory the build host has
[ipfire-2.x.git] / tools / make-functions
CommitLineData
15679d9f 1#!/bin/bash
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
6378290f 5# Copyright (C) 2007-2016 IPFire Team <info@ipfire.org> #
70df8302
MT
6# #
7# This program is free software: you can redistribute it and/or modify #
8# it under the terms of the GNU General Public License as published by #
9# the Free Software Foundation, either version 3 of the License, or #
10# (at your option) any later version. #
11# #
12# This program is distributed in the hope that it will be useful, #
13# but WITHOUT ANY WARRANTY; without even the implied warranty of #
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
15# GNU General Public License for more details. #
16# #
17# You should have received a copy of the GNU General Public License #
18# along with this program. If not, see <http://www.gnu.org/licenses/>. #
19# #
20###############################################################################
21###############################################################################
15679d9f
MT
22#
23# Beautifying variables & presentation & input output interface
24#
70df8302 25###############################################################################
15679d9f
MT
26
27## Screen Dimentions
28# Find current screen size
29if [ -z "${COLUMNS}" ]; then
30 COLUMNS=$(stty size)
31 COLUMNS=${COLUMNS##* }
32fi
33
34# When using remote connections, such as a serial port, stty size returns 0
35if [ "${COLUMNS}" = "0" ]; then
36 COLUMNS=80
37fi
38
39## Measurements for positioning result messages
40RESULT_WIDTH=4
41TIME_WIDTH=8
42OPT_WIDTH=6
43VER_WIDTH=10
44RESULT_COL=$((${COLUMNS} - $RESULT_WIDTH - 4))
45TIME_COL=$((${RESULT_COL} - $TIME_WIDTH - 5))
46OPT_COL=$((${TIME_COL} - $OPT_WIDTH - 5))
47VER_COL=$((${OPT_COL} - $VER_WIDTH - 5))
48
49## Set Cursur Position Commands, used via echo -e
50SET_RESULT_COL="\\033[${RESULT_COL}G"
51SET_TIME_COL="\\033[${TIME_COL}G"
52SET_OPT_COL="\\033[${OPT_COL}G"
53SET_VER_COL="\\033[${VER_COL}G"
54
55# Define color for messages
56BOLD="\\033[1;39m"
57DONE="\\033[1;32m"
58SKIP="\\033[1;34m"
59WARN="\\033[1;35m"
60FAIL="\\033[1;31m"
61NORMAL="\\033[0;39m"
62
5190eea2
MT
63system_memory() {
64 local key val unit
65
66 while read -r key val unit; do
67 case "${key}" in
68 MemTotal:*)
69 # Convert to MB
70 echo "$(( ${val} / 1024 ))"
71 break
72 ;;
73 esac
74 done < /proc/meminfo
75}
76
dc7d6b20
MT
77configure_build() {
78 local build_arch="${1}"
bcb9dc13 79
dc7d6b20
MT
80 if [ "${build_arch}" = "default" ]; then
81 build_arch="$(configure_build_guess)"
bcb9dc13
MT
82 fi
83
dc7d6b20 84 case "${build_arch}" in
fc155193 85 x86_64)
dc7d6b20
MT
86 BUILDTARGET="${build_arch}-unknown-linux-gnu"
87 CROSSTARGET="${build_arch}-cross-linux-gnu"
88 BUILD_PLATFORM="x86"
fc155193
MT
89 CFLAGS_ARCH="-m64 -mtune=generic"
90 ;;
91
bcb9dc13 92 i586)
dc7d6b20
MT
93 BUILDTARGET="${build_arch}-pc-linux-gnu"
94 CROSSTARGET="${build_arch}-cross-linux-gnu"
95 BUILD_PLATFORM="x86"
da3dbb2a 96 CFLAGS_ARCH="-march=i586 -mtune=generic -fomit-frame-pointer"
bcb9dc13
MT
97 ;;
98
bab5ff7c 99 aarch64)
dc7d6b20
MT
100 BUILDTARGET="${build_arch}-unknown-linux-gnu"
101 CROSSTARGET="${build_arch}-cross-linux-gnu"
102 BUILD_PLATFORM="arm"
bab5ff7c
MT
103 CFLAGS_ARCH=""
104 ;;
105
4162dbae 106 armv7hl)
dc7d6b20
MT
107 BUILDTARGET="${build_arch}-unknown-linux-gnueabi"
108 CROSSTARGET="${build_arch}-cross-linux-gnueabi"
109 BUILD_PLATFORM="arm"
ff92f1ac 110 CFLAGS_ARCH="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
4162dbae
MT
111 ;;
112
bcb9dc13 113 armv5tel)
dc7d6b20
MT
114 BUILDTARGET="${build_arch}-unknown-linux-gnueabi"
115 CROSSTARGET="${build_arch}-cross-linux-gnueabi"
116 BUILD_PLATFORM="arm"
bcb9dc13 117 CFLAGS_ARCH="-march=armv5te -mfloat-abi=soft -fomit-frame-pointer"
bcb9dc13
MT
118 ;;
119
120 *)
dc7d6b20 121 exiterror "Cannot build for architure ${build_arch}"
bcb9dc13
MT
122 ;;
123 esac
124
125 # Check if the QEMU helper is available if needed.
dc7d6b20
MT
126 if qemu_is_required "${build_arch}"; then
127 local qemu_build_helper="$(qemu_find_build_helper_name "${build_arch}")"
bcb9dc13 128
dc7d6b20
MT
129 if [ -n "${qemu_build_helper}" ]; then
130 QEMU_TARGET_HELPER="${qemu_build_helper}"
bcb9dc13 131 else
dc7d6b20 132 exiterror "Could not find a binfmt_misc helper entry for ${build_arch}"
bcb9dc13
MT
133 fi
134 fi
135
dc7d6b20 136 BUILD_ARCH="${build_arch}"
bcb9dc13 137
e259f335
MT
138 # Enables hardening
139 HARDENING_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4"
140
141 CFLAGS="-O2 -pipe -Wall -fexceptions -fPIC ${CFLAGS_ARCH}"
bcb9dc13 142 CXXFLAGS="${CFLAGS}"
bcb9dc13
MT
143}
144
dc7d6b20
MT
145configure_build_guess() {
146 case "${HOST_ARCH}" in
bcb9dc13
MT
147 x86_64|i686|i586)
148 echo "i586"
149 ;;
16449f75
MT
150
151 aarch64)
152 echo "aarch64"
153 ;;
154
4162dbae
MT
155 armv7*)
156 echo "armv7hl"
157 ;;
158
159 armv6*|armv5*)
bcb9dc13
MT
160 echo "armv5tel"
161 ;;
4162dbae 162
bcb9dc13 163 *)
dc7d6b20 164 exiterror "Cannot guess build architecture"
bcb9dc13
MT
165 ;;
166 esac
167}
168
15679d9f
MT
169evaluate() {
170 if [ "$?" -eq "0" ]; then
171 beautify message DONE
172 else
173 EXITCODE=$1
174 shift 1
175 beautify message FAIL
176 $*
177 if [ $EXITCODE -ne "0" ]; then
178 exit $EXITCODE
179 fi
180 fi
181}
182
183position_cursor()
184{
185 # ARG1=starting position on screen
186 # ARG2=string to be printed
187 # ARG3=offset, negative for left movement, positive for right movement, relative to ARG1
188 # For example if your starting position is column 50 and you want to print Hello three columns to the right
189 # of your starting position, your call will look like this:
190 # position_cursor 50 "Hello" 3 (you'll get the string Hello at position 53 (= 50 + 3)
191 # If on the other hand you want your string "Hello" to end three columns to the left of position 50,
192 # your call will look like this:
193 # position_cursor 50 "Hello" -3 (you'll get the string Hello at position 42 (= 50 - 5 -3)
194 # If you want to start printing at the exact starting location, use offset 0
195
196 START=$1
197 STRING=$2
198 OFFSET=$3
199
200 STRING_LENGTH=${#STRING}
201
202 if [ ${OFFSET} -lt 0 ]; then
203 COL=$((${START} + ${OFFSET} - ${STRING_LENGTH}))
204 else
205 COL=$((${START} + ${OFFSET}))
206 fi
207
208 SET_COL="\\033[${COL}G"
209
210 echo $SET_COL
211} # End of position_cursor()
212
213
214beautify()
215{
216 # Commands: build_stage, make_pkg, message, result
217 case "$1" in
218 message)
219 case "$2" in
220 DONE)
221 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
222 ;;
223 WARN)
224 echo -ne "${WARN}${3}${NORMAL}${SET_RESULT_COL}[${WARN} WARN ${NORMAL}]\n"
225 ;;
226 FAIL)
227 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
228 ;;
229 SKIP)
230 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
231 ;;
232 esac
233 ;;
0b59f25c 234 build_stage)
15679d9f 235 MESSAGE=$2
0b59f25c
MT
236 if [ "$STAGE_TIME_START" ]; then
237 LAST_STAGE_TIME=$[ `date +%s` - $STAGE_TIME_START ]
238 fi
7ab7a9b4 239 STAGE_TIME_START=`date +%s`
deb99a74 240 echo -ne "${BOLD}*** (${BUILD_ARCH}) ${MESSAGE}${NORMAL}"
0b59f25c 241 if [ "$LAST_STAGE_TIME" ]; then
2be66b3d 242 echo -ne "${DONE} (Last stage took $LAST_STAGE_TIME secs)${NORMAL}\n"
0b59f25c
MT
243 fi
244 echo -ne "${BOLD}${SET_VER_COL} version${SET_OPT_COL} options${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n"
7ab7a9b4
MT
245 ;;
246 build_start)
247 BUILD_TIME_START=`date +%s`
248 ;;
249 build_end)
250 BUILD_TIME_END=`date +%s`
070fb401
CS
251 seconds=$[ $BUILD_TIME_END - $BUILD_TIME_START ]
252 hours=$((seconds / 3600))
253 seconds=$((seconds % 3600))
254 minutes=$((seconds / 60))
255 seconds=$((seconds % 60))
256
257 echo -ne "${DONE}***Build is finished now and took $hours hour(s) $minutes minute(s) $seconds second(s)!${NORMAL}\n"
7ab7a9b4 258 ;;
15679d9f
MT
259 make_pkg)
260 echo "$2" | while read PKG_VER PROGRAM OPTIONS
261 do
262 SET_VER_COL_REAL=`position_cursor $OPT_COL $PKG_VER -3`
263
264 if [ "$OPTIONS" == "" ]; then
265 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
266 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
267 else
268 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
269 echo -ne "${NORMAL} ]${SET_OPT_COL}[ ${BOLD}${OPTIONS}"
270 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
271 fi
272 done
273 ;;
274 result)
275 RESULT=$2
276
277 if [ ! $3 ]; then
278 PKG_TIME=0
279 else
280 PKG_TIME=$3
281 fi
282
283 SET_TIME_COL_REAL=`position_cursor $RESULT_COL $PKG_TIME -3`
284 case "$RESULT" in
285 DONE)
286 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
287 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
288 ;;
289 FAIL)
290 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
291 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
292 ;;
293 SKIP)
15679d9f
MT
294 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
295 ;;
296 esac
297 ;;
298 esac
299} # End of beautify()
300
301
302get_pkg_ver()
303{
33e7a260 304 PKG_VER=`grep -E "^VER |^VER=|^VER " $1 | awk '{print $3}'`
15679d9f
MT
305
306 if [ -z $PKG_VER ]; then
307 PKG_VER=`grep "Exp " $1 | awk '{print $4}'`
308 fi
33e7a260
AF
309 if [ -z $PKG_VER ]; then
310 PKG_VER="?"
311 fi
15679d9f
MT
312 if [ ${#PKG_VER} -gt $VER_WIDTH ]; then
313 # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters
314 # and replace enough characters to fit the resulting string on the screen. We'll replace
315 # the extra character with .. (two dots). That's why the "+ 2" in the formula below.
316 # Example: if we have a 21-long version number that we want to fit into a 10-long space,
317 # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll
318 # end up with a 12-character long string. That's why we replace 12 characters with ..
319 REMOVE=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]`
320 PKG_VER=`echo ${PKG_VER/$REMOVE/..}`
321 fi
322
323 echo "$PKG_VER"
324} # End of get_pkg_ver()
325
15679d9f
MT
326# Define immediately
327stdumount() {
b4b6bcdb
MT
328 umount $BASEDIR/build/sys 2>/dev/null;
329 umount $BASEDIR/build/dev/shm 2>/dev/null;
15679d9f 330 umount $BASEDIR/build/dev/pts 2>/dev/null;
b4b6bcdb 331 umount $BASEDIR/build/dev 2>/dev/null;
15679d9f
MT
332 umount $BASEDIR/build/proc 2>/dev/null;
333 umount $BASEDIR/build/install/mnt 2>/dev/null;
334 umount $BASEDIR/build/usr/src/cache 2>/dev/null;
335 umount $BASEDIR/build/usr/src/ccache 2>/dev/null;
336 umount $BASEDIR/build/usr/src/config 2>/dev/null;
337 umount $BASEDIR/build/usr/src/doc 2>/dev/null;
338 umount $BASEDIR/build/usr/src/html 2>/dev/null;
339 umount $BASEDIR/build/usr/src/langs 2>/dev/null;
340 umount $BASEDIR/build/usr/src/lfs 2>/dev/null;
341 umount $BASEDIR/build/usr/src/log 2>/dev/null;
342 umount $BASEDIR/build/usr/src/src 2>/dev/null;
343}
344
345exiterror() {
346 stdumount
347 for i in `seq 0 7`; do
348 if ( losetup /dev/loop${i} 2>/dev/null | grep -q "/install/images" ); then
349 losetup -d /dev/loop${i} 2>/dev/null
350 fi;
351 done
3f9ecfdc
MT
352
353 if [ -n "${LOGFILE}" ]; then
354 echo # empty line
355
356 local line
357 while read -r line; do
358 echo " ${line}"
359 done <<< "$(tail -n30 ${LOGFILE})"
360 fi
361
15679d9f
MT
362 echo -e "\nERROR: $*"
363 echo " Check $LOGFILE for errors if applicable"
364 exit 1
365}
366
b848d53c
MT
367fake_environ() {
368 [ -e "${BASEDIR}/build/tools/lib/libpakfire_preload.so" ] || return
369
370 local env="LD_PRELOAD=/tools/lib/libpakfire_preload.so"
371
372 # Fake kernel version, because some of the packages do not compile
373 # with kernel 3.0 and later.
374 env="${env} UTS_RELEASE=${KVER}"
375
376 # Fake machine version.
dc7d6b20 377 env="${env} UTS_MACHINE=${BUILD_ARCH}"
bcb9dc13
MT
378
379 echo "${env}"
380}
381
382qemu_environ() {
383 local env
384
385 # Don't add anything if qemu is not used.
386 if ! qemu_is_required; then
387 return
388 fi
389
390 # Set default qemu options
dc7d6b20 391 case "${BUILD_ARCH}" in
bcb9dc13
MT
392 arm*)
393 QEMU_CPU="${QEMU_CPU:-cortex-a9}"
394
395 env="${env} QEMU_CPU=${QEMU_CPU}"
396 ;;
397 esac
398
399 # Enable QEMU strace
400 #env="${env} QEMU_STRACE=1"
b848d53c
MT
401
402 echo "${env}"
403}
404
bcb9dc13 405qemu_is_required() {
dc7d6b20 406 local build_arch="${1}"
bcb9dc13 407
dc7d6b20
MT
408 if [ -z "${build_arch}" ]; then
409 build_arch="${BUILD_ARCH}"
bcb9dc13
MT
410 fi
411
dc7d6b20 412 case "${HOST_ARCH},${build_arch}" in
1f4fea71 413 x86_64,arm*|i?86,arm*|i?86,x86_64)
bcb9dc13
MT
414 return 0
415 ;;
416 *)
417 return 1
418 ;;
419 esac
420}
421
422qemu_install_helper() {
423 # Do nothing, if qemu is not required
424 if ! qemu_is_required; then
425 return 0
426 fi
427
1f4fea71
AF
428 if [ ! -e /proc/sys/fs/binfmt_misc/status ]; then
429 exiterror "binfmt_misc not mounted. QEMU_TARGET_HELPER not useable."
430 fi
431
432 if [ ! $(cat /proc/sys/fs/binfmt_misc/status) = 'enabled' ]; then
433 exiterror "binfmt_misc not enabled. QEMU_TARGET_HELPER not useable."
434 fi
435
436
bcb9dc13
MT
437 if [ -z "${QEMU_TARGET_HELPER}" ]; then
438 exiterror "QEMU_TARGET_HELPER not set"
439 fi
440
441 # Check if the helper is already installed.
442 if [ -x "${LFS}${QEMU_TARGET_HELPER}" ]; then
443 return 0
444 fi
445
446 # Try to find a suitable binary that we can install
447 # to the build environment.
448 local file
449 for file in "${QEMU_TARGET_HELPER}" "${QEMU_TARGET_HELPER}-static"; do
450 # file must exist and be executable.
451 [ -x "${file}" ] || continue
452
453 # Must be static.
454 file_is_static "${file}" || continue
455
456 local dirname="${LFS}$(dirname "${file}")"
457 mkdir -p "${dirname}"
458
459 install -m 755 "${file}" "${LFS}${QEMU_TARGET_HELPER}"
460 return 0
461 done
462
463 exiterror "Could not find a statically-linked QEMU emulator: ${QEMU_TARGET_HELPER}"
464}
465
dc7d6b20
MT
466qemu_find_build_helper_name() {
467 local build_arch="${1}"
bcb9dc13
MT
468
469 local magic
dc7d6b20 470 case "${build_arch}" in
bcb9dc13
MT
471 arm*)
472 magic="7f454c4601010100000000000000000002002800"
473 ;;
1f4fea71
AF
474 x86_64)
475 magic="7f454c4602010100000000000000000002003e00"
476 ;;
bcb9dc13
MT
477 esac
478
479 [ -z "${magic}" ] && return 1
480
481 local file
482 for file in /proc/sys/fs/binfmt_misc/*; do
1f4fea71
AF
483 # skip write only register entry
484 [ $(basename "${file}") = "register" ] && continue
bcb9dc13
MT
485 # Search for the file with the correct magic value.
486 grep -qE "^magic ${magic}$" "${file}" || continue
487
488 local interpreter="$(grep "^interpreter" "${file}" | awk '{ print $2 }')"
489
490 [ -n "${interpreter}" ] || continue
491 [ "${interpreter:0:1}" = "/" ] || continue
492 [ -x "${interpreter}" ] || continue
493
494 echo "${interpreter}"
495 return 0
496 done
497
498 return 1
499}
500
501file_is_static() {
502 local file="${1}"
503
504 file ${file} 2>/dev/null | grep -q "statically linked"
505}
506
9d928e82 507enterchroot() {
bcb9dc13
MT
508 # Install QEMU helper, if needed
509 qemu_install_helper
510
9d928e82
MT
511 local PATH="/tools/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin"
512
513 PATH="${PATH}" chroot ${LFS} env -i \
514 HOME="/root" \
515 TERM="${TERM}" \
516 PS1="${PS1}" \
517 PATH="${PATH}" \
1977473d
MT
518 SYSTEM_RELEASE="${SYSTEM_RELEASE}" \
519 PAKFIRE_CORE="${PAKFIRE_CORE}" \
9d928e82
MT
520 NAME="${NAME}" \
521 SNAME="${SNAME}" \
522 VERSION="${VERSION}" \
1977473d 523 CORE="${CORE}" \
9d928e82
MT
524 SLOGAN="${SLOGAN}" \
525 CONFIG_ROOT="${CONFIG_ROOT}" \
e259f335
MT
526 CFLAGS="${CFLAGS} ${HARDENING_CFLAGS}" \
527 CXXFLAGS="${CXXFLAGS} ${HARDENING_CFLAGS}" \
9d928e82
MT
528 BUILDTARGET="${BUILDTARGET}" \
529 CROSSTARGET="${CROSSTARGET}" \
530 BUILD_ARCH="${BUILD_ARCH}" \
9c82fea2 531 BUILD_PLATFORM="${BUILD_PLATFORM}" \
15679d9f 532 CCACHE_DIR=/usr/src/ccache \
b0ad5600
MT
533 CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
534 CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
9d928e82 535 KVER="${KVER}" \
b848d53c 536 $(fake_environ) \
bcb9dc13 537 $(qemu_environ) \
1977473d 538 "$@"
9d928e82
MT
539}
540
541entershell() {
542 if [ ! -e $BASEDIR/build/usr/src/lfs/ ]; then
543 exiterror "No such file or directory: $BASEDIR/build/usr/src/lfs/"
544 fi
545
546 echo "Entering to a shell inside LFS chroot, go out with exit"
547 local PS1="ipfire build chroot ($(uname -m)) \u:\w\$ "
548
549 if enterchroot bash -i; then
15679d9f 550 stdumount
9d928e82
MT
551 else
552 beautify message FAIL
553 exiterror "chroot error"
15679d9f
MT
554 fi
555}
556
557############################################################################
558# #
559# Necessary shell functions #
560# #
561############################################################################
562#
563# Common checking before entering the chroot and compilling
564#
565# Return:0 caller can continue
566# :1 skip (nothing to do)
567# or fail if no script file found
568#
569lfsmakecommoncheck()
570{
15679d9f
MT
571 # Script present?
572 if [ ! -f $BASEDIR/lfs/$1 ]; then
573 exiterror "No such file or directory: $BASEDIR/$1"
574 fi
575
576 local PKG_VER=`get_pkg_ver $BASEDIR/lfs/$1`
577 beautify make_pkg "$PKG_VER $*"
578
846e756e
MT
579 # Check if this package is supported by our architecture.
580 # If no SUP_ARCH is found, we assume the package can be built for all.
581 if grep "^SUP_ARCH" ${BASEDIR}/lfs/${1} >/dev/null; then
dc7d6b20
MT
582 # Check if package supports ${BUILD_ARCH} or all architectures.
583 if ! grep -E "^SUP_ARCH.*${BUILD_ARCH}|^SUP_ARCH.*all" ${BASEDIR}/lfs/${1} >/dev/null; then
846e756e
MT
584 beautify result SKIP
585 return 1
586 fi
587 fi
588
15679d9f
MT
589 # Script slipped?
590 local i
591 for i in $SKIP_PACKAGE_LIST
592 do
a50d04ab 593 if [ "$i" == "$1" ]; then
15679d9f
MT
594 beautify result SKIP
595 return 1;
596 fi
597 done
598
599 echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE
600
dc7d6b20 601 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
51f9e7ac 602 MESSAGE="$1\t " download >> $LOGFILE 2>&1
15679d9f
MT
603 if [ $? -ne 0 ]; then
604 exiterror "Download error in $1"
605 fi
606
dc7d6b20 607 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
51f9e7ac 608 MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1
15679d9f
MT
609 if [ $? -ne 0 ]; then
610 exiterror "md5sum error in $1, check file in cache or signature"
611 fi
612
613 return 0 # pass all!
614} # End of lfsmakecommoncheck()
615
616lfsmake1() {
617 lfsmakecommoncheck $*
618 [ $? == 1 ] && return 0
619
620 local PKG_TIME_START=`date +%s`
621
dc7d6b20 622 cd $BASEDIR/lfs && env -i \
e467a2f2 623 PATH="/tools/ccache/bin:/tools/bin:$PATH" \
9f172a3d
MT
624 CCACHE_DIR="${CCACHE_DIR}" \
625 CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
626 CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
627 CFLAGS="${CFLAGS}" \
628 CXXFLAGS="${CXXFLAGS}" \
fbe365b9 629 MAKETUNING="${MAKETUNING}" \
dc7d6b20
MT
630 make -f $* \
631 TOOLCHAIN=1 \
632 CROSSTARGET="${CROSSTARGET}" \
633 BUILDTARGET="${BUILDTARGET}" \
634 BUILD_ARCH="${BUILD_ARCH}" \
635 BUILD_PLATFORM="${BUILD_PLATFORM}" \
dc7d6b20
MT
636 LFS_BASEDIR="${BASEDIR}" \
637 ROOT="${LFS}" \
638 KVER="${KVER}" \
dc7d6b20
MT
639 install >> $LOGFILE 2>&1
640
15679d9f
MT
641 local COMPILE_SUCCESS=$?
642 local PKG_TIME_END=`date +%s`
643
644 if [ $COMPILE_SUCCESS -ne 0 ]; then
645 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
646 exiterror "Building $*";
647 else
648 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
649 fi
650
651 return 0
652}
653
654lfsmake2() {
655 lfsmakecommoncheck $*
656 [ $? == 1 ] && return 0
657
658 local PKG_TIME_START=`date +%s`
1977473d
MT
659 local PS1='\u:\w$ '
660
661 enterchroot \
fbe365b9 662 bash -x -c "cd /usr/src/lfs && \
fdc0944a 663 MAKETUNING=${MAKETUNING} \
fbe365b9 664 make -f $* \
fdc0944a 665 LFS_BASEDIR=/usr/src install" \
1977473d
MT
666 >> ${LOGFILE} 2>&1
667
15679d9f
MT
668 local COMPILE_SUCCESS=$?
669 local PKG_TIME_END=`date +%s`
670
671 if [ $COMPILE_SUCCESS -ne 0 ]; then
672 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
673 exiterror "Building $*";
674 else
675 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
676 fi
677
678 return 0
679}
680
15679d9f 681ipfiredist() {
0d909a4a
MT
682 lfsmakecommoncheck $*
683 [ $? == 1 ] && return 0
bcb9dc13 684
0d909a4a 685 local PKG_TIME_START=`date +%s`
e5ecbf7d
MT
686 local PS1='\u:\w$ '
687
688 enterchroot \
689 bash -x -c "cd /usr/src/lfs && make -f $* LFS_BASEDIR=/usr/src dist" \
690 >> ${LOGFILE} 2>&1
0d909a4a
MT
691
692 local COMPILE_SUCCESS=$?
693 local PKG_TIME_END=`date +%s`
694
695 if [ $COMPILE_SUCCESS -ne 0 ]; then
696 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
697 exiterror "Packaging $*";
15679d9f 698 else
0d909a4a 699 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
15679d9f
MT
700 fi
701 return 0
702}
703
8a5f0f44
MT
704update_langs() {
705 echo -ne "Checking the translations for missing or obsolete strings..."
1065bfea 706 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
8a5f0f44
MT
707 $BASEDIR/tools/sort_strings.pl en
708 $BASEDIR/tools/sort_strings.pl de
e73e134c
AF
709 $BASEDIR/tools/sort_strings.pl fr
710 $BASEDIR/tools/sort_strings.pl es
196e5f8f 711 $BASEDIR/tools/sort_strings.pl pl
2bb7b134 712 $BASEDIR/tools/sort_strings.pl ru
b34dac1f 713 $BASEDIR/tools/sort_strings.pl nl
910193da 714 $BASEDIR/tools/sort_strings.pl tr
584601c7 715 $BASEDIR/tools/sort_strings.pl it
8a5f0f44
MT
716 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
717 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
e73e134c
AF
718 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
719 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
196e5f8f 720 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.pl
2bb7b134 721 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
b34dac1f 722 $BASEDIR/tools/check_strings.pl nl > $BASEDIR/doc/language_issues.nl
910193da 723 $BASEDIR/tools/check_strings.pl tr > $BASEDIR/doc/language_issues.tr
584601c7 724 $BASEDIR/tools/check_strings.pl it > $BASEDIR/doc/language_issues.it
8a5f0f44
MT
725 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
726 beautify message DONE
5ae22275
MT
727
728 echo -ne "Updating language lists..."
729 update_language_list ${BASEDIR}/src/installer/po
730 update_language_list ${BASEDIR}/src/setup/po
731 beautify message DONE
732}
733
734update_language_list() {
735 local path="${1}"
736
737 local lang
738 for lang in ${path}/*.po; do
739 lang="$(basename "${lang}")"
740 echo "${lang%*.po}"
741 done | sort -u > "${path}/LINGUAS"
8a5f0f44 742}