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