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