source: jhalfs@ 299b7e0

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

Typo fix

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