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