source: jhalfs@ cf7f294

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

If a package build fails, their sources aren't removed to can review config.cache, config.log, and like.

Added chapters 7, 8 and 9 (but not tested yet.)

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