source: jhalfs@ a0e25ce

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

Changed credits - I'm somewhat active again and Manuel has written enough code to be considered a co-author

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