source: jhalfs@ 7ad4ef5

0.2
Last change on this file since 7ad4ef5 was 7ad4ef5, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Merged r2158 and r2159 from trunk.

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