source: jhalfs@ 3338588

0.2 1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 3338588 was 3338588, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

Set the Makefile to ignore errors on the umounts - necessary if you want to run 'make clean' before the script has hit chapter 6

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