source: jhalfs@ 316b8d7

0.2
Last change on this file since 316b8d7 was 316b8d7, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

Merged revisions 2175, 2176 to branches/0.2

  • Property mode set to 100755
File size: 26.4 KB
Line 
1#!/bin/sh
2
3#
4# Load the configuration file
5#
6source jhalfs.conf
7
8
9version="
10jhalfs 0.2-pre1 \$Date$
11
12Written by Jeremy Huntwork and Manuel Canales Esparcia.
13
14This program is published under the \
15Gnu General Public License, Version 2.
16"
17
18usage="\
19Usage: $0 [OPTION]
20
21Options:
22 -h, --help print this help, then exit
23
24 -V, --version print version number, then exit
25
26 -d --directory DIR use DIR directory for building LFS; all files
27 jhalfs produces will be in the directory
28 DIR/jhalfs. Default is \"/mnt/lfs\".
29
30 -P, --get-packages download the packages and patches. This
31 assumes that the server declared in the
32 jhalfs.conf file has the proper packages
33 and patches for the book version being
34 processed.
35
36 -D, --download-client CLIENT use CLIENT as the program for retrieving
37 packages (for use in conjunction with -P)
38
39 -W, --working-copy DIR use the local working copy placed in DIR
40 as the LFS book
41
42 -L, --LFS-version VER checkout VER version of the LFS book.
43 Supported versions at this time are:
44
45 dev* | trunk | SVN aliases for Development LFS
46 testing | 6.1.1 aliases for the testing 6.1.1 branch
47
48 -T, --testsuites add support to run the optional testsuites
49
50 --no-toolchain-test don't run the toolchain testsuites. This
51 also disables the build of TCL, Expect
52 and DejaGNU
53
54 --timezone TIMEZONE set TIMEZONE as the local timezone. If not
55 specified, \"Europe/London\" will be used.
56
57 --page_size PAGE set PAGE as the default page size (letter
58 or A4). This setting is required to
59 build Groff. If not specified, \"letter\"
60 will be used.
61
62 --fstab FILE use FILE as the /etc/fstab file for the
63 LFS system. If not specified, a default
64 /etc/fstab file with dummy values is
65 created.
66
67 -C, --kernel-config FILE use the kernel configuration file specified
68 in FILE to build the kernel. If the file is
69 not found, or if not specified, the kernel
70 build is skipped.
71
72 -M, --run-make run make on the generated Makefile
73
74"
75
76help="\
77Try '$0 --help' for more information."
78
79exit_missing_arg="\
80echo \"Option '\$1' requires an argument\" >&2
81echo \"\$help\" >&2
82exit 1"
83
84no_dl_client="\
85echo \"Could not find a way to download the LFS sources.\" >&2
86echo \"Attempting to continue.\" >&2"
87
88
89HEADER="# This file is automatically generated by jhalfs
90# DO NOT EDIT THIS FILE MANUALLY
91#
92# Generated on `date \"+%F %X %Z\"`"
93
94
95###################################
96### FUNCTIONS ###
97###################################
98
99
100#----------------------------#
101get_book() {
102#----------------------------#
103 # Check for Subversion instead of just letting the script hit 'svn' and fail.
104 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
105 exit 1"
106 cd $JHALFSDIR
107
108 # Test to make sure the LFS version is set
109 if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
110
111 # Set the book's sources directory
112 if [ -z $BOOK ] ; then BOOK=lfs-$LFSVRS ; fi
113
114 if [ -z $WC ] ; then
115 echo -n "Downloading the LFS Book, version $LFSVRS... "
116
117 # Grab the LFS book fresh if it's missing, otherwise, update it from the
118 # repo. If we've already extracted the commands, move on to getting the
119 # sources.
120 if [ -d lfs-$LFSVRS ] ; then
121 cd lfs-$LFSVRS
122 if svn up | grep -q At && test -d $JHALFSDIR/commands && \
123 test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
124 echo -ne "done\n"
125 get_sources
126 else
127 echo -ne "done\n"
128 extract_commands
129 fi
130 else
131 if [ $LFSVRS = development ] ; then
132 svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
133 else
134 svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
135 fi
136 echo -ne "done\n"
137 extract_commands
138 fi
139 else
140 echo -ne "Using $BOOK as book's sources ...\n"
141 extract_commands
142 fi
143 # Set the canonical book version
144 cd $JHALFSDIR
145 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed -e 's@<!ENTITY version "@@' -e 's@">@@'`
146}
147
148#----------------------------#
149extract_commands() {
150#----------------------------#
151 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
152 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
153 exit 1"
154 cd $JHALFSDIR
155
156 # Start clean
157 if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
158 echo -n "Extracting commands... "
159
160 # Dump the commands in shell script form from the LFS book.
161 xsltproc --nonet --xinclude --stringparam testsuite $TEST \
162 --stringparam toolchaintest $TOOLCHAINTEST -o ./commands/ \
163 $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
164
165 # Make the scripts executable.
166 chmod -R +x $JHALFSDIR/commands
167
168 # Grab the patches and package names.
169 cd $JHALFSDIR
170 for i in patches packages ; do rm -f $i ; done
171 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
172 -e '/generic/d' >> packages
173 echo `grep "glibc" packages | sed 's@glibc@&-linuxthreads@'` >> packages
174 echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
175 # Download the module-init-tools-testsuite package only
176 # if the test suite will be run.
177 if [ "$TEST" = "1" ] ; then
178 echo `grep "module" packages | sed 's@tools@&-testsuite@'` >> packages
179 fi
180 # If we are buildind the UTF-8 branch, the glibc-libidn package is required
181 if grep -q "man-db-version" $BOOK/general.ent ; then
182 echo `grep "glibc" packages | sed 's@glibc@glibc-libidn@'` >> packages
183 fi
184 grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
185
186 # Done. Moving on...
187 echo -ne "done\n"
188 get_sources
189}
190
191#----------------------------#
192download() {
193#----------------------------#
194 cd $BUILDDIR/sources
195
196 # Hackish fix for the bash-doc, glibc-{linuxthreads,libidn} and
197 # module-init-tools-testsuite packages that doesn't conform to
198 # norms in the URL scheme.
199 DIR=`echo $1 | sed 's@-doc@@;s@-linuxthreads@@;s@-libidn@@;s@-testsuite@@'`
200
201 # Find the md5 sum for this package.
202 if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
203
204 if [ ! -f $2 ] ; then
205 case $DL in
206 wget )
207 wget $HTTP/$DIR/$2
208 ;;
209 curl )
210 `curl -# $HTTP/$DIR/$2 -o $2`
211 ;;
212 * )
213 echo "$DL not supported at this time."
214 ;;
215 esac
216 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
217 case $DL in
218 wget )
219 wget -c $HTTP/$DIR/$2
220 ;;
221 curl )
222 `curl -# -C - $HTTP/$DIR/$2 -o $2`
223 ;;
224 * )
225 echo "$DL not supported at this time."
226 ;;
227 esac
228 fi
229 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
230 exit 1
231 fi
232}
233
234#----------------------------#
235get_sources() {
236#----------------------------#
237
238 # Test if the packages must be downloaded
239 if [ "$HPKG" = "1" ] ; then
240
241 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
242 # separates each iteration by lines. It is necessary to have the second
243 # ' on the next line.
244 IFS='
245'
246
247 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
248 cd $BUILDDIR/sources
249 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
250
251 download "" MD5SUMS
252
253 # Iterate through each package and grab it, along with any patches it needs.
254 for i in `cat $JHALFSDIR/packages` ; do
255 PKG=`echo $i | sed -e 's/-version.*//' -e 's/-file.*//'`
256 # Needed for Groff patchlevel patch on UTF-8 branch
257 GROFFLEVEL=`grep "groff-patchlevel" $JHALFSDIR/packages | sed -e 's/groff-patchlevel //' -e 's/"//g'`
258
259 # There is some entities that aren't valid package entities.
260 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" -o "$PKG" = "groff-patchlevel" ] ; then continue ; fi
261
262 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
263 if [ "$PKG" = "tcl" ] ; then
264 FILE="$PKG$VRS-src.tar.bz2"
265 elif [ "$PKG" = "udev-config" ] ; then
266 PKG="udev"
267 FILE="$VRS"
268 else
269 FILE="$PKG-$VRS.tar.bz2"
270 fi
271 download $PKG $FILE
272 for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
273 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
274 download $PKG $PATCH
275 done
276 # Needed for Groff patchlevel patch on UTF-8 branch
277 for patch in `grep "patchlevel" $JHALFSDIR/patches` ; do
278 PATCH=`echo $patch | sed 's@&'$PKG'-version;-&'$PKG'-patchlevel;@'$VRS'-'$GROFFLEVEL'@'`
279 download $PKG $PATCH
280 done
281 done
282 fi
283}
284
285#-----------------------------------------------#
286_IS_() # Function to test build scripts names
287#-----------------------------------------------#
288{
289 # Returns substr $2 or null str
290 # Must use string testing
291 case $1 in
292 *$2*) echo "$2" ;;
293 *) echo "" ;;
294 esac
295}
296
297#----------------------------#
298chapter4_Makefiles() {
299#----------------------------#
300(
301 cat << EOF
302020-creatingtoolsdir:
303 @\$(call echo_message, Building)
304 @mkdir -v \$(LFS)/tools && \\
305 ln -sv \$(LFS)/tools / && \\
306 touch \$@
307
308021-addinguser: 020-creatingtoolsdir
309 @\$(call echo_message, Building)
310 @groupadd lfs && \\
311 useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
312 chown lfs \$(LFS)/tools && \\
313 chown lfs \$(LFS)/sources && \\
314 touch \$@
315
316022-settingenvironment: 021-addinguser
317 @\$(call echo_message, Building)
318 @echo "set +h" > /home/lfs/.bashrc && \\
319 echo "umask 022" >> /home/lfs/.bashrc && \\
320 echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
321 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
322 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
323 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
324 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
325 chown lfs:lfs /home/lfs/.bashrc && \\
326 touch envars && \\
327 touch \$@
328EOF
329) >> $MKFILE.tmp
330}
331
332#----------------------------#
333chapter5_Makefiles() {
334#----------------------------#
335 for file in chapter05/* ; do
336 # Keep the script file name
337 i=`basename $file`
338
339 # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
340 if [ "$TOOLCHAINTEST" = "0" ]; then
341 if [[ `_IS_ $i tcl` ]] || [[ `_IS_ $i expect` ]] || [[ `_IS_ $i dejagnu` ]] ; then
342 continue
343 fi
344 fi
345
346 # First append each name of the script files to a list (this will become
347 # the names of the targets in the Makefile
348 chapter5="$chapter5 $i"
349
350 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
351 # and binutils in chapter 5)
352 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
353
354 # Set the dependency for the first target.
355 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
356
357 # Drop in the name of the target on a new line, and the previous target
358 # as a dependency. Also call the echo_message function.
359(
360 cat << EOF
361
362$i: $PREV
363 @\$(call echo_message, Building)
364EOF
365) >> $MKFILE.tmp
366
367 # Find the version of the command files, if it corresponds with the building of
368 # a specific package
369 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
370
371 # If $vrs isn't empty, we've got a package...
372 if [ "$vrs" != "" ] ; then
373 if [ "$name" = "tcl" ] ; then
374 FILE="$name$vrs-src.tar"
375 else
376 FILE="$name-$vrs.tar"
377 fi
378
379 # Insert instructions for unpacking the package and to set
380 # the PKGDIR variable.
381(
382 cat << EOF
383 @\$(call unpack,$FILE)
384 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
385 chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
386 echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
387 echo "export PKGDIR" >> envars && \\
388EOF
389) >> $MKFILE.tmp
390
391 fi
392
393 # Dump the path to the Binutils or TCL sources directory.
394 if [[ `_IS_ $i binutils` ]] || [[ `_IS_ $i tcl` ]] ; then
395(
396 cat << EOF
397 echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
398EOF
399) >> $MKFILE.tmp
400
401 # For the Adjusting phase we must to cd to the binutils-build directory.
402 elif [[ `_IS_ $i adjusting` ]] ; then
403(
404 cat << EOF
405 @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
406 echo "export PKGDIR" >> envars
407EOF
408) >> $MKFILE.tmp
409
410 # For the Expect build we need to set the TCLPATH envar.
411 elif [[ `_IS_ $i expect` ]] ; then
412(
413 cat << EOF
414 echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
415 echo "export TCLPATH" >> envars
416EOF
417) >> $MKFILE.tmp
418
419 # Everything else, add a true statment so we don't confuse make
420 else
421(
422 cat << EOF
423 true
424EOF
425) >> $MKFILE.tmp
426 fi
427
428 # Insert date and disk usage at the top of the log file, the script run
429 # and date and disk usage again at the bottom of the log file.
430(
431 cat << EOF
432 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
433 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
434 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
435EOF
436) >> $MKFILE.tmp
437
438 # Remove the build directory(ies) except if the package build fails
439 # (to can review config.cache, config.log, and like.)
440 # For Binutils and TCL the sources must be retained some time.
441 if [ "$vrs" != "" ] ; then
442 if [[ ! `_IS_ $i binutils` ]] && [[ ! `_IS_ $i tcl` ]] ; then
443(
444 cat << EOF
445 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
446 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
447 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
448 rm -r \$(LFS)\$(SRC)/$name-build; \\
449 fi;
450EOF
451) >> $MKFILE.tmp
452 fi
453 fi
454
455 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
456 if [[ `_IS_ $i adjusting` ]] ; then
457(
458 cat << EOF
459 @rm -r \`cat sources-dir\` && \\
460 rm -r \$(LFS)\$(SRC)/binutils-build && \\
461 rm sources-dir
462EOF
463) >> $MKFILE.tmp
464 fi
465
466 # Remove the TCL sources after a successful Expect build.
467 if [[ `_IS_ $i expect` ]] ; then
468(
469 cat << EOF
470 @rm -r \`cat sources-dir\` && \\
471 rm sources-dir
472EOF
473) >> $MKFILE.tmp
474 fi
475
476 # Include a touch of the target name so make can check
477 # if it's already been made.
478(
479 cat << EOF
480 @touch \$@
481EOF
482) >> $MKFILE.tmp
483
484 # Keep the script file name for Makefile dependencies.
485 PREV=$i
486 done # end for file in chapter05/*
487}
488
489#----------------------------#
490chapter6_Makefiles() {
491#----------------------------#
492 for file in chapter06/* ; do
493 # Keep the script file name
494 i=`basename $file`
495
496 # We'll run the chroot commands differently than the others, so skip them in the
497 # dependencies and target creation.
498 if [[ `_IS_ $i chroot` ]] ; then
499 continue
500 fi
501
502 # First append each name of the script files to a list (this will become
503 # the names of the targets in the Makefile
504 chapter6="$chapter6 $i"
505
506 # Grab the name of the target
507 name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
508
509 # Drop in the name of the target on a new line, and the previous target
510 # as a dependency. Also call the echo_message function.
511(
512 cat << EOF
513
514$i: $PREV
515 @\$(call echo_message, Building)
516EOF
517) >> $MKFILE.tmp
518
519 # Find the version of the command files, if it corresponds with the building of
520 # a specific package
521 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
522
523 # If $vrs isn't empty, we've got a package...
524 # Insert instructions for unpacking the package and changing directories
525 if [ "$vrs" != "" ] ; then
526 FILE="$name-$vrs.tar.*"
527(
528 cat << EOF
529 @\$(call unpack2,$FILE)
530 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
531 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
532 echo "export PKGDIR" >> envars
533EOF
534) >> $MKFILE.tmp
535 fi
536
537 # For the Re-Adjusting phase we must to cd to the binutils-build directory.
538 if [[ `_IS_ $i readjusting` ]] ; then
539(
540 cat << EOF
541 @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
542 echo "export PKGDIR" >> envars
543EOF
544) >> $MKFILE.tmp
545
546 # For Glibc we need to set TIMEZONE envar.
547 elif [[ `_IS_ $i glibc` ]] ; then
548(
549 cat << EOF
550 @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
551 echo "export TIMEZONE" >> envars
552EOF
553) >> $MKFILE.tmp
554
555 # For Groff we need to set PAGE envar.
556 elif [[ `_IS_ $i groff` ]] ; then
557(
558 cat << EOF
559 @echo "PAGE=\$(PAGE)" >> envars && \\
560 echo "export PAGE" >> envars
561EOF
562) >> $MKFILE.tmp
563 fi
564
565 # In the mount of kernel filesystems we need to set LFS
566 # and not to use chroot.
567 if [[ `_IS_ $i kernfs` ]] ; then
568(
569 cat << EOF
570 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
571 export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
572 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
573EOF
574) >> $MKFILE.tmp
575
576 # The rest of Chapter06
577 else
578(
579 cat << EOF
580 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
581 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
582 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
583EOF
584) >> $MKFILE.tmp
585 fi
586
587 # Remove the build directory(ies) except if the package build fails.
588 if [ "$vrs" != "" ] ; then
589(
590 cat << EOF
591 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
592 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
593 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
594 rm -r \$(LFS)\$(SRC)/$name-build; \\
595 fi;
596EOF
597) >> $MKFILE.tmp
598 fi
599
600 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
601 if [[ `_IS_ $i readjusting` ]] ; then
602(
603 cat << EOF
604 @rm -r \`cat sources-dir\` && \\
605 rm -r \$(LFS)\$(SRC)/binutils-build && \\
606 rm sources-dir
607EOF
608) >> $MKFILE.tmp
609 fi
610
611 # Include a touch of the target name so make can check
612 # if it's already been made.
613(
614 cat << EOF
615 @touch \$@
616EOF
617) >> $MKFILE.tmp
618
619 # Keep the script file name for Makefile dependencies.
620 PREV=$i
621 done # end for file in chapter06/*
622}
623
624#----------------------------#
625chapter789_Makefiles() {
626#----------------------------#
627 for file in chapter0{7,8,9}/* ; do
628 # Keep the script file name
629 i=`basename $file`
630
631 # Grub must be configured manually.
632 # The filesystems can't be unmounted via Makefile and the user
633 # should to enter to the chroot environment to create the root
634 # password, edit several files and setup Grub,
635 if [[ `_IS_ $i grub` ]] || [[ `_IS_ $i reboot` ]] ; then
636 continue
637 fi
638
639 # If no .config file is supplied, the kernel build is skipped
640 if [ -z $CONFIG ] && [[ `_IS_ $i kernel` ]] ; then
641 continue
642 fi
643
644 # First append each name of the script files to a list (this will become
645 # the names of the targets in the Makefile
646 chapter789="$chapter789 $i"
647
648 # Drop in the name of the target on a new line, and the previous target
649 # as a dependency. Also call the echo_message function.
650(
651 cat << EOF
652
653$i: $PREV
654 @\$(call echo_message, Building)
655EOF
656) >> $MKFILE.tmp
657
658 # Find the the bootscripts and kernel package names
659 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
660 if [[ `_IS_ $i bootscripts` ]] ; then
661 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
662 FILE="lfs-bootscripts-$vrs.tar.*"
663 elif [[ `_IS_ $i kernel` ]] ; then
664 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
665 FILE="linux-$vrs.tar.*"
666 fi
667(
668 cat << EOF
669 @\$(call unpack2,$FILE)
670 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
671 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
672 echo "export PKGDIR" >> envars
673EOF
674) >> $MKFILE.tmp
675 fi
676
677 # Put in place the kernel .config file
678 if [[ `_IS_ $i kernel` ]] ; then
679(
680 cat << EOF
681 @cp $CONFIG \$(LFS)/sources/kernel-config
682EOF
683) >> $MKFILE.tmp
684 fi
685
686 # Check if we have a real /etc/fstab file
687 if [[ `_IS_ $i fstab` ]] && [[ -n "$FSTAB" ]] ; then
688(
689 cat << EOF
690 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
691 cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
692 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
693EOF
694) >> $MKFILE.tmp
695 else
696 # Initialize the log an run the script
697(
698 cat << EOF
699 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
700 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
701 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
702EOF
703) >> $MKFILE.tmp
704 fi
705
706 # Remove the build directory except if the package build fails.
707 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
708(
709 cat << EOF
710 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
711 rm -r \$(LFS)\$(SRC)/\$\$ROOT
712EOF
713) >> $MKFILE.tmp
714 fi
715
716 # Include a touch of the target name so make can check
717 # if it's already been made.
718(
719 cat << EOF
720 @touch \$@
721EOF
722) >> $MKFILE.tmp
723
724 # Keep the script file name for Makefile dependencies.
725 PREV=$i
726 done # for file in chapter0{7,8,9}/*
727}
728
729
730#----------------------------#
731build_Makefile() {
732#----------------------------#
733 echo -n "Creating Makefile... "
734 cd $JHALFSDIR/commands
735
736 # Start with a clean Makefile.tmp file
737 >$MKFILE.tmp
738
739 chapter4_Makefiles
740 chapter5_Makefiles
741 chapter6_Makefiles
742 chapter789_Makefiles
743
744
745 # Add a header, some variables and include the function file
746 # to the top of the real Makefile.
747(
748 cat << EOF
749$HEADER
750
751SRC= /sources
752LFS= $BUILDDIR
753PAGE= $PAGE
754TIMEZONE= $TIMEZONE
755
756include functions
757
758EOF
759) > $MKFILE
760
761
762 # Add chroot commands
763 i=1
764 for file in chapter06/*chroot* ; do
765 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
766 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
767 -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
768 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
769 i=`expr $i + 1`
770 done
771
772 # Drop in the main target 'all:' and the chapter targets with each sub-target
773 # as a dependency.
774(
775 cat << EOF
776all: chapter4 chapter5 chapter6 chapter789
777 @\$(call echo_finished,$VERSION)
778
779chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
780
781chapter5: chapter4 $chapter5
782
783chapter6: chapter5 $chapter6
784
785chapter789: chapter6 $chapter789
786
787clean-all: clean
788 rm -rf ./*
789
790clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
791
792clean-chapter4:
793 -userdel lfs
794 rm -rf /home/lfs
795 rm -rf \$(LFS)/tools
796 rm -f /tools
797 rm -f envars
798 rm -f 02* logs/02*.log
799
800clean-chapter5:
801 rm -rf \$(LFS)/tools/*
802 rm -f $chapter5
803 cd logs && rm -f $chapter5 && cd ..
804
805clean-chapter6:
806 -umount \$(LFS)/sys
807 -umount \$(LFS)/proc
808 -umount \$(LFS)/dev/shm
809 -umount \$(LFS)/dev/pts
810 -umount \$(LFS)/dev
811 rm -rf \$(LFS)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
812 rm -f $chapter6
813 cd logs && rm -f $chapter6 && cd ..
814
815clean-chapter789:
816 rm -f $chapter789
817 cd logs && rm -f $chapter789 && cd ..
818
819
820EOF
821) >> $MKFILE
822
823 # Bring over the items from the Makefile.tmp
824 cat $MKFILE.tmp >> $MKFILE
825 rm $MKFILE.tmp
826 echo -ne "done\n"
827}
828
829#----------------------------#
830run_make() {
831#----------------------------#
832 # Test if make must be run.
833 if [ "$RUNMAKE" = "1" ] ; then
834 # Test to make sure we're running the build as root
835 if [ "$UID" != "0" ] ; then
836 echo "You must be logged in as root to successfully build LFS."
837 exit 1
838 fi
839 # Build the system
840 if [ -e $MKFILE ] ; then
841 echo -ne "Building the LFS system...\n"
842 cd $JHALFSDIR && make
843 echo -ne "done\n"
844 fi
845 fi
846}
847
848
849
850###################################
851### MAIN ###
852###################################
853
854# Evaluate any command line switches
855
856while test $# -gt 0 ; do
857 case $1 in
858 --version | -V )
859 echo "$version"
860 exit 0
861 ;;
862
863 --help | -h )
864 echo "$usage"
865 exit 0
866 ;;
867
868 --LFS-version | -L )
869 test $# = 1 && eval "$exit_missing_arg"
870 shift
871 case $1 in
872 dev* | SVN | trunk )
873 LFSVRS=development
874 ;;
875 testing | 6.1.1 )
876 LFSVRS=6.1.1
877 ;;
878
879 alpha*)
880 LFSVRS=alphabetical
881 ;;
882 * )
883 echo "$1 is an unsupported version at this time."
884 exit 1
885 ;;
886 esac
887 ;;
888
889 --directory | -d )
890 test $# = 1 && eval "$exit_missing_arg"
891 shift
892 BUILDDIR=$1
893 ;;
894
895 --download-client | -D )
896 test $# = 1 && eval "$exit_missing_arg"
897 shift
898 DL=$1
899 ;;
900
901 --working-copy | -W )
902 test $# = 1 && eval "$exit_missing_arg"
903 shift
904 if [ -f $1/patches.ent ] ; then
905 WC=1
906 BOOK=$1
907 else
908 echo -e "\nLook like $1 isn't a supported working copy."
909 echo -e "Verify your selection and the command line.\n"
910 exit 1
911 fi
912 ;;
913
914 --testsuites | -T ) TEST=1 ;;
915
916 --get-packages | -P ) HPKG=1 ;;
917
918 --run-make | -M ) RUNMAKE=1 ;;
919
920 --no-toolchain-test ) TOOLCHAINTEST=0 ;;
921
922 --page_size )
923 test $# = 1 && eval "$exit_missing_arg"
924 shift
925 case $1 in
926 letter | A4 )
927 PAGE=$1
928 ;;
929 * )
930 echo "$1 isn't a supported page size."
931 exit 1
932 ;;
933 esac
934 ;;
935
936
937 --timezone )
938 test $# = 1 && eval "$exit_missing_arg"
939 shift
940 if [ -f /usr/share/zoneinfo/$1 ] ; then
941 TIMEZONE=$1
942 else
943 echo -e "\nLook like $1 isn't a valid timezone description."
944 echo -e "Verify your selection and the command line.\n"
945 exit 1
946 fi
947 ;;
948
949 --fstab )
950 test $# = 1 && eval "$exit_missing_arg"
951 shift
952 if [ -f $1 ] ; then
953 FSTAB=$1
954 else
955 echo -e "\nFile $1 not found. Verify your command line.\n"
956 exit 1
957 fi
958 ;;
959
960 --kernel-config | -C )
961 test $# = 1 && eval "$exit_missing_arg"
962 shift
963 if [ -f $1 ] ; then
964 CONFIG=$1
965 else
966 echo -e "\nFile $1 not found. Verify your command line.\n"
967 exit 1
968 fi
969 ;;
970
971 * )
972 echo "$usage"
973 exit 1
974 ;;
975 esac
976 shift
977done
978
979# Find the download client to use, if not already specified.
980
981if [ -z $DL ] ; then
982 if [ `type -p wget` ] ; then
983 DL=wget
984 elif [ `type -p curl` ] ; then
985 DL=curl
986 else
987 eval "$no_dl_client"
988 fi
989fi
990
991[[ ! -d $JHALFSDIR ]] && mkdir -pv $JHALFSDIR
992[[ "$PWD" != "$JHALFSDIR" ]] && cp -v $FILES $JHALFSDIR/
993[[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
994>$LOGDIR/$LOG
995
996get_book
997build_Makefile
998run_make
999
Note: See TracBrowser for help on using the repository browser.