make.sh: Calculate MAKETUNING depending on available memory
[ipfire-2.x.git] / tools / make-functions
CommitLineData
15679d9f 1#!/bin/bash
70df8302
MT
2###############################################################################
3# #
4# IPFire.org - A linux based firewall #
6378290f 5# Copyright (C) 2007-2016 IPFire Team <info@ipfire.org> #
70df8302
MT
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###############################################################################
15679d9f
MT
22#
23# Beautifying variables & presentation & input output interface
24#
70df8302 25###############################################################################
15679d9f
MT
26
27## Screen Dimentions
28# Find current screen size
29if [ -z "${COLUMNS}" ]; then
30 COLUMNS=$(stty size)
31 COLUMNS=${COLUMNS##* }
32fi
33
34# When using remote connections, such as a serial port, stty size returns 0
35if [ "${COLUMNS}" = "0" ]; then
36 COLUMNS=80
37fi
38
39## Measurements for positioning result messages
40RESULT_WIDTH=4
41TIME_WIDTH=8
42OPT_WIDTH=6
43VER_WIDTH=10
44RESULT_COL=$((${COLUMNS} - $RESULT_WIDTH - 4))
45TIME_COL=$((${RESULT_COL} - $TIME_WIDTH - 5))
46OPT_COL=$((${TIME_COL} - $OPT_WIDTH - 5))
47VER_COL=$((${OPT_COL} - $VER_WIDTH - 5))
48
49## Set Cursur Position Commands, used via echo -e
50SET_RESULT_COL="\\033[${RESULT_COL}G"
51SET_TIME_COL="\\033[${TIME_COL}G"
52SET_OPT_COL="\\033[${OPT_COL}G"
53SET_VER_COL="\\033[${VER_COL}G"
54
55# Define color for messages
56BOLD="\\033[1;39m"
57DONE="\\033[1;32m"
58SKIP="\\033[1;34m"
59WARN="\\033[1;35m"
60FAIL="\\033[1;31m"
61NORMAL="\\033[0;39m"
62
1445a5ac
MT
63system_processors() {
64 getconf _NPROCESSORS_ONLN 2>/dev/null || echo "1"
65}
66
5190eea2
MT
67system_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
dc7d6b20
MT
81configure_build() {
82 local build_arch="${1}"
bcb9dc13 83
dc7d6b20
MT
84 if [ "${build_arch}" = "default" ]; then
85 build_arch="$(configure_build_guess)"
bcb9dc13
MT
86 fi
87
dc7d6b20 88 case "${build_arch}" in
fc155193 89 x86_64)
dc7d6b20
MT
90 BUILDTARGET="${build_arch}-unknown-linux-gnu"
91 CROSSTARGET="${build_arch}-cross-linux-gnu"
92 BUILD_PLATFORM="x86"
fc155193
MT
93 CFLAGS_ARCH="-m64 -mtune=generic"
94 ;;
95
bcb9dc13 96 i586)
dc7d6b20
MT
97 BUILDTARGET="${build_arch}-pc-linux-gnu"
98 CROSSTARGET="${build_arch}-cross-linux-gnu"
99 BUILD_PLATFORM="x86"
da3dbb2a 100 CFLAGS_ARCH="-march=i586 -mtune=generic -fomit-frame-pointer"
bcb9dc13
MT
101 ;;
102
bab5ff7c 103 aarch64)
dc7d6b20
MT
104 BUILDTARGET="${build_arch}-unknown-linux-gnu"
105 CROSSTARGET="${build_arch}-cross-linux-gnu"
106 BUILD_PLATFORM="arm"
bab5ff7c
MT
107 CFLAGS_ARCH=""
108 ;;
109
4162dbae 110 armv7hl)
dc7d6b20
MT
111 BUILDTARGET="${build_arch}-unknown-linux-gnueabi"
112 CROSSTARGET="${build_arch}-cross-linux-gnueabi"
113 BUILD_PLATFORM="arm"
ff92f1ac 114 CFLAGS_ARCH="-march=armv7-a -mfpu=vfpv3-d16 -mfloat-abi=hard"
4162dbae
MT
115 ;;
116
bcb9dc13 117 armv5tel)
dc7d6b20
MT
118 BUILDTARGET="${build_arch}-unknown-linux-gnueabi"
119 CROSSTARGET="${build_arch}-cross-linux-gnueabi"
120 BUILD_PLATFORM="arm"
bcb9dc13 121 CFLAGS_ARCH="-march=armv5te -mfloat-abi=soft -fomit-frame-pointer"
bcb9dc13
MT
122 ;;
123
124 *)
dc7d6b20 125 exiterror "Cannot build for architure ${build_arch}"
bcb9dc13
MT
126 ;;
127 esac
128
129 # Check if the QEMU helper is available if needed.
dc7d6b20
MT
130 if qemu_is_required "${build_arch}"; then
131 local qemu_build_helper="$(qemu_find_build_helper_name "${build_arch}")"
bcb9dc13 132
dc7d6b20
MT
133 if [ -n "${qemu_build_helper}" ]; then
134 QEMU_TARGET_HELPER="${qemu_build_helper}"
bcb9dc13 135 else
dc7d6b20 136 exiterror "Could not find a binfmt_misc helper entry for ${build_arch}"
bcb9dc13
MT
137 fi
138 fi
139
dc7d6b20 140 BUILD_ARCH="${build_arch}"
bcb9dc13 141
e259f335
MT
142 # Enables hardening
143 HARDENING_CFLAGS="-Wp,-D_FORTIFY_SOURCE=2 -fstack-protector-strong --param=ssp-buffer-size=4"
144
7e1639a4
MT
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
bcb9dc13 152 CXXFLAGS="${CFLAGS}"
a98ab1d7
MT
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
bcb9dc13
MT
173}
174
dc7d6b20
MT
175configure_build_guess() {
176 case "${HOST_ARCH}" in
bcb9dc13
MT
177 x86_64|i686|i586)
178 echo "i586"
179 ;;
16449f75
MT
180
181 aarch64)
182 echo "aarch64"
183 ;;
184
4162dbae
MT
185 armv7*)
186 echo "armv7hl"
187 ;;
188
189 armv6*|armv5*)
bcb9dc13
MT
190 echo "armv5tel"
191 ;;
4162dbae 192
bcb9dc13 193 *)
dc7d6b20 194 exiterror "Cannot guess build architecture"
bcb9dc13
MT
195 ;;
196 esac
197}
198
15679d9f
MT
199evaluate() {
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
213position_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
244beautify()
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 ;;
0b59f25c 264 build_stage)
15679d9f 265 MESSAGE=$2
0b59f25c
MT
266 if [ "$STAGE_TIME_START" ]; then
267 LAST_STAGE_TIME=$[ `date +%s` - $STAGE_TIME_START ]
268 fi
7ab7a9b4 269 STAGE_TIME_START=`date +%s`
deb99a74 270 echo -ne "${BOLD}*** (${BUILD_ARCH}) ${MESSAGE}${NORMAL}"
0b59f25c 271 if [ "$LAST_STAGE_TIME" ]; then
2be66b3d 272 echo -ne "${DONE} (Last stage took $LAST_STAGE_TIME secs)${NORMAL}\n"
0b59f25c
MT
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"
7ab7a9b4
MT
275 ;;
276 build_start)
277 BUILD_TIME_START=`date +%s`
278 ;;
279 build_end)
280 BUILD_TIME_END=`date +%s`
070fb401
CS
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"
7ab7a9b4 288 ;;
15679d9f
MT
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)
15679d9f
MT
324 echo -ne "${SET_RESULT_COL}[${SKIP} SKIP ${NORMAL}]\n"
325 ;;
326 esac
327 ;;
328 esac
329} # End of beautify()
330
331
332get_pkg_ver()
333{
33e7a260 334 PKG_VER=`grep -E "^VER |^VER=|^VER " $1 | awk '{print $3}'`
15679d9f
MT
335
336 if [ -z $PKG_VER ]; then
337 PKG_VER=`grep "Exp " $1 | awk '{print $4}'`
338 fi
33e7a260
AF
339 if [ -z $PKG_VER ]; then
340 PKG_VER="?"
341 fi
15679d9f
MT
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
15679d9f
MT
356# Define immediately
357stdumount() {
b4b6bcdb
MT
358 umount $BASEDIR/build/sys 2>/dev/null;
359 umount $BASEDIR/build/dev/shm 2>/dev/null;
15679d9f 360 umount $BASEDIR/build/dev/pts 2>/dev/null;
b4b6bcdb 361 umount $BASEDIR/build/dev 2>/dev/null;
15679d9f
MT
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
375exiterror() {
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
3f9ecfdc
MT
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
15679d9f
MT
392 echo -e "\nERROR: $*"
393 echo " Check $LOGFILE for errors if applicable"
394 exit 1
395}
396
b848d53c
MT
397fake_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.
dc7d6b20 407 env="${env} UTS_MACHINE=${BUILD_ARCH}"
bcb9dc13
MT
408
409 echo "${env}"
410}
411
412qemu_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
dc7d6b20 421 case "${BUILD_ARCH}" in
bcb9dc13
MT
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"
b848d53c
MT
431
432 echo "${env}"
433}
434
bcb9dc13 435qemu_is_required() {
dc7d6b20 436 local build_arch="${1}"
bcb9dc13 437
dc7d6b20
MT
438 if [ -z "${build_arch}" ]; then
439 build_arch="${BUILD_ARCH}"
bcb9dc13
MT
440 fi
441
dc7d6b20 442 case "${HOST_ARCH},${build_arch}" in
1f4fea71 443 x86_64,arm*|i?86,arm*|i?86,x86_64)
bcb9dc13
MT
444 return 0
445 ;;
446 *)
447 return 1
448 ;;
449 esac
450}
451
452qemu_install_helper() {
453 # Do nothing, if qemu is not required
454 if ! qemu_is_required; then
455 return 0
456 fi
457
1f4fea71
AF
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
bcb9dc13
MT
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
dc7d6b20
MT
496qemu_find_build_helper_name() {
497 local build_arch="${1}"
bcb9dc13
MT
498
499 local magic
dc7d6b20 500 case "${build_arch}" in
bcb9dc13
MT
501 arm*)
502 magic="7f454c4601010100000000000000000002002800"
503 ;;
1f4fea71
AF
504 x86_64)
505 magic="7f454c4602010100000000000000000002003e00"
506 ;;
bcb9dc13
MT
507 esac
508
509 [ -z "${magic}" ] && return 1
510
511 local file
512 for file in /proc/sys/fs/binfmt_misc/*; do
1f4fea71
AF
513 # skip write only register entry
514 [ $(basename "${file}") = "register" ] && continue
bcb9dc13
MT
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
531file_is_static() {
532 local file="${1}"
533
534 file ${file} 2>/dev/null | grep -q "statically linked"
535}
536
9d928e82 537enterchroot() {
bcb9dc13
MT
538 # Install QEMU helper, if needed
539 qemu_install_helper
540
9d928e82
MT
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}" \
1977473d
MT
548 SYSTEM_RELEASE="${SYSTEM_RELEASE}" \
549 PAKFIRE_CORE="${PAKFIRE_CORE}" \
9d928e82
MT
550 NAME="${NAME}" \
551 SNAME="${SNAME}" \
552 VERSION="${VERSION}" \
1977473d 553 CORE="${CORE}" \
9d928e82
MT
554 SLOGAN="${SLOGAN}" \
555 CONFIG_ROOT="${CONFIG_ROOT}" \
e259f335
MT
556 CFLAGS="${CFLAGS} ${HARDENING_CFLAGS}" \
557 CXXFLAGS="${CXXFLAGS} ${HARDENING_CFLAGS}" \
9d928e82
MT
558 BUILDTARGET="${BUILDTARGET}" \
559 CROSSTARGET="${CROSSTARGET}" \
560 BUILD_ARCH="${BUILD_ARCH}" \
9c82fea2 561 BUILD_PLATFORM="${BUILD_PLATFORM}" \
15679d9f 562 CCACHE_DIR=/usr/src/ccache \
b0ad5600
MT
563 CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
564 CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
9d928e82 565 KVER="${KVER}" \
b848d53c 566 $(fake_environ) \
bcb9dc13 567 $(qemu_environ) \
1977473d 568 "$@"
9d928e82
MT
569}
570
571entershell() {
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
15679d9f 580 stdumount
9d928e82
MT
581 else
582 beautify message FAIL
583 exiterror "chroot error"
15679d9f
MT
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#
599lfsmakecommoncheck()
600{
15679d9f
MT
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
846e756e
MT
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
dc7d6b20
MT
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
846e756e
MT
614 beautify result SKIP
615 return 1
616 fi
617 fi
618
15679d9f
MT
619 # Script slipped?
620 local i
621 for i in $SKIP_PACKAGE_LIST
622 do
a50d04ab 623 if [ "$i" == "$1" ]; then
15679d9f
MT
624 beautify result SKIP
625 return 1;
626 fi
627 done
628
629 echo -ne "`date -u '+%b %e %T'`: Building $* " >> $LOGFILE
630
dc7d6b20 631 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
51f9e7ac 632 MESSAGE="$1\t " download >> $LOGFILE 2>&1
15679d9f
MT
633 if [ $? -ne 0 ]; then
634 exiterror "Download error in $1"
635 fi
636
dc7d6b20 637 cd $BASEDIR/lfs && make -s -f $* LFS_BASEDIR=$BASEDIR BUILD_ARCH="${BUILD_ARCH}" \
51f9e7ac 638 MESSAGE="$1\t md5sum" md5 >> $LOGFILE 2>&1
15679d9f
MT
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
646lfsmake1() {
647 lfsmakecommoncheck $*
648 [ $? == 1 ] && return 0
649
650 local PKG_TIME_START=`date +%s`
651
dc7d6b20 652 cd $BASEDIR/lfs && env -i \
e467a2f2 653 PATH="/tools/ccache/bin:/tools/bin:$PATH" \
9f172a3d
MT
654 CCACHE_DIR="${CCACHE_DIR}" \
655 CCACHE_COMPRESS="${CCACHE_COMPRESS}" \
656 CCACHE_COMPILERCHECK="${CCACHE_COMPILERCHECK}" \
657 CFLAGS="${CFLAGS}" \
658 CXXFLAGS="${CXXFLAGS}" \
fbe365b9 659 MAKETUNING="${MAKETUNING}" \
dc7d6b20
MT
660 make -f $* \
661 TOOLCHAIN=1 \
662 CROSSTARGET="${CROSSTARGET}" \
663 BUILDTARGET="${BUILDTARGET}" \
664 BUILD_ARCH="${BUILD_ARCH}" \
665 BUILD_PLATFORM="${BUILD_PLATFORM}" \
dc7d6b20
MT
666 LFS_BASEDIR="${BASEDIR}" \
667 ROOT="${LFS}" \
668 KVER="${KVER}" \
dc7d6b20
MT
669 install >> $LOGFILE 2>&1
670
15679d9f
MT
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
684lfsmake2() {
685 lfsmakecommoncheck $*
686 [ $? == 1 ] && return 0
687
688 local PKG_TIME_START=`date +%s`
1977473d
MT
689 local PS1='\u:\w$ '
690
691 enterchroot \
fbe365b9 692 bash -x -c "cd /usr/src/lfs && \
fdc0944a 693 MAKETUNING=${MAKETUNING} \
fbe365b9 694 make -f $* \
fdc0944a 695 LFS_BASEDIR=/usr/src install" \
1977473d
MT
696 >> ${LOGFILE} 2>&1
697
15679d9f
MT
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
15679d9f 711ipfiredist() {
0d909a4a
MT
712 lfsmakecommoncheck $*
713 [ $? == 1 ] && return 0
bcb9dc13 714
0d909a4a 715 local PKG_TIME_START=`date +%s`
e5ecbf7d
MT
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
0d909a4a
MT
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 $*";
15679d9f 728 else
0d909a4a 729 beautify result DONE $[ $PKG_TIME_END - $PKG_TIME_START ]
15679d9f
MT
730 fi
731 return 0
732}
733
8a5f0f44
MT
734update_langs() {
735 echo -ne "Checking the translations for missing or obsolete strings..."
1065bfea 736 chmod 755 $BASEDIR/tools/{check_strings.pl,sort_strings.pl,check_langs.sh}
8a5f0f44
MT
737 $BASEDIR/tools/sort_strings.pl en
738 $BASEDIR/tools/sort_strings.pl de
e73e134c
AF
739 $BASEDIR/tools/sort_strings.pl fr
740 $BASEDIR/tools/sort_strings.pl es
196e5f8f 741 $BASEDIR/tools/sort_strings.pl pl
2bb7b134 742 $BASEDIR/tools/sort_strings.pl ru
b34dac1f 743 $BASEDIR/tools/sort_strings.pl nl
910193da 744 $BASEDIR/tools/sort_strings.pl tr
584601c7 745 $BASEDIR/tools/sort_strings.pl it
8a5f0f44
MT
746 $BASEDIR/tools/check_strings.pl en > $BASEDIR/doc/language_issues.en
747 $BASEDIR/tools/check_strings.pl de > $BASEDIR/doc/language_issues.de
e73e134c
AF
748 $BASEDIR/tools/check_strings.pl fr > $BASEDIR/doc/language_issues.fr
749 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.es
196e5f8f 750 $BASEDIR/tools/check_strings.pl es > $BASEDIR/doc/language_issues.pl
2bb7b134 751 $BASEDIR/tools/check_strings.pl ru > $BASEDIR/doc/language_issues.ru
b34dac1f 752 $BASEDIR/tools/check_strings.pl nl > $BASEDIR/doc/language_issues.nl
910193da 753 $BASEDIR/tools/check_strings.pl tr > $BASEDIR/doc/language_issues.tr
584601c7 754 $BASEDIR/tools/check_strings.pl it > $BASEDIR/doc/language_issues.it
8a5f0f44
MT
755 $BASEDIR/tools/check_langs.sh > $BASEDIR/doc/language_missings
756 beautify message DONE
5ae22275
MT
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
764update_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"
8a5f0f44 772}