2 ###############################################################################
4 # IPFire.org - A linux based firewall #
5 # Copyright (C) 2007-2016 IPFire Team <info@ipfire.org> #
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. #
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. #
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/>. #
20 ###############################################################################
21 ###############################################################################
23 # Beautifying variables & presentation & input output interface
25 ###############################################################################
28 # Find current screen size
29 if [ -z "${COLUMNS}" ]; then
31 COLUMNS
=${COLUMNS##* }
34 # When using remote connections, such as a serial port, stty size returns 0
35 if [ "${COLUMNS}" = "0" ]; then
39 ## Measurements for positioning result messages
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))
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"
55 # Define color for messages
64 getconf _NPROCESSORS_ONLN
2>/dev
/null ||
echo "1"
70 while read -r key val unit
; do
74 echo "$(( ${val} / 1024 ))"
82 local build_arch
="${1}"
84 if [ "${build_arch}" = "default" ]; then
85 build_arch
="$(configure_build_guess)"
88 case "${build_arch}" in
90 BUILDTARGET
="${build_arch}-unknown-linux-gnu"
91 CROSSTARGET
="${build_arch}-cross-linux-gnu"
93 CFLAGS_ARCH
="-m64 -mtune=generic"
97 BUILDTARGET
="${build_arch}-pc-linux-gnu"
98 CROSSTARGET
="${build_arch}-cross-linux-gnu"
100 CFLAGS_ARCH
="-march=i586 -mtune=generic -fomit-frame-pointer"
104 BUILDTARGET
="${build_arch}-unknown-linux-gnu"
105 CROSSTARGET
="${build_arch}-cross-linux-gnu"
111 BUILDTARGET
="${build_arch}-unknown-linux-gnueabi"
112 CROSSTARGET
="${build_arch}-cross-linux-gnueabi"
114 CFLAGS_ARCH
="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
118 BUILDTARGET
="${build_arch}-unknown-linux-gnueabi"
119 CROSSTARGET
="${build_arch}-cross-linux-gnueabi"
121 CFLAGS_ARCH
="-march=armv5te -mfloat-abi=soft -fomit-frame-pointer"
125 exiterror
"Cannot build for architure ${build_arch}"
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}")"
133 if [ -n "${qemu_build_helper}" ]; then
134 QEMU_TARGET_HELPER
="${qemu_build_helper}"
136 exiterror
"Could not find a binfmt_misc helper entry for ${build_arch}"
140 BUILD_ARCH
="${build_arch}"
143 HARDENING_CFLAGS
="-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4"
145 CFLAGS
="-O2 -pipe -Wall -fexceptions -fPIC ${CFLAGS_ARCH}"
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 ))
155 local processors
="$(system_processors)"
156 local cpu_max
=$
(( ${processors} * 2 ))
159 if [ ${mem_max} -lt ${cpu_max} ]; then
160 parallelism
=${mem_max}
162 parallelism
=${cpu_max}
165 MAKETUNING
="-j${parallelism}"
169 configure_build_guess
() {
170 case "${HOST_ARCH}" in
188 exiterror
"Cannot guess build architecture"
194 if [ "$?" -eq "0" ]; then
195 beautify message DONE
199 beautify message FAIL
201 if [ $EXITCODE -ne "0" ]; then
209 # ARG1=starting position on screen
210 # ARG2=string to be printed
211 # ARG3=offset, negative for left movement, positive for right movement, relative to ARG1
212 # For example if your starting position is column 50 and you want to print Hello three columns to the right
213 # of your starting position, your call will look like this:
214 # position_cursor 50 "Hello" 3 (you'll get the string Hello at position 53 (= 50 + 3)
215 # If on the other hand you want your string "Hello" to end three columns to the left of position 50,
216 # your call will look like this:
217 # position_cursor 50 "Hello" -3 (you'll get the string Hello at position 42 (= 50 - 5 -3)
218 # If you want to start printing at the exact starting location, use offset 0
224 STRING_LENGTH
=${#STRING}
226 if [ ${OFFSET} -lt 0 ]; then
227 COL
=$
((${START} + ${OFFSET} - ${STRING_LENGTH}))
229 COL
=$
((${START} + ${OFFSET}))
232 SET_COL
="\\033[${COL}G"
235 } # End of position_cursor()
240 # Commands: build_stage, make_pkg, message, result
245 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
248 echo -ne "${WARN}${3}${NORMAL}${SET_RESULT_COL}[${WARN} WARN ${NORMAL}]\n"
251 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
254 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
260 if [ "$STAGE_TIME_START" ]; then
261 LAST_STAGE_TIME
=$
[ `date +%s` - $STAGE_TIME_START ]
263 STAGE_TIME_START
=`date +%s`
264 echo -ne "${BOLD}*** (${BUILD_ARCH}) ${MESSAGE}${NORMAL}"
265 if [ "$LAST_STAGE_TIME" ]; then
266 echo -ne "${DONE} (Last stage took $LAST_STAGE_TIME secs)${NORMAL}\n"
268 echo -ne "${BOLD}${SET_VER_COL} version${SET_OPT_COL} options${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n"
271 BUILD_TIME_START
=`date +%s`
274 BUILD_TIME_END
=`date +%s`
275 seconds
=$
[ $BUILD_TIME_END - $BUILD_TIME_START ]
276 hours
=$
((seconds
/ 3600))
277 seconds
=$
((seconds
% 3600))
278 minutes
=$
((seconds
/ 60))
279 seconds
=$
((seconds
% 60))
281 echo -ne "${DONE}***Build is finished now and took $hours hour(s) $minutes minute(s) $seconds second(s)!${NORMAL}\n"
284 echo "$2" |
while read PKG_VER PROGRAM OPTIONS
286 SET_VER_COL_REAL
=`position_cursor $OPT_COL $PKG_VER -3`
288 if [ "$OPTIONS" == "" ]; then
289 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
290 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
292 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
293 echo -ne "${NORMAL} ]${SET_OPT_COL}[ ${BOLD}${OPTIONS}"
294 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
307 SET_TIME_COL_REAL
=`position_cursor $RESULT_COL $PKG_TIME -3`
310 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
311 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
314 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
315 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
318 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
323 } # End of beautify()
328 PKG_VER
=`grep -E "^VER |^VER=|^VER " $1 | awk '{print $3}'`
330 if [ -z $PKG_VER ]; then
331 PKG_VER
=`grep "Exp " $1 | awk '{print $4}'`
333 if [ -z $PKG_VER ]; then
336 if [ ${#PKG_VER} -gt $VER_WIDTH ]; then
337 # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters
338 # and replace enough characters to fit the resulting string on the screen. We'll replace
339 # the extra character with .. (two dots). That's why the "+ 2" in the formula below.
340 # Example: if we have a 21-long version number that we want to fit into a 10-long space,
341 # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll
342 # end up with a 12-character long string. That's why we replace 12 characters with ..
343 REMOVE
=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]`
344 PKG_VER
=`echo ${PKG_VER/$REMOVE/..}`
348 } # End of get_pkg_ver()
352 umount
$BASEDIR/build
/sys
2>/dev
/null
;
353 umount
$BASEDIR/build
/dev
/shm
2>/dev
/null
;
354 umount
$BASEDIR/build
/dev
/pts
2>/dev
/null
;
355 umount
$BASEDIR/build
/dev
2>/dev
/null
;
356 umount
$BASEDIR/build
/proc
2>/dev
/null
;
357 umount
$BASEDIR/build
/install
/mnt
2>/dev
/null
;
358 umount
$BASEDIR/build
/usr
/src
/cache
2>/dev
/null
;
359 umount
$BASEDIR/build
/usr
/src
/ccache
2>/dev
/null
;
360 umount
$BASEDIR/build
/usr
/src
/config
2>/dev
/null
;
361 umount
$BASEDIR/build
/usr
/src
/doc
2>/dev
/null
;
362 umount
$BASEDIR/build
/usr
/src
/html
2>/dev
/null
;
363 umount
$BASEDIR/build
/usr
/src
/langs
2>/dev
/null
;
364 umount
$BASEDIR/build
/usr
/src
/lfs
2>/dev
/null
;
365 umount
$BASEDIR/build
/usr
/src
/log
2>/dev
/null
;
366 umount
$BASEDIR/build
/usr
/src
/src
2>/dev
/null
;
371 for i
in `seq 0 7`; do
372 if ( losetup
/dev
/loop
${i} 2>/dev
/null |
grep -q "/install/images" ); then
373 losetup
-d /dev
/loop
${i} 2>/dev
/null
377 if [ -n "${LOGFILE}" ]; then
381 while read -r line
; do
383 done <<< "$(tail -n30 ${LOGFILE})"
386 echo -e "\nERROR: $*"
387 echo " Check $LOGFILE for errors if applicable"
392 [ -e "${BASEDIR}/build/tools/lib/libpakfire_preload.so" ] ||
return
394 local env
="LD_PRELOAD=/tools/lib/libpakfire_preload.so"
396 # Fake kernel version, because some of the packages do not compile
397 # with kernel 3.0 and later.
398 env
="${env} UTS_RELEASE=${KVER}"
400 # Fake machine version.
401 env
="${env} UTS_MACHINE=${BUILD_ARCH}"
409 # Don't add anything if qemu is not used.
410 if ! qemu_is_required
; then
414 # Set default qemu options
415 case "${BUILD_ARCH}" in
417 QEMU_CPU
="${QEMU_CPU:-cortex-a9}"
419 env
="${env} QEMU_CPU=${QEMU_CPU}"
424 #env="${env} QEMU_STRACE=1"
430 local build_arch
="${1}"
432 if [ -z "${build_arch}" ]; then
433 build_arch
="${BUILD_ARCH}"
436 case "${HOST_ARCH},${build_arch}" in
437 x86_64
,arm
*|i?
86,arm
*|i?
86,x86_64
)
446 qemu_install_helper
() {
447 # Do nothing, if qemu is not required
448 if ! qemu_is_required
; then
452 if [ ! -e /proc
/sys
/fs
/binfmt_misc
/status
]; then
453 exiterror
"binfmt_misc not mounted. QEMU_TARGET_HELPER not useable."
456 if [ ! $
(cat /proc
/sys
/fs
/binfmt_misc
/status
) = 'enabled' ]; then
457 exiterror
"binfmt_misc not enabled. QEMU_TARGET_HELPER not useable."
461 if [ -z "${QEMU_TARGET_HELPER}" ]; then
462 exiterror
"QEMU_TARGET_HELPER not set"
465 # Check if the helper is already installed.
466 if [ -x "${LFS}${QEMU_TARGET_HELPER}" ]; then
470 # Try to find a suitable binary that we can install
471 # to the build environment.
473 for file in "${QEMU_TARGET_HELPER}" "${QEMU_TARGET_HELPER}-static"; do
474 # file must exist and be executable.
475 [ -x "${file}" ] ||
continue
478 file_is_static
"${file}" ||
continue
480 local dirname="${LFS}$(dirname "${file}")"
481 mkdir
-p "${dirname}"
483 install -m 755 "${file}" "${LFS}${QEMU_TARGET_HELPER}"
487 exiterror
"Could not find a statically-linked QEMU emulator: ${QEMU_TARGET_HELPER}"
490 qemu_find_build_helper_name
() {
491 local build_arch
="${1}"
494 case "${build_arch}" in
496 magic
="7f454c4601010100000000000000000002002800"
499 magic
="7f454c4602010100000000000000000002003e00"
503 [ -z "${magic}" ] && return 1
506 for file in /proc
/sys
/fs
/binfmt_misc
/*; do
507 # skip write only register entry
508 [ $
(basename "${file}") = "register" ] && continue
509 # Search for the file with the correct magic value.
510 grep -qE "^magic ${magic}$" "${file}" ||
continue
512 local interpreter
="$(grep "^interpreter
" "${file}" | awk '{ print $2 }')"
514 [ -n "${interpreter}" ] ||
continue
515 [ "${interpreter:0:1}" = "/" ] ||
continue
516 [ -x "${interpreter}" ] ||
continue
518 echo "${interpreter}"
528 file ${file} 2>/dev
/null |
grep -q "statically linked"
532 # Install QEMU helper, if needed
535 local PATH
="/tools/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin"
537 PATH
="${PATH}" chroot
${LFS} env
-i \
542 SYSTEM_RELEASE
="${SYSTEM_RELEASE}" \
543 PAKFIRE_CORE
="${PAKFIRE_CORE}" \
546 VERSION
="${VERSION}" \
549 CONFIG_ROOT
="${CONFIG_ROOT}" \
550 CFLAGS
="${CFLAGS} ${HARDENING_CFLAGS}" \
551 CXXFLAGS
="${CXXFLAGS} ${HARDENING_CFLAGS}" \
552 BUILDTARGET
="${BUILDTARGET}" \
553 CROSSTARGET
="${CROSSTARGET}" \
554 BUILD_ARCH
="${BUILD_ARCH}" \
555 BUILD_PLATFORM
="${BUILD_PLATFORM}" \
556 CCACHE_DIR
=/usr
/src
/ccache \
557 CCACHE_COMPRESS
="${CCACHE_COMPRESS}" \
558 CCACHE_COMPILERCHECK
="${CCACHE_COMPILERCHECK}" \
566 if [ ! -e $BASEDIR/build
/usr
/src
/lfs
/ ]; then
567 exiterror
"No such file or directory: $BASEDIR/build/usr/src/lfs/"
570 echo "Entering to a shell inside LFS chroot, go out with exit"
571 local PS1
="ipfire build chroot ($(uname -m)) \u:\w\$ "
573 if enterchroot bash
-i; then
576 beautify message FAIL
577 exiterror
"chroot error"
581 ############################################################################
583 # Necessary shell functions #
585 ############################################################################
587 # Common checking before entering the chroot and compilling
589 # Return:0 caller can continue
590 # :1 skip (nothing to do)
591 # or fail if no script file found
596 if [ ! -f $BASEDIR/lfs
/$1 ]; then
597 exiterror
"No such file or directory: $BASEDIR/$1"
600 local PKG_VER
=`get_pkg_ver $BASEDIR/lfs/$1`
601 beautify make_pkg
"$PKG_VER $*"
603 # Check if this package is supported by our architecture.
604 # If no SUP_ARCH is found, we assume the package can be built for all.
605 if grep "^SUP_ARCH" ${BASEDIR}/lfs
/${1} >/dev
/null
; then
606 # Check if package supports ${BUILD_ARCH} or all architectures.
607 if ! grep -E "^SUP_ARCH.*${BUILD_ARCH}|^SUP_ARCH.*all" ${BASEDIR}/lfs/${1} >/dev/null; then
615 for i in $SKIP_PACKAGE_LIST
617 if [ "$i" == "$1" ]; then
623 echo -ne "`date -u '+%b %e %T'`: Building $
* " >> $LOGFILE
625 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
626 MESSAGE="$1\t " download >> $LOGFILE 2>&1
627 if [ $? -ne 0 ]; then
628 exiterror "Download error
in $1"
631 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
632 MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1
633 if [ $? -ne 0 ]; then
634 exiterror "md5sum error
in $1, check
file in cache or signature
"
638 } # End of lfsmakecommoncheck()
641 lfsmakecommoncheck $*
642 [ $? == 1 ] && return 0
644 local PKG_TIME_START=`date +%s`
646 cd $BASEDIR/lfs && env -i \
647 PATH="/tools
/ccache
/bin
:/tools
/bin
:$PATH" \
648 CCACHE_DIR="${CCACHE_DIR}" \
649 CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
650 CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
652 CXXFLAGS="${CXXFLAGS}" \
653 MAKETUNING="${MAKETUNING}" \
656 CROSSTARGET="${CROSSTARGET}" \
657 BUILDTARGET="${BUILDTARGET}" \
658 BUILD_ARCH="${BUILD_ARCH}" \
659 BUILD_PLATFORM="${BUILD_PLATFORM}" \
660 LFS_BASEDIR="${BASEDIR}" \
663 install >> $LOGFILE 2>&1
665 local COMPILE_SUCCESS=$?
666 local PKG_TIME_END=`date +%s`
668 if [ $COMPILE_SUCCESS -ne 0 ]; then
669 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
670 exiterror "Building $
*";
672 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
679 lfsmakecommoncheck $*
680 [ $? == 1 ] && return 0
682 local PKG_TIME_START=`date +%s`
686 bash -x -c "cd /usr
/src
/lfs
&& \
687 MAKETUNING
=${MAKETUNING} \
689 LFS_BASEDIR
=/usr
/src
install" \
692 local COMPILE_SUCCESS=$?
693 local PKG_TIME_END=`date +%s`
695 if [ $COMPILE_SUCCESS -ne 0 ]; then
696 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
697 exiterror "Building $
*";
699 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
706 lfsmakecommoncheck $*
707 [ $? == 1 ] && return 0
709 local PKG_TIME_START=`date +%s`
713 bash -x -c "cd /usr
/src
/lfs
&& make -f $
* LFS_BASEDIR
=/usr
/src dist
" \
716 local COMPILE_SUCCESS=$?
717 local PKG_TIME_END=`date +%s`
719 if [ $COMPILE_SUCCESS -ne 0 ]; then
720 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
721 exiterror "Packaging $
*";
723 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
729 echo -ne "Checking the translations
for missing or obsolete
strings...
"
730 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
731 $BASEDIR/tools/sort_strings.pl en
732 $BASEDIR/tools/sort_strings.pl de
733 $BASEDIR/tools/sort_strings.pl fr
734 $BASEDIR/tools/sort_strings.pl es
735 $BASEDIR/tools/sort_strings.pl pl
736 $BASEDIR/tools/sort_strings.pl ru
737 $BASEDIR/tools/sort_strings.pl nl
738 $BASEDIR/tools/sort_strings.pl tr
739 $BASEDIR/tools/sort_strings.pl it
740 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
741 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
742 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
743 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
744 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.pl
745 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
746 $BASEDIR/tools/check_strings.pl nl > $BASEDIR/doc/language_issues.nl
747 $BASEDIR/tools/check_strings.pl tr > $BASEDIR/doc/language_issues.tr
748 $BASEDIR/tools/check_strings.pl it > $BASEDIR/doc/language_issues.it
749 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
750 beautify message DONE
752 echo -ne "Updating language lists...
"
753 update_language_list ${BASEDIR}/src/installer/po
754 update_language_list ${BASEDIR}/src/setup/po
755 beautify message DONE
758 update_language_list() {
762 for lang in ${path}/*.po; do
763 lang="$
(basename "${lang}")"
765 done | sort -u > "${path}/LINGUAS
"