source: jhalfs@ 7178cdc

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

Merged r2182 from trunk.

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