1 | #!/bin/bash
|
---|
2 |
|
---|
3 | # $Id$
|
---|
4 |
|
---|
5 | set +e
|
---|
6 |
|
---|
7 | # VT100 colors
|
---|
8 | declare -r BLACK=$'\e[1;30m'
|
---|
9 | declare -r DK_GRAY=$'\e[0;30m'
|
---|
10 |
|
---|
11 | declare -r RED=$'\e[31m'
|
---|
12 | declare -r GREEN=$'\e[32m'
|
---|
13 | declare -r YELLOW=$'\e[33m'
|
---|
14 | declare -r BLUE=$'\e[34m'
|
---|
15 | declare -r MAGENTA=$'\e[35m'
|
---|
16 | declare -r CYAN=$'\e[36m'
|
---|
17 | declare -r WHITE=$'\e[37m'
|
---|
18 |
|
---|
19 | declare -r OFF=$'\e[0m'
|
---|
20 | declare -r BOLD=$'\e[1m'
|
---|
21 | declare -r REVERSE=$'\e[7m'
|
---|
22 | declare -r HIDDEN=$'\e[8m'
|
---|
23 |
|
---|
24 | declare -r tab_=$'\t'
|
---|
25 | declare -r nl_=$'\n'
|
---|
26 |
|
---|
27 | declare -r DD_BORDER="${BOLD}==============================================================================${OFF}"
|
---|
28 | declare -r SD_BORDER="${BOLD}------------------------------------------------------------------------------${OFF}"
|
---|
29 | declare -r STAR_BORDER="${BOLD}******************************************************************************${OFF}"
|
---|
30 |
|
---|
31 | # bold yellow > < pair
|
---|
32 | declare -r R_arrow=$'\e[1;33m>\e[0m'
|
---|
33 | declare -r L_arrow=$'\e[1;33m<\e[0m'
|
---|
34 |
|
---|
35 |
|
---|
36 | usage() {
|
---|
37 | cat <<- -EOF-
|
---|
38 | ${DD_BORDER}
|
---|
39 | ${BOLD}
|
---|
40 | Usage: $0 ${BOLD}[OPTION]
|
---|
41 |
|
---|
42 | ${RED}IMPORTANT:${OFF} Only supported command line switches are listed here.
|
---|
43 | For more fine-grained setups you must edit the relevant
|
---|
44 | configuration files placed under ${BOLD}common/${OFF} and ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])/${OFF}
|
---|
45 |
|
---|
46 | Options:
|
---|
47 | ${BOLD} -h, --help${OFF}
|
---|
48 | print this help, then exit
|
---|
49 |
|
---|
50 | ${BOLD} -V, --version${OFF}
|
---|
51 | print version information, then exit
|
---|
52 |
|
---|
53 | ${BOLD} -B, --book VER${OFF}
|
---|
54 | use VER version of the book as the system to build.
|
---|
55 | Supported versions are: dev*, trunk, SVN
|
---|
56 | These are aliases for the Development version of {C,H}LFS
|
---|
57 |
|
---|
58 | ${BOLD} -D --directory DIR${OFF}
|
---|
59 | use DIR directory for building ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF}; all files jhalfs produces
|
---|
60 | will be in the directory DIR/${SCRIPT_ROOT}.
|
---|
61 | The current setting for BUILDDIR is "$BUILDDIR"
|
---|
62 |
|
---|
63 | ${BOLD} -G, --get-packages${OFF}
|
---|
64 | download the packages and patches. This assumes that the server declared
|
---|
65 | in the configuration file has the proper packages and patches for the
|
---|
66 | book version being processed.
|
---|
67 |
|
---|
68 | ${BOLD} -O, --optimize${OFF}
|
---|
69 | Optimize [0-2]
|
---|
70 | 0 = no optimization
|
---|
71 | 1 = optimize final system only
|
---|
72 | 2 = optimize both temporary tools and final system
|
---|
73 | Edit common/opt_config{,.d/*} and common/opt_override as desired.
|
---|
74 |
|
---|
75 | ${BOLD} -T, --testsuites N ${OFF}
|
---|
76 | Run test suites [0-3]
|
---|
77 | 0 = none
|
---|
78 | 1 = only final system Glibc, GCC and Binutils testsuites
|
---|
79 | 2 = all final system testsuites
|
---|
80 | 3 = all temporary tools and final system testsuites
|
---|
81 | In CLFS, 3 is an alias to 2
|
---|
82 |
|
---|
83 | ${BOLD} -W, --working-copy DIR${OFF}
|
---|
84 | use the local working copy placed in DIR as the $(echo $PROGNAME | tr [a-z] [A-Z]) book
|
---|
85 |
|
---|
86 | ${BOLD} -C, --comparasion TYPE${OFF}
|
---|
87 | do iterative comparison analysis. This extends the total build time
|
---|
88 | considerably because the entire final system will rebuild itself
|
---|
89 | the number of times specified by ITERATIONS in common/config.
|
---|
90 | Types allowed are:
|
---|
91 | ICA = do ICA as designed by Greg Schafer
|
---|
92 | farce = do the farce analysis designed by Ken Moffat
|
---|
93 | both = perfom both ICA and farce analysis
|
---|
94 |
|
---|
95 | ${BOLD} -F, --fstab FILE${OFF}
|
---|
96 | use FILE as the /etc/fstab file for the ${BOLD}$(echo $PROGNAME | tr [a-z] [A-Z])${OFF} system. If not specified,
|
---|
97 | a default /etc/fstab file with dummy values is created.
|
---|
98 |
|
---|
99 | ${BOLD} -K, --kernel-config FILE${OFF}
|
---|
100 | use the kernel configuration file specified in FILE to build the kernel.
|
---|
101 | if the file is not found, or if not specified, the kernel build is skipped.
|
---|
102 |
|
---|
103 | ${BOLD} -M, --run-make${OFF}
|
---|
104 | run make on the generated Makefile
|
---|
105 |
|
---|
106 | ${BOLD} -R --rebuild${OFF}
|
---|
107 | clean the build directory before perfoming any other task. The directory
|
---|
108 | is cleaned only if it was populated by a previous jhalfs run.
|
---|
109 | -EOF-
|
---|
110 |
|
---|
111 | [[ ${PROGNAME} = "clfs" ]] &&
|
---|
112 | cat <<- -EOF-
|
---|
113 |
|
---|
114 | ${BOLD} -A, --arch ARCH ${OFF}
|
---|
115 | Select the TARGET architecture, valid selections are:
|
---|
116 | 32bit builds
|
---|
117 | x86, i486, i586, ppc, mips, mipsel, sparc
|
---|
118 | 64bit builds
|
---|
119 | x86_64-64, mips64-64, mipsel64-64, sparc64-64, alpha
|
---|
120 | 64bit multi-lib
|
---|
121 | x86_64, mips64, mipsel64, sparc64, ppc64
|
---|
122 |
|
---|
123 | ${BOLD} --boot-config FILE ${OFF}
|
---|
124 | The configuration file for the bootstrap kernel if method=boot
|
---|
125 |
|
---|
126 | ${BOLD} --method BUILDMETHOD ${OFF}
|
---|
127 | Select the build method, chroot or boot
|
---|
128 | -EOF-
|
---|
129 |
|
---|
130 | [[ ${PROGNAME} = "hlfs" ]] &&
|
---|
131 | cat <<- -EOF-
|
---|
132 |
|
---|
133 | ${BOLD} --model STYLE ${OFF}
|
---|
134 | Select the library model for the HLFS system
|
---|
135 | Valid choices are: glibc or uclibc
|
---|
136 | -EOF-
|
---|
137 |
|
---|
138 | cat <<- -EOF-
|
---|
139 | ${DD_BORDER}
|
---|
140 | -EOF-
|
---|
141 | exit
|
---|
142 | }
|
---|
143 |
|
---|
144 | version="
|
---|
145 | ${BOLD} \"jhalfs\"${OFF} builder tool (development) \$Rev$
|
---|
146 | \$Date$
|
---|
147 |
|
---|
148 | ${BOLD} \"${PROGNAME}\"${OFF} script module
|
---|
149 |
|
---|
150 | Written by George Boudreau,
|
---|
151 | Manuel Canales Esparcia,
|
---|
152 | Jeremy Huntwork
|
---|
153 |
|
---|
154 | This program is published under the ${BOLD}Gnu General Public License, Version 2.${OFF}
|
---|
155 | "
|
---|
156 |
|
---|
157 |
|
---|
158 | no_empty_builddir() {
|
---|
159 | 'clear'
|
---|
160 | cat <<- -EOF-
|
---|
161 | ${DD_BORDER}
|
---|
162 |
|
---|
163 | ${tab_}${tab_}${BOLD}${RED}W A R N I N G${OFF}
|
---|
164 | Looks like the \$BUILDDIR directory contains subdirectories
|
---|
165 | from a previous HLFS build.
|
---|
166 |
|
---|
167 | Please format the partition mounted on \$BUILDDIR or set
|
---|
168 | a different build directory before running jhalfs.
|
---|
169 | ${OFF}
|
---|
170 | ${DD_BORDER}
|
---|
171 | -EOF-
|
---|
172 | exit
|
---|
173 | }
|
---|
174 |
|
---|
175 |
|
---|
176 | help="${nl_}Try '$0 --help' for more information."
|
---|
177 |
|
---|
178 | exit_missing_arg="\
|
---|
179 | echo \"Option '\$1' requires an argument\" >&2
|
---|
180 | echo \"\$help\" >&2
|
---|
181 | exit 1"
|
---|
182 |
|
---|
183 | HEADER="# This file is automatically generated by jhalfs
|
---|
184 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
185 | #
|
---|
186 | # Generated on `date \"+%F %X %Z\"`"
|
---|
187 |
|
---|
188 |
|
---|
189 |
|
---|
190 | #----------------------------------#
|
---|
191 | wrt_target() { # Create target and initialize log file
|
---|
192 | #----------------------------------#
|
---|
193 | local i=$1
|
---|
194 | local PREV=$2
|
---|
195 | case $i in
|
---|
196 | iteration* ) local LOGFILE=$this_script.log ;;
|
---|
197 | * ) local LOGFILE=$this_script ;;
|
---|
198 | esac
|
---|
199 | (
|
---|
200 | cat << EOF
|
---|
201 |
|
---|
202 | $i: $PREV
|
---|
203 | @\$(call echo_message, Building)
|
---|
204 | @./progress_bar.sh \$@ &
|
---|
205 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >logs/$LOGFILE
|
---|
206 | EOF
|
---|
207 | ) >> $MKFILE.tmp
|
---|
208 | }
|
---|
209 |
|
---|
210 | #----------------------------#
|
---|
211 | get_package_tarball_name() { #
|
---|
212 | #----------------------------#
|
---|
213 | local script_name=$1
|
---|
214 |
|
---|
215 | # The use of 'head' is necessary to limit the return value to the FIRST match..
|
---|
216 | # hopefully this will not cause problems.
|
---|
217 | #
|
---|
218 | case $script_name in
|
---|
219 | tcl) echo $(grep "^tcl" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
|
---|
220 | *) echo $(grep "^$script_name-[[:digit:]]" $JHALFSDIR/pkg_tarball_list | head -n1 ) ;;
|
---|
221 | esac
|
---|
222 |
|
---|
223 | }
|
---|
224 |
|
---|
225 | #----------------------------------#
|
---|
226 | wrt_remove_existing_dirs() { #
|
---|
227 | #----------------------------------#
|
---|
228 | local PKG_NAME=$1
|
---|
229 | (
|
---|
230 | cat << EOF
|
---|
231 | @PKG_PATH=\`ls -t \$(MOUNT_PT)\$(SRC)/${PKG_NAME} | head -n1\` && \\
|
---|
232 | ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
|
---|
233 | [[ -n \$\$ROOT ]] && \\
|
---|
234 | rm -rf \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
|
---|
235 | if [ -e \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build ]; then \\
|
---|
236 | rm -rf \$(MOUNT_PT)\$(SRC)/${PKG_NAME%-*}-build; \\
|
---|
237 | fi;
|
---|
238 | EOF
|
---|
239 | ) >> $MKFILE.tmp
|
---|
240 | }
|
---|
241 |
|
---|
242 | #----------------------------------#
|
---|
243 | wrt_remove_existing_dirs2() { #
|
---|
244 | #----------------------------------#
|
---|
245 | local PKG_NAME=$1
|
---|
246 | (
|
---|
247 | cat << EOF
|
---|
248 | @PKG_PATH=\`ls -t \$(SRC)/${PKG_NAME} | head -n1\` && \\
|
---|
249 | ROOT=\`tar -tf \$\$PKG_PATH | head -n1 | sed -e 's@^./@@;s@/.*@@'\` && \\
|
---|
250 | [[ -n \$\$ROOT ]] && \\
|
---|
251 | rm -rf \$(SRC)/\$\$ROOT && \\
|
---|
252 | if [ -e \$(SRC)/${PKG_NAME%-*}-build ]; then \\
|
---|
253 | rm -rf \$(SRC)/${PKG_NAME%-*}-build; \\
|
---|
254 | fi;
|
---|
255 | EOF
|
---|
256 | ) >> $MKFILE.tmp
|
---|
257 | }
|
---|
258 |
|
---|
259 |
|
---|
260 |
|
---|
261 | #----------------------------------#
|
---|
262 | wrt_unpack() { # Unpack and set 'ROOT' var
|
---|
263 | #----------------------------------#
|
---|
264 | local FILE=$1
|
---|
265 | local optSAVE_PREVIOUS=$2
|
---|
266 |
|
---|
267 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
268 | wrt_remove_existing_dirs "$FILE"
|
---|
269 | fi
|
---|
270 | (
|
---|
271 | cat << EOF
|
---|
272 | @\$(call unpack,$FILE)
|
---|
273 | @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
274 | echo "export PKGDIR=\$(MOUNT_PT)\$(SRC)/\$\$ROOT" > envars && \\
|
---|
275 | chown -R lfs \$(MOUNT_PT)\$(SRC)/\$\$ROOT
|
---|
276 | EOF
|
---|
277 | ) >> $MKFILE.tmp
|
---|
278 | }
|
---|
279 |
|
---|
280 |
|
---|
281 | #----------------------------------#
|
---|
282 | wrt_unpack2() { #
|
---|
283 | #----------------------------------#
|
---|
284 | local FILE=$1
|
---|
285 | local optSAVE_PREVIOUS=$2
|
---|
286 |
|
---|
287 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
288 | wrt_remove_existing_dirs "$FILE"
|
---|
289 | fi
|
---|
290 | (
|
---|
291 | cat << EOF
|
---|
292 | @\$(call unpack2,$FILE)
|
---|
293 | @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
294 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
295 | EOF
|
---|
296 | ) >> $MKFILE.tmp
|
---|
297 | }
|
---|
298 |
|
---|
299 |
|
---|
300 | #----------------------------------#
|
---|
301 | wrt_unpack3() { #
|
---|
302 | #----------------------------------#
|
---|
303 | local FILE=$1
|
---|
304 | local optSAVE_PREVIOUS=$2
|
---|
305 |
|
---|
306 | if [ "${optSAVE_PREVIOUS}" != "1" ]; then
|
---|
307 | wrt_remove_existing_dirs2 "$FILE"
|
---|
308 | fi
|
---|
309 | (
|
---|
310 | cat << EOF
|
---|
311 | @\$(call unpack3,$FILE)
|
---|
312 | @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
313 | echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars
|
---|
314 | EOF
|
---|
315 | ) >> $MKFILE.tmp
|
---|
316 | }
|
---|
317 |
|
---|
318 | #----------------------------------#
|
---|
319 | wrt_test_log() { # Initialize testsuite log file
|
---|
320 | #----------------------------------#
|
---|
321 | local TESTLOGFILE=$1
|
---|
322 | (
|
---|
323 | cat << EOF
|
---|
324 | @echo "export TEST_LOG=$TESTLOGDIR/$TESTLOGFILE" >> envars && \\
|
---|
325 | su - lfs -c "echo -e '\n\`date\`\n' >$TESTLOGDIR/$TESTLOGFILE"
|
---|
326 | EOF
|
---|
327 | ) >> $MKFILE.tmp
|
---|
328 | }
|
---|
329 |
|
---|
330 | #----------------------------------#
|
---|
331 | wrt_test_log2() { #
|
---|
332 | #----------------------------------#
|
---|
333 | local TESTLOGFILE=$1
|
---|
334 | (
|
---|
335 | cat << EOF
|
---|
336 | @echo "export TEST_LOG=/$SCRIPT_ROOT/test-logs/$TESTLOGFILE" >> envars && \\
|
---|
337 | echo -e "\n\`date\`\n" >test-logs/$TESTLOGFILE
|
---|
338 | EOF
|
---|
339 | ) >> $MKFILE.tmp
|
---|
340 | }
|
---|
341 |
|
---|
342 | #----------------------------------#
|
---|
343 | wrt_target_vars() { # Target vars for hlfs (cross-build method)
|
---|
344 | #----------------------------------#
|
---|
345 | (
|
---|
346 | cat << EOF
|
---|
347 | @echo "export target=$(uname -m)-${TARGET}" >> envars && \\
|
---|
348 | echo "export ldso=/lib/${LOADER}" >> envars
|
---|
349 | EOF
|
---|
350 | ) >> $MKFILE.tmp
|
---|
351 |
|
---|
352 | }
|
---|
353 |
|
---|
354 |
|
---|
355 | #----------------------------------#
|
---|
356 | wrt_run_as_su() { # Execute script inside time { }, footer to log file
|
---|
357 | #----------------------------------#
|
---|
358 | local this_script=$1
|
---|
359 | local file=$2
|
---|
360 | (
|
---|
361 | cat << EOF
|
---|
362 | @( time { su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/${PROGNAME}-commands/$file" >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
|
---|
363 | echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
364 | EOF
|
---|
365 | ) >> $MKFILE.tmp
|
---|
366 | }
|
---|
367 |
|
---|
368 |
|
---|
369 | #----------------------------------#
|
---|
370 | wrt_run_as_root() { # Some scripts must be run as root..
|
---|
371 | #----------------------------------#
|
---|
372 | local this_script=$1
|
---|
373 | local file=$2
|
---|
374 | (
|
---|
375 | cat << EOF
|
---|
376 | @( time { export LFS=\$(MOUNT_PT) && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
|
---|
377 | echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/$this_script
|
---|
378 | EOF
|
---|
379 | ) >> $MKFILE.tmp
|
---|
380 | }
|
---|
381 |
|
---|
382 |
|
---|
383 | #----------------------------------#
|
---|
384 | wrt_run_as_root2() { #
|
---|
385 | #----------------------------------#
|
---|
386 | local this_script=$1
|
---|
387 | local file=$2
|
---|
388 | (
|
---|
389 | cat << EOF
|
---|
390 | @( time { source envars && ${PROGNAME}-commands/$file >>logs/$this_script 2>&1 ; } ) 2>>logs/$this_script && \\
|
---|
391 | echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \`\n" >>logs/$this_script
|
---|
392 | EOF
|
---|
393 | ) >> $MKFILE.tmp
|
---|
394 | }
|
---|
395 |
|
---|
396 |
|
---|
397 |
|
---|
398 | #----------------------------------#
|
---|
399 | wrt_run_as_chroot1() { #
|
---|
400 | #----------------------------------#
|
---|
401 | local this_script=$1
|
---|
402 | local file=$2
|
---|
403 | (
|
---|
404 | cat << EOF
|
---|
405 | @( time { \$(CHROOT1) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
|
---|
406 | echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
407 | EOF
|
---|
408 | ) >> $MKFILE.tmp
|
---|
409 | }
|
---|
410 |
|
---|
411 |
|
---|
412 | #----------------------------------#
|
---|
413 | wrt_run_as_chroot2() { #
|
---|
414 | #----------------------------------#
|
---|
415 | local this_script=$1
|
---|
416 | local file=$2
|
---|
417 | (
|
---|
418 | cat << EOF
|
---|
419 | @( time { \$(CHROOT2) 'cd /${SCRIPT_ROOT} && source envars && /${SCRIPT_ROOT}/${PROGNAME}-commands/$file >>/${SCRIPT_ROOT}/logs/${this_script} 2>&1' ; } ) 2>>logs/$this_script && \\
|
---|
420 | echo -e "\nKB: \`du -skx --exclude=${SCRIPT_ROOT} \$(MOUNT_PT)\`\n" >>logs/${this_script}
|
---|
421 | EOF
|
---|
422 | ) >> $MKFILE.tmp
|
---|
423 | }
|
---|
424 |
|
---|
425 |
|
---|
426 | #----------------------------------#
|
---|
427 | wrt_copy_fstab() { #
|
---|
428 | #----------------------------------#
|
---|
429 | local i=$1
|
---|
430 | (
|
---|
431 | cat << EOF
|
---|
432 | @cp -v $FSTAB \$(MOUNT_PT)/etc/fstab >>logs/$i 2>&1
|
---|
433 | EOF
|
---|
434 | ) >> $MKFILE.tmp
|
---|
435 | }
|
---|
436 |
|
---|
437 | #----------------------------------#
|
---|
438 | wrt_copy_fstab2() { #
|
---|
439 | #----------------------------------#
|
---|
440 | local i=$1
|
---|
441 | (
|
---|
442 | cat << EOF
|
---|
443 | @cp -v /sources/fstab /etc/fstab >>logs/$i 2>&1
|
---|
444 | EOF
|
---|
445 | ) >> $MKFILE.tmp
|
---|
446 | }
|
---|
447 |
|
---|
448 |
|
---|
449 | #----------------------------------#
|
---|
450 | wrt_remove_build_dirs() { #
|
---|
451 | #----------------------------------#
|
---|
452 | local name=$1
|
---|
453 | (
|
---|
454 | cat << EOF
|
---|
455 | @ROOT=\`head -n1 \$(MOUNT_PT)\$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
456 | rm -r \$(MOUNT_PT)\$(SRC)/\$\$ROOT && \\
|
---|
457 | if [ -e \$(MOUNT_PT)\$(SRC)/$name-build ]; then \\
|
---|
458 | rm -r \$(MOUNT_PT)\$(SRC)/$name-build; \\
|
---|
459 | fi;
|
---|
460 | EOF
|
---|
461 | ) >> $MKFILE.tmp
|
---|
462 | }
|
---|
463 |
|
---|
464 |
|
---|
465 | #----------------------------------#
|
---|
466 | wrt_remove_build_dirs2() { #
|
---|
467 | #----------------------------------#
|
---|
468 | local name=$1
|
---|
469 | (
|
---|
470 | cat << EOF
|
---|
471 | @ROOT=\`head -n1 \$(SRC)/\$(PKG_LST) | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
472 | rm -r \$(SRC)/\$\$ROOT && \\
|
---|
473 | if [ -e \$(SRC)/$name-build ]; then \\
|
---|
474 | rm -r \$(SRC)/$name-build; \\
|
---|
475 | fi;
|
---|
476 | EOF
|
---|
477 | ) >> $MKFILE.tmp
|
---|
478 | }
|
---|
479 |
|
---|
480 |
|
---|
481 | #----------------------------------#
|
---|
482 | wrt_touch() { #
|
---|
483 | #----------------------------------#
|
---|
484 | (
|
---|
485 | cat << EOF
|
---|
486 | @touch \$@ && \\
|
---|
487 | sleep .25 && \\
|
---|
488 | echo -e "\n\n "\$(BOLD)Target \$(BLUE)\$@ \$(BOLD)OK && \\
|
---|
489 | echo --------------------------------------------------------------------------------\$(WHITE)
|
---|
490 | EOF
|
---|
491 | ) >> $MKFILE.tmp
|
---|
492 | }
|
---|
493 |
|
---|
494 |
|
---|
495 | #----------------------------------#
|
---|
496 | wrt_report() { #
|
---|
497 | #----------------------------------#
|
---|
498 | (
|
---|
499 | cat << EOF
|
---|
500 |
|
---|
501 | create-sbu_du-report: $PREV
|
---|
502 | @\$(call echo_message, Building)
|
---|
503 | @./create-sbu_du-report.sh logs $VERSION
|
---|
504 | @\$(call echo_report,$VERSION-SBU_DU-$(date --iso-8601).report)
|
---|
505 | @touch \$@
|
---|
506 | EOF
|
---|
507 | ) >> $MKFILE.tmp
|
---|
508 |
|
---|
509 | chapter789="$chapter789 create-sbu_du-report"
|
---|
510 | }
|
---|
511 |
|
---|
512 |
|
---|
513 | #----------------------------#
|
---|
514 | run_make() { #
|
---|
515 | #----------------------------#
|
---|
516 | # Test if make must be run.
|
---|
517 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
518 | # Test to make sure we're running the build as root
|
---|
519 | if [ "$UID" != "0" ] ; then
|
---|
520 | echo "You must be logged in as root to successfully build the system."
|
---|
521 | exit 1
|
---|
522 | fi
|
---|
523 | # Build the system
|
---|
524 | if [ -e $MKFILE ] ; then
|
---|
525 | echo -ne "Building the system...\n"
|
---|
526 | cd $JHALFSDIR && make
|
---|
527 | echo -ne "done\n"
|
---|
528 | fi
|
---|
529 | fi
|
---|
530 | }
|
---|
531 |
|
---|
532 |
|
---|
533 | #----------------------------#
|
---|
534 | clean_builddir() { #
|
---|
535 | #----------------------------#
|
---|
536 | # Test if the clean must be done.
|
---|
537 | if [ "$CLEAN" = "1" ] ; then
|
---|
538 | # Test to make sure we're running the clean as root
|
---|
539 | if [ "$UID" != "0" ] ; then
|
---|
540 | echo "You must be logged in as root to clean the build directory."
|
---|
541 | exit 1
|
---|
542 | fi
|
---|
543 | # Test to make sure that the build directory was populated by jhalfs
|
---|
544 | if [ ! -d $JHALFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
|
---|
545 | echo "Looks like $BUILDDIR was not populated by a previous jhalfs run."
|
---|
546 | exit 1
|
---|
547 | else
|
---|
548 | # Clean the build directory
|
---|
549 | echo -ne "Cleaning $BUILDDIR...\n"
|
---|
550 | rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,cross-tools,usr,var}
|
---|
551 | echo -ne "Cleaning $JHALFSDIR...\n"
|
---|
552 | rm -rf $JHALFSDIR/{0*,1*,envars,sources-dir,*commands,*logs,Makefile,*.xsl,makefile-functions,pkg_tarball_list,*.config,*.sh}
|
---|
553 | echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
|
---|
554 | rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
|
---|
555 | echo -ne "done\n"
|
---|
556 | fi
|
---|
557 | fi
|
---|
558 | }
|
---|
559 |
|
---|
560 | #----------------------------#
|
---|
561 | get_book() { #
|
---|
562 | #----------------------------#
|
---|
563 | cd $JHALFSDIR
|
---|
564 |
|
---|
565 | if [ -z $WC ] ; then
|
---|
566 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
567 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
568 | exit 1"
|
---|
569 | echo -n "Downloading the $PROGNAME document, $LFSVRS version... "
|
---|
570 |
|
---|
571 | case $PROGNAME in
|
---|
572 | lfs) svn_root="LFS" ;;
|
---|
573 | hlfs) svn_root="HLFS" ;;
|
---|
574 | clfs) svn_root="cross-lfs" ;;
|
---|
575 | *) echo "BOOK not defined in function <get_book>"
|
---|
576 | exit 1 ;;
|
---|
577 | esac
|
---|
578 | # Grab a fresh book if it's missing, otherwise, update it from the
|
---|
579 | # repo. If we've already extracted the commands, move on to getting the
|
---|
580 | # sources.
|
---|
581 | if [ -d ${PROGNAME}-$LFSVRS ] ; then
|
---|
582 | cd ${PROGNAME}-$LFSVRS
|
---|
583 | if LC_ALL=C svn up | grep -q At && \
|
---|
584 | test -d $JHALFSDIR/${PROGNAME}-commands && \
|
---|
585 | test -f $JHALFSDIR/pkg_tarball_list ; then
|
---|
586 | # Set the canonical book version
|
---|
587 | echo -ne "done\n"
|
---|
588 | cd $JHALFSDIR
|
---|
589 | case $PROGNAME in
|
---|
590 | clfs)
|
---|
591 | VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
592 | *)
|
---|
593 | VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
594 | esac
|
---|
595 | get_sources
|
---|
596 | else
|
---|
597 | echo -ne "done\n"
|
---|
598 | extract_commands
|
---|
599 | fi
|
---|
600 | else
|
---|
601 | case $LFSVRS in
|
---|
602 | development)
|
---|
603 | svn co $SVN/${svn_root}/trunk/BOOK ${PROGNAME}-$LFSVRS >>$LOGDIR/$LOG 2>&1 ;;
|
---|
604 | esac
|
---|
605 | echo -ne "done\n"
|
---|
606 | extract_commands
|
---|
607 | fi
|
---|
608 |
|
---|
609 | else
|
---|
610 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
611 | extract_commands
|
---|
612 | fi
|
---|
613 | echo -ne " Document version ${L_arrow}${BOLD}${VERSION}${R_arrow}\n"
|
---|
614 | }
|
---|
615 |
|
---|
616 | #----------------------------#
|
---|
617 | extract_commands() { #
|
---|
618 | #----------------------------#
|
---|
619 |
|
---|
620 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
621 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
622 | exit 1"
|
---|
623 |
|
---|
624 | cd $JHALFSDIR
|
---|
625 | case $PROGNAME in
|
---|
626 | clfs)
|
---|
627 | VERSION=$(xmllint --noent $BOOK/prologue/$ARCH/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
628 | *)
|
---|
629 | VERSION=$(xmllint --noent $BOOK/prologue/bookinfo.xml 2>/dev/null | grep subtitle | sed -e 's/^.*ion //' -e 's/<\/.*//') ;;
|
---|
630 | esac
|
---|
631 |
|
---|
632 | # Start clean
|
---|
633 | if [ -d ${PROGNAME}-commands ]; then
|
---|
634 | rm -rf ${PROGNAME}-commands
|
---|
635 | mkdir -v ${PROGNAME}-commands
|
---|
636 | fi
|
---|
637 | echo -n "Extracting commands for"
|
---|
638 |
|
---|
639 | # Dump the commands in shell script form from the HLFS book.
|
---|
640 | case ${PROGNAME} in
|
---|
641 | clfs)
|
---|
642 | echo -n " ${L_arrow}${BOLD}$ARCH${R_arrow} target architecture"
|
---|
643 | xsltproc --nonet \
|
---|
644 | --xinclude \
|
---|
645 | --stringparam method $METHOD \
|
---|
646 | --stringparam testsuite $TEST \
|
---|
647 | --stringparam vim-lang $VIMLANG \
|
---|
648 | --stringparam timezone $TIMEZONE \
|
---|
649 | --stringparam page $PAGE \
|
---|
650 | --stringparam lang $LANG \
|
---|
651 | --stringparam keymap $KEYMAP \
|
---|
652 | -o ./${PROGNAME}-commands/ $XSL $BOOK/$ARCH-index.xml >>$LOGDIR/$LOG 2>&1
|
---|
653 | ;;
|
---|
654 | hlfs)
|
---|
655 | echo -n " ${L_arrow}${BOLD}$MODEL${R_arrow} HLFS libc implementation"
|
---|
656 | xsltproc --nonet \
|
---|
657 | --xinclude \
|
---|
658 | --stringparam model $MODEL \
|
---|
659 | --stringparam testsuite $TEST \
|
---|
660 | --stringparam timezone $TIMEZONE \
|
---|
661 | --stringparam page $PAGE \
|
---|
662 | --stringparam lang $LANG \
|
---|
663 | --stringparam lc_all $LC_ALL \
|
---|
664 | --stringparam keymap $KEYMAP \
|
---|
665 | --stringparam grsecurity_host $GRSECURITY_HOST \
|
---|
666 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
667 | ;;
|
---|
668 | lfs)
|
---|
669 | echo -n " ${L_arrow}${BOLD}LFS${R_arrow} build"
|
---|
670 | xsltproc --nonet \
|
---|
671 | --xinclude \
|
---|
672 | --stringparam testsuite $TEST \
|
---|
673 | --stringparam vim-lang $VIMLANG \
|
---|
674 | --stringparam timezone $TIMEZONE \
|
---|
675 | --stringparam page $PAGE \
|
---|
676 | --stringparam lang $LANG \
|
---|
677 | -o ./${PROGNAME}-commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
678 | ;;
|
---|
679 | *) exit 1 ;;
|
---|
680 | esac
|
---|
681 |
|
---|
682 | echo " ...OK"
|
---|
683 |
|
---|
684 | # Make the scripts executable.
|
---|
685 | chmod -R +x $JHALFSDIR/${PROGNAME}-commands
|
---|
686 |
|
---|
687 | # Create the packages file. We need it for proper Makefile creation
|
---|
688 | create_package_list
|
---|
689 |
|
---|
690 | # Done. Moving on...
|
---|
691 | get_sources
|
---|
692 | }
|
---|
693 |
|
---|
694 | #----------------------------#
|
---|
695 | create_package_list() { #
|
---|
696 | #----------------------------#
|
---|
697 |
|
---|
698 | # Create the packages file. We need it for proper Makefile creation
|
---|
699 | rm -f pkg_tarball_list
|
---|
700 | echo -n "Creating <${PROGNAME}> list of tarball names for $BOOK $ARCH"
|
---|
701 | case ${PROGNAME} in
|
---|
702 | clfs)
|
---|
703 | xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
|
---|
704 | $BOOK/materials/${ARCH}-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
705 | ;;
|
---|
706 | hlfs)
|
---|
707 | xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
|
---|
708 | $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
|
---|
709 | ;;
|
---|
710 | lfs)
|
---|
711 | xsltproc --nonet --xinclude -o pkg_tarball_list packages.xsl \
|
---|
712 | $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
|
---|
713 | ;;
|
---|
714 | esac
|
---|
715 | echo " ...OK"
|
---|
716 |
|
---|
717 | }
|
---|
718 |
|
---|
719 |
|
---|
720 | #----------------------------#
|
---|
721 | get_sources() { # Download file, write name to MISSING_FILES.DMP if an error
|
---|
722 | #----------------------------#
|
---|
723 | local saveIFS=$IFS
|
---|
724 | local IFS line URL1 URL2 FILE BOOKMD5 MD5 HAVEMD5 fromARCHIVE
|
---|
725 |
|
---|
726 | # Test if the packages must be downloaded
|
---|
727 | [ ! "$GETPKG" = "1" ] && return
|
---|
728 |
|
---|
729 | gs_wrt_message(){
|
---|
730 | echo "${RED}$1${OFF}"
|
---|
731 | echo "$1" >> MISSING_FILES.DMP
|
---|
732 | }
|
---|
733 | # Housekeeping
|
---|
734 | [[ ! -d $BUILDDIR/sources ]] && mkdir $BUILDDIR/sources
|
---|
735 | cd $BUILDDIR/sources
|
---|
736 | [[ -f MD5SUMS ]] && rm MD5SUMS
|
---|
737 | [[ -f MISSING_FILES.DMP ]] && rm MISSING_FILES.DMP
|
---|
738 | [[ -f urls.lst ]] && rm urls.lst
|
---|
739 |
|
---|
740 | # Generate URLs file
|
---|
741 | create_urls
|
---|
742 |
|
---|
743 | IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
|
---|
744 | for line in `cat urls.lst`; do
|
---|
745 | IFS=$saveIFS # Restore the system defaults
|
---|
746 |
|
---|
747 | # Skip some packages if they aren't needed
|
---|
748 | case $line in
|
---|
749 | */tcl* | */expect* | */dejagnu* | */tree* | */gcc-testsuite* )
|
---|
750 | [[ "$TEST" = "0" ]] && continue
|
---|
751 | ;;
|
---|
752 | */vim-*-lang* )
|
---|
753 | [[ "$VIMLANG" = "0" ]] && continue
|
---|
754 | ;;
|
---|
755 | *linux/linux-* )
|
---|
756 | [[ -z "$CONFIG" ]] && [[ -z "$BOOT_CONFIG" ]] && \
|
---|
757 | [[ "$GETKERNEL" = "0" ]] && continue
|
---|
758 | ;;
|
---|
759 | esac
|
---|
760 |
|
---|
761 | # Locations
|
---|
762 | URL1=`echo $line | cut -d" " -f2` # Preferred URL
|
---|
763 | URL2=`echo $line | cut -d" " -f1` # Fallback Upstream URL
|
---|
764 | FILE=`basename $URL1` # File name
|
---|
765 | BOOKMD5=`echo $line | cut -d" " -f3` # MD5 book value
|
---|
766 |
|
---|
767 | # Validation pair
|
---|
768 | MD5="$BOOKMD5 $FILE"
|
---|
769 | HAVEMD5=1
|
---|
770 |
|
---|
771 | set -e
|
---|
772 | # If the file exists in the archive copy it to the
|
---|
773 | # $BUILDDIR/sources dir. MD5SUM will be validated later.
|
---|
774 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
775 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
776 | [ -f ${SRC_ARCHIVE}/$FILE ]; then
|
---|
777 | cp ${SRC_ARCHIVE}/$FILE .
|
---|
778 | echo "$FILE: -- copied from $SRC_ARCHIVE"
|
---|
779 | fromARCHIVE=1
|
---|
780 | else
|
---|
781 | echo "${BOLD}${YELLOW}$FILE: not found in ${SRC_ARCHIVE}${OFF}"
|
---|
782 | fromARCHIVE=0
|
---|
783 | # If the file does not exist yet in /sources download a fresh one
|
---|
784 | if [ ! -f $FILE ] ; then
|
---|
785 | if ! wget $URL1 && ! wget $URL2 ; then
|
---|
786 | gs_wrt_message "$FILE not found in the SRC_ARCHIVE or on any server..SKIPPING"
|
---|
787 | continue
|
---|
788 | fi
|
---|
789 | fi
|
---|
790 | fi
|
---|
791 |
|
---|
792 | # IF the md5sum does not match the existing files
|
---|
793 | if ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
794 | [[ $fromARCHIVE = "1" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match SRC_ARCHIVE copy${OFF}"
|
---|
795 | [[ $fromARCHIVE = "0" ]] && echo "${BOLD}${YELLOW}MD5SUM did not match REMOTE copy${OFF}"
|
---|
796 | # Remove the old file and download a new one
|
---|
797 | rm -fv $FILE
|
---|
798 | # Force storage in SRC_ARCHIVE
|
---|
799 | fromARCHIVE=0;
|
---|
800 | # Try to retrieve again the file. Servers in reverse order.
|
---|
801 | if ! wget $URL2 && ! wget $URL1 ; then
|
---|
802 | gs_wrt_message "$FILE not found on the servers.. SKIPPING"
|
---|
803 | continue
|
---|
804 | fi
|
---|
805 | fi
|
---|
806 |
|
---|
807 | # Validate the MD5SUM one last time
|
---|
808 | if ! echo "$MD5" | md5sum -c - >/dev/null ; then
|
---|
809 | gs_wrt_message "$FILE does not match MD5SUMS value"
|
---|
810 | # Force generation of MD5SUM
|
---|
811 | HAVEMD5=0
|
---|
812 | fi
|
---|
813 |
|
---|
814 | # Generate a fresh MD5SUM for this file
|
---|
815 | if [[ "$HAVEMD5" = "0" ]] ; then
|
---|
816 | echo "${BOLD}${YELLOW}Generating a new MD5SUM for ${OFF}$FILE"
|
---|
817 | echo "NEW MD5SUM: $(md5sum $FILE)" >> MISSING_FILES.DMP
|
---|
818 | fi
|
---|
819 |
|
---|
820 | # Good or bad we write the original md5sum to a file
|
---|
821 | echo "$MD5" >> MD5SUMS
|
---|
822 |
|
---|
823 | # Copy the freshly downloaded file
|
---|
824 | # to the source archive.
|
---|
825 | if [ ! -z ${SRC_ARCHIVE} ] &&
|
---|
826 | [ -d ${SRC_ARCHIVE} ] &&
|
---|
827 | [ -w ${SRC_ARCHIVE} ] &&
|
---|
828 | [ "$fromARCHIVE" = "0" ] ; then
|
---|
829 | echo "Storing file:<$FILE> in the package archive"
|
---|
830 | cp -f $FILE ${SRC_ARCHIVE}
|
---|
831 | fi
|
---|
832 |
|
---|
833 | done
|
---|
834 |
|
---|
835 | if [[ -s MISSING_FILES.DMP ]]; then
|
---|
836 | echo -e "\n\n${tab_}${RED} One or more files were not retrieved or have a bad MD5SUMS chechsum.\n${tab_} Check ${L_arrow}$BUILDDIR/sources/MISSING_FILES.DMP${R_arrow} for names ${OFF}\n"
|
---|
837 | # Do not allow the automatic exection of the Makefile.
|
---|
838 | echo "${tab_}${BOLD}${RED}*** ${YELLOW}Automatic execution of the generated makefile has been inhibited. ${RED}***${OFF}${nl_}"
|
---|
839 | RUNMAKE=0
|
---|
840 | fi
|
---|
841 | }
|
---|
842 |
|
---|
843 | #----------------------------#
|
---|
844 | create_urls() { #
|
---|
845 | #----------------------------#
|
---|
846 | cd $JHALFSDIR
|
---|
847 |
|
---|
848 | case ${PROGNAME} in
|
---|
849 | clfs)
|
---|
850 | echo -n "Creating CLFS <${ARCH}> specific URLs file"
|
---|
851 | xsltproc --nonet --xinclude \
|
---|
852 | --stringparam server $SERVER \
|
---|
853 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
854 | $BOOK/materials/$ARCH-chapter.xml >>$LOGDIR/$LOG 2>&1
|
---|
855 | echo " ...OK"
|
---|
856 | ;;
|
---|
857 | hlfs)
|
---|
858 | echo -n "Creating HLFS <${MODEL}> specific URLs file"
|
---|
859 | xsltproc --nonet --xinclude \
|
---|
860 | --stringparam server $SERVER \
|
---|
861 | --stringparam model $MODEL \
|
---|
862 | -o $BUILDDIR/sources/urls.lst urls.xsl \
|
---|
863 | $BOOK/chapter04/chapter04.xml >>$LOGDIR/$LOG 2>&1
|
---|
864 | echo " ...OK"
|
---|
865 | ;;
|
---|
866 | lfs)
|
---|
867 | echo -n "Creating LFS specific URLs file"
|
---|
868 | xsltproc --nonet --xinclude \
|
---|
869 | --stringparam server $SERVER \
|
---|
870 | -o ../sources/urls.lst urls.xsl \
|
---|
871 | $BOOK/chapter03/chapter03.xml >>$LOGDIR/$LOG 2>&1
|
---|
872 | echo " ...OK"
|
---|
873 | ;;
|
---|
874 | esac
|
---|
875 |
|
---|
876 | cd $BUILDDIR/sources
|
---|
877 | }
|
---|