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 local build_arch
="${1}"
66 if [ "${build_arch}" = "default" ]; then
67 build_arch
="$(configure_build_guess)"
70 case "${build_arch}" in
72 BUILDTARGET
="${build_arch}-unknown-linux-gnu"
73 CROSSTARGET
="${build_arch}-cross-linux-gnu"
75 CFLAGS_ARCH
="-m64 -mtune=generic"
79 BUILDTARGET
="${build_arch}-pc-linux-gnu"
80 CROSSTARGET
="${build_arch}-cross-linux-gnu"
82 CFLAGS_ARCH
="-march=i586 -mtune=generic -fomit-frame-pointer"
86 BUILDTARGET
="${build_arch}-unknown-linux-gnu"
87 CROSSTARGET
="${build_arch}-cross-linux-gnu"
93 BUILDTARGET
="${build_arch}-unknown-linux-gnueabi"
94 CROSSTARGET
="${build_arch}-cross-linux-gnueabi"
96 CFLAGS_ARCH
="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
100 BUILDTARGET
="${build_arch}-unknown-linux-gnueabi"
101 CROSSTARGET
="${build_arch}-cross-linux-gnueabi"
103 CFLAGS_ARCH
="-march=armv5te -mfloat-abi=soft -fomit-frame-pointer"
107 exiterror
"Cannot build for architure ${build_arch}"
111 # Check if the QEMU helper is available if needed.
112 if qemu_is_required
"${build_arch}"; then
113 local qemu_build_helper
="$(qemu_find_build_helper_name "${build_arch}")"
115 if [ -n "${qemu_build_helper}" ]; then
116 QEMU_TARGET_HELPER
="${qemu_build_helper}"
118 exiterror
"Could not find a binfmt_misc helper entry for ${build_arch}"
122 BUILD_ARCH
="${build_arch}"
125 HARDENING_CFLAGS
="-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4"
127 CFLAGS
="-O2 -pipe -Wall -fexceptions -fPIC ${CFLAGS_ARCH}"
131 configure_build_guess
() {
132 case "${HOST_ARCH}" in
150 exiterror
"Cannot guess build architecture"
156 if [ "$?" -eq "0" ]; then
157 beautify message DONE
161 beautify message FAIL
163 if [ $EXITCODE -ne "0" ]; then
171 # ARG1=starting position on screen
172 # ARG2=string to be printed
173 # ARG3=offset, negative for left movement, positive for right movement, relative to ARG1
174 # For example if your starting position is column 50 and you want to print Hello three columns to the right
175 # of your starting position, your call will look like this:
176 # position_cursor 50 "Hello" 3 (you'll get the string Hello at position 53 (= 50 + 3)
177 # If on the other hand you want your string "Hello" to end three columns to the left of position 50,
178 # your call will look like this:
179 # position_cursor 50 "Hello" -3 (you'll get the string Hello at position 42 (= 50 - 5 -3)
180 # If you want to start printing at the exact starting location, use offset 0
186 STRING_LENGTH
=${#STRING}
188 if [ ${OFFSET} -lt 0 ]; then
189 COL
=$
((${START} + ${OFFSET} - ${STRING_LENGTH}))
191 COL
=$
((${START} + ${OFFSET}))
194 SET_COL
="\\033[${COL}G"
197 } # End of position_cursor()
202 # Commands: build_stage, make_pkg, message, result
207 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
210 echo -ne "${WARN}${3}${NORMAL}${SET_RESULT_COL}[${WARN} WARN ${NORMAL}]\n"
213 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
216 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
222 if [ "$STAGE_TIME_START" ]; then
223 LAST_STAGE_TIME
=$
[ `date +%s` - $STAGE_TIME_START ]
225 STAGE_TIME_START
=`date +%s`
226 echo -ne "${BOLD}*** (${BUILD_ARCH}) ${MESSAGE}${NORMAL}"
227 if [ "$LAST_STAGE_TIME" ]; then
228 echo -ne "${DONE} (Last stage took $LAST_STAGE_TIME secs)${NORMAL}\n"
230 echo -ne "${BOLD}${SET_VER_COL} version${SET_OPT_COL} options${SET_TIME_COL} time (sec)${SET_RESULT_COL} status${NORMAL}\n"
233 BUILD_TIME_START
=`date +%s`
236 BUILD_TIME_END
=`date +%s`
237 seconds
=$
[ $BUILD_TIME_END - $BUILD_TIME_START ]
238 hours
=$
((seconds
/ 3600))
239 seconds
=$
((seconds
% 3600))
240 minutes
=$
((seconds
/ 60))
241 seconds
=$
((seconds
% 60))
243 echo -ne "${DONE}***Build is finished now and took $hours hour(s) $minutes minute(s) $seconds second(s)!${NORMAL}\n"
246 echo "$2" |
while read PKG_VER PROGRAM OPTIONS
248 SET_VER_COL_REAL
=`position_cursor $OPT_COL $PKG_VER -3`
250 if [ "$OPTIONS" == "" ]; then
251 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
252 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
254 echo -ne "${PROGRAM}${SET_VER_COL}[ ${BOLD}${SET_VER_COL_REAL}${PKG_VER}"
255 echo -ne "${NORMAL} ]${SET_OPT_COL}[ ${BOLD}${OPTIONS}"
256 echo -ne "${NORMAL} ]${SET_RESULT_COL}"
269 SET_TIME_COL_REAL
=`position_cursor $RESULT_COL $PKG_TIME -3`
272 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
273 echo -ne "${SET_RESULT_COL}[${DONE} DONE ${NORMAL}]\n"
276 echo -ne "${SET_TIME_COL}[ ${BOLD}${SET_TIME_COL_REAL}$PKG_TIME${NORMAL} ]"
277 echo -ne "${SET_RESULT_COL}[${FAIL} FAIL ${NORMAL}]\n"
280 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
285 } # End of beautify()
290 PKG_VER
=`grep -E "^VER |^VER=|^VER " $1 | awk '{print $3}'`
292 if [ -z $PKG_VER ]; then
293 PKG_VER
=`grep "Exp " $1 | awk '{print $4}'`
295 if [ -z $PKG_VER ]; then
298 if [ ${#PKG_VER} -gt $VER_WIDTH ]; then
299 # If a package version number is greater than $VER_WIDTH, we keep the first 4 characters
300 # and replace enough characters to fit the resulting string on the screen. We'll replace
301 # the extra character with .. (two dots). That's why the "+ 2" in the formula below.
302 # Example: if we have a 21-long version number that we want to fit into a 10-long space,
303 # we have to remove 11 characters. But if we replace 11 characters with 2 characters, we'll
304 # end up with a 12-character long string. That's why we replace 12 characters with ..
305 REMOVE
=`expr substr "$PKG_VER" 4 $[ ${#PKG_VER} - $VER_WIDTH + 2 ]`
306 PKG_VER
=`echo ${PKG_VER/$REMOVE/..}`
310 } # End of get_pkg_ver()
314 umount
$BASEDIR/build
/sys
2>/dev
/null
;
315 umount
$BASEDIR/build
/dev
/shm
2>/dev
/null
;
316 umount
$BASEDIR/build
/dev
/pts
2>/dev
/null
;
317 umount
$BASEDIR/build
/dev
2>/dev
/null
;
318 umount
$BASEDIR/build
/proc
2>/dev
/null
;
319 umount
$BASEDIR/build
/install
/mnt
2>/dev
/null
;
320 umount
$BASEDIR/build
/usr
/src
/cache
2>/dev
/null
;
321 umount
$BASEDIR/build
/usr
/src
/ccache
2>/dev
/null
;
322 umount
$BASEDIR/build
/usr
/src
/config
2>/dev
/null
;
323 umount
$BASEDIR/build
/usr
/src
/doc
2>/dev
/null
;
324 umount
$BASEDIR/build
/usr
/src
/html
2>/dev
/null
;
325 umount
$BASEDIR/build
/usr
/src
/langs
2>/dev
/null
;
326 umount
$BASEDIR/build
/usr
/src
/lfs
2>/dev
/null
;
327 umount
$BASEDIR/build
/usr
/src
/log
2>/dev
/null
;
328 umount
$BASEDIR/build
/usr
/src
/src
2>/dev
/null
;
333 for i
in `seq 0 7`; do
334 if ( losetup
/dev
/loop
${i} 2>/dev
/null |
grep -q "/install/images" ); then
335 losetup
-d /dev
/loop
${i} 2>/dev
/null
339 if [ -n "${LOGFILE}" ]; then
343 while read -r line
; do
345 done <<< "$(tail -n30 ${LOGFILE})"
348 echo -e "\nERROR: $*"
349 echo " Check $LOGFILE for errors if applicable"
354 [ -e "${BASEDIR}/build/tools/lib/libpakfire_preload.so" ] ||
return
356 local env
="LD_PRELOAD=/tools/lib/libpakfire_preload.so"
358 # Fake kernel version, because some of the packages do not compile
359 # with kernel 3.0 and later.
360 env
="${env} UTS_RELEASE=${KVER}"
362 # Fake machine version.
363 env
="${env} UTS_MACHINE=${BUILD_ARCH}"
371 # Don't add anything if qemu is not used.
372 if ! qemu_is_required
; then
376 # Set default qemu options
377 case "${BUILD_ARCH}" in
379 QEMU_CPU
="${QEMU_CPU:-cortex-a9}"
381 env
="${env} QEMU_CPU=${QEMU_CPU}"
386 #env="${env} QEMU_STRACE=1"
392 local build_arch
="${1}"
394 if [ -z "${build_arch}" ]; then
395 build_arch
="${BUILD_ARCH}"
398 case "${HOST_ARCH},${build_arch}" in
399 x86_64
,arm
*|i?
86,arm
*|i?
86,x86_64
)
408 qemu_install_helper
() {
409 # Do nothing, if qemu is not required
410 if ! qemu_is_required
; then
414 if [ ! -e /proc
/sys
/fs
/binfmt_misc
/status
]; then
415 exiterror
"binfmt_misc not mounted. QEMU_TARGET_HELPER not useable."
418 if [ ! $
(cat /proc
/sys
/fs
/binfmt_misc
/status
) = 'enabled' ]; then
419 exiterror
"binfmt_misc not enabled. QEMU_TARGET_HELPER not useable."
423 if [ -z "${QEMU_TARGET_HELPER}" ]; then
424 exiterror
"QEMU_TARGET_HELPER not set"
427 # Check if the helper is already installed.
428 if [ -x "${LFS}${QEMU_TARGET_HELPER}" ]; then
432 # Try to find a suitable binary that we can install
433 # to the build environment.
435 for file in "${QEMU_TARGET_HELPER}" "${QEMU_TARGET_HELPER}-static"; do
436 # file must exist and be executable.
437 [ -x "${file}" ] ||
continue
440 file_is_static
"${file}" ||
continue
442 local dirname="${LFS}$(dirname "${file}")"
443 mkdir
-p "${dirname}"
445 install -m 755 "${file}" "${LFS}${QEMU_TARGET_HELPER}"
449 exiterror
"Could not find a statically-linked QEMU emulator: ${QEMU_TARGET_HELPER}"
452 qemu_find_build_helper_name
() {
453 local build_arch
="${1}"
456 case "${build_arch}" in
458 magic
="7f454c4601010100000000000000000002002800"
461 magic
="7f454c4602010100000000000000000002003e00"
465 [ -z "${magic}" ] && return 1
468 for file in /proc
/sys
/fs
/binfmt_misc
/*; do
469 # skip write only register entry
470 [ $
(basename "${file}") = "register" ] && continue
471 # Search for the file with the correct magic value.
472 grep -qE "^magic ${magic}$" "${file}" ||
continue
474 local interpreter
="$(grep "^interpreter
" "${file}" | awk '{ print $2 }')"
476 [ -n "${interpreter}" ] ||
continue
477 [ "${interpreter:0:1}" = "/" ] ||
continue
478 [ -x "${interpreter}" ] ||
continue
480 echo "${interpreter}"
490 file ${file} 2>/dev
/null |
grep -q "statically linked"
494 # Install QEMU helper, if needed
497 local PATH
="/tools/ccache/bin:/bin:/usr/bin:/sbin:/usr/sbin:/tools/bin"
499 PATH
="${PATH}" chroot
${LFS} env
-i \
504 SYSTEM_RELEASE
="${SYSTEM_RELEASE}" \
505 PAKFIRE_CORE
="${PAKFIRE_CORE}" \
508 VERSION
="${VERSION}" \
511 CONFIG_ROOT
="${CONFIG_ROOT}" \
512 CFLAGS
="${CFLAGS} ${HARDENING_CFLAGS}" \
513 CXXFLAGS
="${CXXFLAGS} ${HARDENING_CFLAGS}" \
514 BUILDTARGET
="${BUILDTARGET}" \
515 CROSSTARGET
="${CROSSTARGET}" \
516 BUILD_ARCH
="${BUILD_ARCH}" \
517 BUILD_PLATFORM
="${BUILD_PLATFORM}" \
518 CCACHE_DIR
=/usr
/src
/ccache \
519 CCACHE_COMPRESS
="${CCACHE_COMPRESS}" \
520 CCACHE_COMPILERCHECK
="${CCACHE_COMPILERCHECK}" \
528 if [ ! -e $BASEDIR/build
/usr
/src
/lfs
/ ]; then
529 exiterror
"No such file or directory: $BASEDIR/build/usr/src/lfs/"
532 echo "Entering to a shell inside LFS chroot, go out with exit"
533 local PS1
="ipfire build chroot ($(uname -m)) \u:\w\$ "
535 if enterchroot bash
-i; then
538 beautify message FAIL
539 exiterror
"chroot error"
543 ############################################################################
545 # Necessary shell functions #
547 ############################################################################
549 # Common checking before entering the chroot and compilling
551 # Return:0 caller can continue
552 # :1 skip (nothing to do)
553 # or fail if no script file found
558 if [ ! -f $BASEDIR/lfs
/$1 ]; then
559 exiterror
"No such file or directory: $BASEDIR/$1"
562 local PKG_VER
=`get_pkg_ver $BASEDIR/lfs/$1`
563 beautify make_pkg
"$PKG_VER $*"
565 # Check if this package is supported by our architecture.
566 # If no SUP_ARCH is found, we assume the package can be built for all.
567 if grep "^SUP_ARCH" ${BASEDIR}/lfs
/${1} >/dev
/null
; then
568 # Check if package supports ${BUILD_ARCH} or all architectures.
569 if ! grep -E "^SUP_ARCH.*${BUILD_ARCH}|^SUP_ARCH.*all" ${BASEDIR}/lfs/${1} >/dev/null; then
577 for i in $SKIP_PACKAGE_LIST
579 if [ "$i" == "$1" ]; then
585 echo -ne "`date -u '+%b %e %T'`: Building $
* " >> $LOGFILE
587 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
588 MESSAGE="$1\t " download >> $LOGFILE 2>&1
589 if [ $? -ne 0 ]; then
590 exiterror "Download error
in $1"
593 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
594 MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1
595 if [ $? -ne 0 ]; then
596 exiterror "md5sum error
in $1, check
file in cache or signature
"
600 } # End of lfsmakecommoncheck()
603 lfsmakecommoncheck $*
604 [ $? == 1 ] && return 0
606 local PKG_TIME_START=`date +%s`
608 cd $BASEDIR/lfs && env -i \
609 PATH="/tools
/ccache
/bin
:/tools
/bin
:$PATH" \
610 CCACHE_DIR="${CCACHE_DIR}" \
611 CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
612 CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
614 CXXFLAGS="${CXXFLAGS}" \
615 MAKETUNING="${MAKETUNING}" \
618 CROSSTARGET="${CROSSTARGET}" \
619 BUILDTARGET="${BUILDTARGET}" \
620 BUILD_ARCH="${BUILD_ARCH}" \
621 BUILD_PLATFORM="${BUILD_PLATFORM}" \
622 LFS_BASEDIR="${BASEDIR}" \
625 install >> $LOGFILE 2>&1
627 local COMPILE_SUCCESS=$?
628 local PKG_TIME_END=`date +%s`
630 if [ $COMPILE_SUCCESS -ne 0 ]; then
631 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
632 exiterror "Building $
*";
634 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
641 lfsmakecommoncheck $*
642 [ $? == 1 ] && return 0
644 local PKG_TIME_START=`date +%s`
648 bash -x -c "cd /usr
/src
/lfs
&& \
649 MAKETUNING
=${MAKETUNING} \
651 LFS_BASEDIR
=/usr
/src
install" \
654 local COMPILE_SUCCESS=$?
655 local PKG_TIME_END=`date +%s`
657 if [ $COMPILE_SUCCESS -ne 0 ]; then
658 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
659 exiterror "Building $
*";
661 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
668 lfsmakecommoncheck $*
669 [ $? == 1 ] && return 0
671 local PKG_TIME_START=`date +%s`
675 bash -x -c "cd /usr
/src
/lfs
&& make -f $
* LFS_BASEDIR
=/usr
/src dist
" \
678 local COMPILE_SUCCESS=$?
679 local PKG_TIME_END=`date +%s`
681 if [ $COMPILE_SUCCESS -ne 0 ]; then
682 beautify result FAIL $[ $PKG_TIME_END - $PKG_TIME_START ]
683 exiterror "Packaging $
*";
685 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
691 echo -ne "Checking the translations
for missing or obsolete
strings...
"
692 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
693 $BASEDIR/tools/sort_strings.pl en
694 $BASEDIR/tools/sort_strings.pl de
695 $BASEDIR/tools/sort_strings.pl fr
696 $BASEDIR/tools/sort_strings.pl es
697 $BASEDIR/tools/sort_strings.pl pl
698 $BASEDIR/tools/sort_strings.pl ru
699 $BASEDIR/tools/sort_strings.pl nl
700 $BASEDIR/tools/sort_strings.pl tr
701 $BASEDIR/tools/sort_strings.pl it
702 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
703 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
704 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
705 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
706 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.pl
707 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
708 $BASEDIR/tools/check_strings.pl nl > $BASEDIR/doc/language_issues.nl
709 $BASEDIR/tools/check_strings.pl tr > $BASEDIR/doc/language_issues.tr
710 $BASEDIR/tools/check_strings.pl it > $BASEDIR/doc/language_issues.it
711 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
712 beautify message DONE
714 echo -ne "Updating language lists...
"
715 update_language_list ${BASEDIR}/src/installer/po
716 update_language_list ${BASEDIR}/src/setup/po
717 beautify message DONE
720 update_language_list() {
724 for lang in ${path}/*.po; do
725 lang="$
(basename "${lang}")"
727 done | sort -u > "${path}/LINGUAS
"