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 -Wall -fexceptions -fPIC ${CFLAGS_ARCH}"
147 # Run compiler and assembler simultaneously on systems that have enough memory
148 if [ ${HOST_MEM} -ge 1024 ]; then
149 CFLAGS
="${CFLAGS} -pipe"
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 ))
161 local processors
="$(system_processors)"
162 local cpu_max
=$
(( ${processors} * 2 ))
165 if [ ${mem_max} -lt ${cpu_max} ]; then
166 parallelism
=${mem_max}
168 parallelism
=${cpu_max}
171 MAKETUNING
="-j${parallelism}"
175 configure_build_guess
() {
176 case "${HOST_ARCH}" in
194 exiterror
"Cannot guess build architecture"
200 if [ "$?" -eq "0" ]; then
201 beautify message DONE
205 beautify message FAIL
207 if [ $EXITCODE -ne "0" ]; then
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
230 STRING_LENGTH
=${#STRING}
232 if [ ${OFFSET} -lt 0 ]; then
233 COL
=$
((${START} + ${OFFSET} - ${STRING_LENGTH}))
235 COL
=$
((${START} + ${OFFSET}))
238 SET_COL
="\\033[${COL}G"
241 } # End of position_cursor()
246 # Commands: build_stage, make_pkg, message, result
251 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
254 echo -ne "${WARN}${3}${NORMAL}${SET_RESULT_COL}[${WARN} WARN ${NORMAL}]\n"
257 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
260 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
266 if [ "$STAGE_TIME_START" ]; then
267 LAST_STAGE_TIME
=$
[ `date +%s` - $STAGE_TIME_START ]
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"
274 echo -ne "${BOLD}${SET_VER_COL} version${SET_OPT_COL} options${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n"
277 BUILD_TIME_START
=`date +%s`
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))
287 echo -ne "${DONE}***Build is finished now and took $hours hour(s) $minutes minute(s) $seconds second(s)!${NORMAL}\n"
290 echo "$2" |
while read PKG_VER PROGRAM OPTIONS
292 SET_VER_COL_REAL
=`position_cursor $OPT_COL $PKG_VER -3`
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}"
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}"
313 SET_TIME_COL_REAL
=`position_cursor $RESULT_COL $PKG_TIME -3`
316 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
317 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
320 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
321 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
324 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
329 } # End of beautify()
334 PKG_VER
=`grep -E "^VER |^VER=|^VER " $1 | awk '{print $3}'`
336 if [ -z $PKG_VER ]; then
337 PKG_VER
=`grep "Exp " $1 | awk '{print $4}'`
339 if [ -z $PKG_VER ]; then
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/..}`
354 } # End of get_pkg_ver()
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
;
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
383 if [ -n "${LOGFILE}" ]; then
387 while read -r line
; do
389 done <<< "$(tail -n30 ${LOGFILE})"
392 echo -e "\nERROR: $*"
393 echo " Check $LOGFILE for errors if applicable"
398 [ -e "${BASEDIR}/build/tools/lib/libpakfire_preload.so" ] ||
return
400 local env
="LD_PRELOAD=/tools/lib/libpakfire_preload.so"
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}"
406 # Fake machine version.
407 env
="${env} UTS_MACHINE=${BUILD_ARCH}"
415 # Don't add anything if qemu is not used.
416 if ! qemu_is_required
; then
420 # Set default qemu options
421 case "${BUILD_ARCH}" in
423 QEMU_CPU
="${QEMU_CPU:-cortex-a9}"
425 env
="${env} QEMU_CPU=${QEMU_CPU}"
430 #env="${env} QEMU_STRACE=1"
436 local build_arch
="${1}"
438 if [ -z "${build_arch}" ]; then
439 build_arch
="${BUILD_ARCH}"
442 case "${HOST_ARCH},${build_arch}" in
443 x86_64
,arm
*|i?
86,arm
*|i?
86,x86_64
)
452 qemu_install_helper
() {
453 # Do nothing, if qemu is not required
454 if ! qemu_is_required
; then
458 if [ ! -e /proc
/sys
/fs
/binfmt_misc
/status
]; then
459 exiterror
"binfmt_misc not mounted. QEMU_TARGET_HELPER not useable."
462 if [ ! $
(cat /proc
/sys
/fs
/binfmt_misc
/status
) = 'enabled' ]; then
463 exiterror
"binfmt_misc not enabled. QEMU_TARGET_HELPER not useable."
467 if [ -z "${QEMU_TARGET_HELPER}" ]; then
468 exiterror
"QEMU_TARGET_HELPER not set"
471 # Check if the helper is already installed.
472 if [ -x "${LFS}${QEMU_TARGET_HELPER}" ]; then
476 # Try to find a suitable binary that we can install
477 # to the build environment.
479 for file in "${QEMU_TARGET_HELPER}" "${QEMU_TARGET_HELPER}-static"; do
480 # file must exist and be executable.
481 [ -x "${file}" ] ||
continue
484 file_is_static
"${file}" ||
continue
486 local dirname="${LFS}$(dirname "${file}")"
487 mkdir
-p "${dirname}"
489 install -m 755 "${file}" "${LFS}${QEMU_TARGET_HELPER}"
493 exiterror
"Could not find a statically-linked QEMU emulator: ${QEMU_TARGET_HELPER}"
496 qemu_find_build_helper_name
() {
497 local build_arch
="${1}"
500 case "${build_arch}" in
502 magic
="7f454c4601010100000000000000000002002800"
505 magic
="7f454c4602010100000000000000000002003e00"
509 [ -z "${magic}" ] && return 1
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
518 local interpreter
="$(grep "^interpreter
" "${file}" | awk '{ print $2 }')"
520 [ -n "${interpreter}" ] ||
continue
521 [ "${interpreter:0:1}" = "/" ] ||
continue
522 [ -x "${interpreter}" ] ||
continue
524 echo "${interpreter}"
534 file ${file} 2>/dev
/null |
grep -q "statically linked"
538 # Install QEMU helper, if needed
541 local PATH
="/tools/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin"
543 PATH
="${PATH}" chroot
${LFS} env
-i \
548 SYSTEM_RELEASE
="${SYSTEM_RELEASE}" \
549 PAKFIRE_CORE
="${PAKFIRE_CORE}" \
552 VERSION
="${VERSION}" \
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}" \
572 if [ ! -e $BASEDIR/build
/usr
/src
/lfs
/ ]; then
573 exiterror
"No such file or directory: $BASEDIR/build/usr/src/lfs/"
576 echo "Entering to a shell inside LFS chroot, go out with exit"
577 local PS1
="ipfire build chroot ($(uname -m)) \u:\w\$ "
579 if enterchroot bash
-i; then
582 beautify message FAIL
583 exiterror
"chroot error"
587 ############################################################################
589 # Necessary shell functions #
591 ############################################################################
593 # Common checking before entering the chroot and compilling
595 # Return:0 caller can continue
596 # :1 skip (nothing to do)
597 # or fail if no script file found
602 if [ ! -f $BASEDIR/lfs
/$1 ]; then
603 exiterror
"No such file or directory: $BASEDIR/$1"
606 local PKG_VER
=`get_pkg_ver $BASEDIR/lfs/$1`
607 beautify make_pkg
"$PKG_VER $*"
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
621 for i in $SKIP_PACKAGE_LIST
623 if [ "$i" == "$1" ]; then
629 echo -ne "`date -u '+%b %e %T'`: Building $
* " >> $LOGFILE
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"
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
"
644 } # End of lfsmakecommoncheck()
647 lfsmakecommoncheck $*
648 [ $? == 1 ] && return 0
650 local PKG_TIME_START=`date +%s`
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}" \
658 CXXFLAGS="${CXXFLAGS}" \
659 MAKETUNING="${MAKETUNING}" \
662 CROSSTARGET="${CROSSTARGET}" \
663 BUILDTARGET="${BUILDTARGET}" \
664 BUILD_ARCH="${BUILD_ARCH}" \
665 BUILD_PLATFORM="${BUILD_PLATFORM}" \
666 LFS_BASEDIR="${BASEDIR}" \
669 install >> $LOGFILE 2>&1
671 local COMPILE_SUCCESS=$?
672 local PKG_TIME_END=`date +%s`
674 if [ $COMPILE_SUCCESS -ne 0 ]; then
675 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
676 exiterror "Building $
*";
678 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
685 lfsmakecommoncheck $*
686 [ $? == 1 ] && return 0
688 local PKG_TIME_START=`date +%s`
692 bash -x -c "cd /usr
/src
/lfs
&& \
693 MAKETUNING
=${MAKETUNING} \
695 LFS_BASEDIR
=/usr
/src
install" \
698 local COMPILE_SUCCESS=$?
699 local PKG_TIME_END=`date +%s`
701 if [ $COMPILE_SUCCESS -ne 0 ]; then
702 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
703 exiterror "Building $
*";
705 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
712 lfsmakecommoncheck $*
713 [ $? == 1 ] && return 0
715 local PKG_TIME_START=`date +%s`
719 bash -x -c "cd /usr
/src
/lfs
&& make -f $
* LFS_BASEDIR
=/usr
/src dist
" \
722 local COMPILE_SUCCESS=$?
723 local PKG_TIME_END=`date +%s`
725 if [ $COMPILE_SUCCESS -ne 0 ]; then
726 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
727 exiterror "Packaging $
*";
729 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
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
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
764 update_language_list() {
768 for lang in ${path}/*.po; do
769 lang="$
(basename "${lang}")"
771 done | sort -u > "${path}/LINGUAS
"