source: jhalfs@ 50408d5

0.2 1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 50408d5 was 50408d5, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Added a switch to submmint a real /etc/fstab file.
Some space clean-up.

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