source: jhalfs@ 42ddaf8

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

Merged revision 2151 to 0.2 branch

  • Property mode set to 100755
File size: 26.1 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@glibc-linuxthreads@'` >> packages
174 echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
175 # If we are buildind the UTF-8 branch, the glibc-libidn package is required
176 if grep -q "man-db-version" $BOOK/general.ent ; then
177 echo `grep "glibc" packages | sed 's@glibc@glibc-libidn@'` >> packages
178 fi
179 grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
180
181 # Done. Moving on...
182 echo -ne "done\n"
183 get_sources
184}
185
186#----------------------------#
187download() {
188#----------------------------#
189 cd $BUILDDIR/sources
190
191 # Hackish fix for the bash-doc and glibc-{linuxthreads,libidn} packages that
192 # doesn't conform to norms in the URL scheme.
193 DIR=`echo $1 | sed -e 's@-doc@@' -e 's@-linuxthreads@@' -e 's@-libidn@@'`
194
195 # Find the md5 sum for this package.
196 if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
197
198 if [ ! -f $2 ] ; then
199 case $DL in
200 wget )
201 wget $HTTP/$DIR/$2
202 ;;
203 curl )
204 `curl -# $HTTP/$DIR/$2 -o $2`
205 ;;
206 * )
207 echo "$DL not supported at this time."
208 ;;
209 esac
210 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
211 case $DL in
212 wget )
213 wget -c $HTTP/$DIR/$2
214 ;;
215 curl )
216 `curl -# -C - $HTTP/$DIR/$2 -o $2`
217 ;;
218 * )
219 echo "$DL not supported at this time."
220 ;;
221 esac
222 fi
223 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
224 exit 1
225 fi
226}
227
228#----------------------------#
229get_sources() {
230#----------------------------#
231
232 # Test if the packages must be downloaded
233 if [ "$HPKG" = "1" ] ; then
234
235 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
236 # separates each iteration by lines. It is necessary to have the second
237 # ' on the next line.
238 IFS='
239'
240
241 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
242 cd $BUILDDIR/sources
243 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
244
245 download "" MD5SUMS
246
247 # Iterate through each package and grab it, along with any patches it needs.
248 for i in `cat $JHALFSDIR/packages` ; do
249 PKG=`echo $i | sed -e 's/-version.*//' -e 's/-file.*//'`
250 # Needed for Groff patchlevel patch on UTF-8 branch
251 GROFFLEVEL=`grep "groff-patchlevel" $JHALFSDIR/packages | sed -e 's/groff-patchlevel //' -e 's/"//g'`
252
253 # There is some entities that aren't valid package entities.
254 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" -o "$PKG" = "groff-patchlevel" ] ; then continue ; fi
255
256 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
257 if [ "$PKG" = "tcl" ] ; then
258 FILE="$PKG$VRS-src.tar.bz2"
259 elif [ "$PKG" = "udev-config" ] ; then
260 PKG="udev"
261 FILE="$VRS"
262 else
263 FILE="$PKG-$VRS.tar.bz2"
264 fi
265 download $PKG $FILE
266 for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
267 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
268 download $PKG $PATCH
269 done
270 # Needed for Groff patchlevel patch on UTF-8 branch
271 for patch in `grep "patchlevel" $JHALFSDIR/patches` ; do
272 PATCH=`echo $patch | sed 's@&'$PKG'-version;-&'$PKG'-patchlevel;@'$VRS'-'$GROFFLEVEL'@'`
273 download $PKG $PATCH
274 done
275 done
276 fi
277}
278
279#-----------------------------------------------#
280_IS_() # Function to test build scripts names
281#-----------------------------------------------#
282{
283 # Returns substr $2 or null str
284 # Must use string testing
285 case $1 in
286 *$2*) echo "$2" ;;
287 *) echo "" ;;
288 esac
289}
290
291#----------------------------#
292chapter4_Makefiles() {
293#----------------------------#
294(
295 cat << EOF
296020-creatingtoolsdir:
297 @\$(call echo_message, Building)
298 @mkdir -v \$(LFS)/tools && \\
299 ln -sv \$(LFS)/tools / && \\
300 touch \$@
301
302021-addinguser: 020-creatingtoolsdir
303 @\$(call echo_message, Building)
304 @groupadd lfs && \\
305 useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
306 chown lfs \$(LFS)/tools && \\
307 chown lfs \$(LFS)/sources && \\
308 touch \$@
309
310022-settingenvironment: 021-addinguser
311 @\$(call echo_message, Building)
312 @echo "set +h" > /home/lfs/.bashrc && \\
313 echo "umask 022" >> /home/lfs/.bashrc && \\
314 echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
315 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
316 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
317 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
318 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
319 chown lfs:lfs /home/lfs/.bashrc && \\
320 touch envars && \\
321 touch \$@
322EOF
323) >> $MKFILE.tmp
324}
325
326#----------------------------#
327chapter5_Makefiles() {
328#----------------------------#
329 for file in chapter05/* ; do
330 # Keep the script file name
331 i=`basename $file`
332
333 # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
334 if [ "$TOOLCHAINTEST" = "0" ]; then
335 if [[ `_IS_ $i tcl` ]] || [[ `_IS_ $i expect` ]] || [[ `_IS_ $i dejagnu` ]] ; then
336 continue
337 fi
338 fi
339
340 # First append each name of the script files to a list (this will become
341 # the names of the targets in the Makefile
342 chapter5="$chapter5 $i"
343
344 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
345 # and binutils in chapter 5)
346 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
347
348 # Set the dependency for the first target.
349 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
350
351 # Drop in the name of the target on a new line, and the previous target
352 # as a dependency. Also call the echo_message function.
353(
354 cat << EOF
355
356$i: $PREV
357 @\$(call echo_message, Building)
358EOF
359) >> $MKFILE.tmp
360
361 # Find the version of the command files, if it corresponds with the building of
362 # a specific package
363 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
364
365 # If $vrs isn't empty, we've got a package...
366 if [ "$vrs" != "" ] ; then
367 if [ "$name" = "tcl" ] ; then
368 FILE="$name$vrs-src.tar"
369 else
370 FILE="$name-$vrs.tar"
371 fi
372
373 # Insert instructions for unpacking the package and to set
374 # the PKGDIR variable.
375(
376 cat << EOF
377 @\$(call unpack,$FILE)
378 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
379 chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
380 echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
381 echo "export PKGDIR" >> envars && \\
382EOF
383) >> $MKFILE.tmp
384
385 fi
386
387 # Dump the path to the Binutils or TCL sources directory.
388 if [[ `_IS_ $i binutils` ]] || [[ `_IS_ $i tcl` ]] ; then
389(
390 cat << EOF
391 echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
392EOF
393) >> $MKFILE.tmp
394
395 # For the Adjusting phase we must to cd to the binutils-build directory.
396 elif [[ `_IS_ $i adjusting` ]] ; then
397(
398 cat << EOF
399 @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
400 echo "export PKGDIR" >> envars
401EOF
402) >> $MKFILE.tmp
403
404 # For the Expect build we need to set the TCLPATH envar.
405 elif [[ `_IS_ $i expect` ]] ; then
406(
407 cat << EOF
408 echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
409 echo "export TCLPATH" >> envars
410EOF
411) >> $MKFILE.tmp
412
413 # Everything else, add a true statment so we don't confuse make
414 else
415(
416 cat << EOF
417 true
418EOF
419) >> $MKFILE.tmp
420 fi
421
422 # Insert date and disk usage at the top of the log file, the script run
423 # and date and disk usage again at the bottom of the log file.
424(
425 cat << EOF
426 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
427 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
428 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
429EOF
430) >> $MKFILE.tmp
431
432 # Remove the build directory(ies) except if the package build fails
433 # (to can review config.cache, config.log, and like.)
434 # For Binutils and TCL the sources must be retained some time.
435 if [ "$vrs" != "" ] ; then
436 if [[ ! `_IS_ $i binutils` ]] && [[ ! `_IS_ $i tcl` ]] ; then
437(
438 cat << EOF
439 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
440 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
441 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
442 rm -r \$(LFS)\$(SRC)/$name-build; \\
443 fi;
444EOF
445) >> $MKFILE.tmp
446 fi
447 fi
448
449 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
450 if [[ `_IS_ $i adjusting` ]] ; then
451(
452 cat << EOF
453 @rm -r \`cat sources-dir\` && \\
454 rm -r \$(LFS)\$(SRC)/binutils-build && \\
455 rm sources-dir
456EOF
457) >> $MKFILE.tmp
458 fi
459
460 # Remove the TCL sources after a successful Expect build.
461 if [[ `_IS_ $i expect` ]] ; then
462(
463 cat << EOF
464 @rm -r \`cat sources-dir\` && \\
465 rm sources-dir
466EOF
467) >> $MKFILE.tmp
468 fi
469
470 # Include a touch of the target name so make can check
471 # if it's already been made.
472(
473 cat << EOF
474 @touch \$@
475EOF
476) >> $MKFILE.tmp
477
478 # Keep the script file name for Makefile dependencies.
479 PREV=$i
480 done # end for file in chapter05/*
481}
482
483#----------------------------#
484chapter6_Makefiles() {
485#----------------------------#
486 for file in chapter06/* ; do
487 # Keep the script file name
488 i=`basename $file`
489
490 # We'll run the chroot commands differently than the others, so skip them in the
491 # dependencies and target creation.
492 if [[ `_IS_ $i chroot` ]] ; then
493 continue
494 fi
495
496 # First append each name of the script files to a list (this will become
497 # the names of the targets in the Makefile
498 chapter6="$chapter6 $i"
499
500 # Grab the name of the target
501 name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
502
503 # Drop in the name of the target on a new line, and the previous target
504 # as a dependency. Also call the echo_message function.
505(
506 cat << EOF
507
508$i: $PREV
509 @\$(call echo_message, Building)
510EOF
511) >> $MKFILE.tmp
512
513 # Find the version of the command files, if it corresponds with the building of
514 # a specific package
515 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
516
517 # If $vrs isn't empty, we've got a package...
518 # Insert instructions for unpacking the package and changing directories
519 if [ "$vrs" != "" ] ; then
520 FILE="$name-$vrs.tar.*"
521(
522 cat << EOF
523 @\$(call unpack2,$FILE)
524 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
525 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
526 echo "export PKGDIR" >> envars
527EOF
528) >> $MKFILE.tmp
529 fi
530
531 # For the Re-Adjusting phase we must to cd to the binutils-build directory.
532 if [[ `_IS_ $i readjusting` ]] ; then
533(
534 cat << EOF
535 @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
536 echo "export PKGDIR" >> envars
537EOF
538) >> $MKFILE.tmp
539
540 # For Glibc we need to set TIMEZONE envar.
541 elif [[ `_IS_ $i glibc` ]] ; then
542(
543 cat << EOF
544 @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
545 echo "export TIMEZONE" >> envars
546EOF
547) >> $MKFILE.tmp
548
549 # For Groff we need to set PAGE envar.
550 elif [[ `_IS_ $i groff` ]] ; then
551(
552 cat << EOF
553 @echo "PAGE=\$(PAGE)" >> envars && \\
554 echo "export PAGE" >> envars
555EOF
556) >> $MKFILE.tmp
557 fi
558
559 # In the mount of kernel filesystems we need to set LFS
560 # and not to use chroot.
561 if [[ `_IS_ $i kernfs` ]] ; then
562(
563 cat << EOF
564 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
565 export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
566 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
567EOF
568) >> $MKFILE.tmp
569
570 # The rest of Chapter06
571 else
572(
573 cat << EOF
574 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
575 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
576 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
577EOF
578) >> $MKFILE.tmp
579 fi
580
581 # Remove the build directory(ies) except if the package build fails.
582 if [ "$vrs" != "" ] ; then
583(
584 cat << EOF
585 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
586 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
587 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
588 rm -r \$(LFS)\$(SRC)/$name-build; \\
589 fi;
590EOF
591) >> $MKFILE.tmp
592 fi
593
594 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
595 if [[ `_IS_ $i readjusting` ]] ; then
596(
597 cat << EOF
598 @rm -r \`cat sources-dir\` && \\
599 rm -r \$(LFS)\$(SRC)/binutils-build && \\
600 rm sources-dir
601EOF
602) >> $MKFILE.tmp
603 fi
604
605 # Include a touch of the target name so make can check
606 # if it's already been made.
607(
608 cat << EOF
609 @touch \$@
610EOF
611) >> $MKFILE.tmp
612
613 # Keep the script file name for Makefile dependencies.
614 PREV=$i
615 done # end for file in chapter06/*
616}
617
618#----------------------------#
619chapter789_Makefiles() {
620#----------------------------#
621 for file in chapter0{7,8,9}/* ; do
622 # Keep the script file name
623 i=`basename $file`
624
625 # Grub must be configured manually.
626 # The filesystems can't be unmounted via Makefile and the user
627 # should to enter to the chroot environment to create the root
628 # password, edit several files and setup Grub,
629 if [[ `_IS_ $i grub` ]] || [[ `_IS_ $i reboot` ]] ; then
630 continue
631 fi
632
633 # If no .config file is supplied, the kernel build is skipped
634 if [ -z $CONFIG ] && [[ `_IS_ $i kernel` ]] ; then
635 continue
636 fi
637
638 # First append each name of the script files to a list (this will become
639 # the names of the targets in the Makefile
640 chapter789="$chapter789 $i"
641
642 # Drop in the name of the target on a new line, and the previous target
643 # as a dependency. Also call the echo_message function.
644(
645 cat << EOF
646
647$i: $PREV
648 @\$(call echo_message, Building)
649EOF
650) >> $MKFILE.tmp
651
652 # Find the the bootscripts and kernel package names
653 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
654 if [[ `_IS_ $i bootscripts` ]] ; then
655 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
656 FILE="lfs-bootscripts-$vrs.tar.*"
657 elif [[ `_IS_ $i kernel` ]] ; then
658 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
659 FILE="linux-$vrs.tar.*"
660 fi
661(
662 cat << EOF
663 @\$(call unpack2,$FILE)
664 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
665 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
666 echo "export PKGDIR" >> envars
667EOF
668) >> $MKFILE.tmp
669 fi
670
671 # Put in place the kernel .config file
672 if [[ `_IS_ $i kernel` ]] ; then
673(
674 cat << EOF
675 @cp $CONFIG \$(LFS)/sources/kernel-config
676EOF
677) >> $MKFILE.tmp
678 fi
679
680 # Check if we have a real /etc/fstab file
681 if [[ `_IS_ $i fstab` ]] && [[ -n "$FSTAB" ]] ; then
682(
683 cat << EOF
684 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
685 cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
686 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
687EOF
688) >> $MKFILE.tmp
689 else
690 # Initialize the log an run the script
691(
692 cat << EOF
693 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
694 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
695 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
696EOF
697) >> $MKFILE.tmp
698 fi
699
700 # Remove the build directory except if the package build fails.
701 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
702(
703 cat << EOF
704 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
705 rm -r \$(LFS)\$(SRC)/\$\$ROOT
706EOF
707) >> $MKFILE.tmp
708 fi
709
710 # Include a touch of the target name so make can check
711 # if it's already been made.
712(
713 cat << EOF
714 @touch \$@
715EOF
716) >> $MKFILE.tmp
717
718 # Keep the script file name for Makefile dependencies.
719 PREV=$i
720 done # for file in chapter0{7,8,9}/*
721}
722
723
724#----------------------------#
725build_Makefile() {
726#----------------------------#
727 echo -n "Creating Makefile... "
728 cd $JHALFSDIR/commands
729
730 # Start with a clean Makefile.tmp file
731 >$MKFILE.tmp
732
733 chapter4_Makefiles
734 chapter5_Makefiles
735 chapter6_Makefiles
736 chapter789_Makefiles
737
738
739 # Add a header, some variables and include the function file
740 # to the top of the real Makefile.
741(
742 cat << EOF
743$HEADER
744
745SRC= /sources
746LFS= $BUILDDIR
747PAGE= $PAGE
748TIMEZONE= $TIMEZONE
749
750include functions
751
752EOF
753) > $MKFILE
754
755
756 # Add chroot commands
757 i=1
758 for file in chapter06/*chroot* ; do
759 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
760 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
761 -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
762 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
763 i=`expr $i + 1`
764 done
765
766 # Drop in the main target 'all:' and the chapter targets with each sub-target
767 # as a dependency.
768(
769 cat << EOF
770all: chapter4 chapter5 chapter6 chapter789
771 @\$(call echo_finished,$VERSION)
772
773chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
774
775chapter5: chapter4 $chapter5
776
777chapter6: chapter5 $chapter6
778
779chapter789: chapter6 $chapter789
780
781clean-all: clean
782 rm -rf ./*
783
784clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
785
786clean-chapter4:
787 -userdel lfs
788 rm -rf /home/lfs
789 rm -rf \$(LFS)/tools
790 rm -f /tools
791 rm -f envars
792 rm -f 02* logs/02*.log
793
794clean-chapter5:
795 rm -rf \$(LFS)/tools/*
796 rm -f $chapter5
797 cd logs && rm -f $chapter5 && cd ..
798
799clean-chapter6:
800 -umount \$(LFS)/sys
801 -umount \$(LFS)/proc
802 -umount \$(LFS)/dev/shm
803 -umount \$(LFS)/dev/pts
804 -umount \$(LFS)/dev
805 rm -rf \$(LFS)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
806 rm -f $chapter6
807 cd logs && rm -f $chapter6 && cd ..
808
809clean-chapter789:
810 rm -f $chapter789
811 cd logs && rm -f $chapter789 && cd ..
812
813
814EOF
815) >> $MKFILE
816
817 # Bring over the items from the Makefile.tmp
818 cat $MKFILE.tmp >> $MKFILE
819 rm $MKFILE.tmp
820 echo -ne "done\n"
821}
822
823#----------------------------#
824run_make() {
825#----------------------------#
826 # Test if make must be run.
827 if [ "$RUNMAKE" = "1" ] ; then
828 # Test to make sure we're running the build as root
829 if [ "$UID" != "0" ] ; then
830 echo "You must be logged in as root to successfully build LFS."
831 exit 1
832 fi
833 # Build the system
834 if [ -e $MKFILE ] ; then
835 echo -ne "Building the LFS system...\n"
836 cd $JHALFSDIR && make
837 echo -ne "done\n"
838 fi
839 fi
840}
841
842
843
844###################################
845### MAIN ###
846###################################
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 $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.