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