source: jhalfs@ 0bd7b91

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

Added clean-chapter6 and clean-chapter789 targets.

  • Property mode set to 100755
File size: 26.0 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
[db9cec6]12Originally written by Jeremy Huntwork.
[557fe91]13Maintained by Manuel Canales Esparcia.
[1236262]14
15This program is published under the \
[557fe91]16Gnu General Public License, Version 2.
17"
[1236262]18
19usage="\
20Usage: $0 [OPTION]
21
22Options:
[557fe91]23 -h, --help print this help, then exit
[24530379]24
[557fe91]25 -V, --version print version number, then exit
[24530379]26
[a41ce58]27 -d --directory DIR use DIR directory for building LFS; all files
[557fe91]28 jhalfs produces will be in the directory
[af47a19]29 DIR/jhalfs. Default is \"/mnt/lfs\".
[24530379]30
[1fb586e]31 -P, --get-packages download the packages and patches. That
32 depend on the server declared in the
33 jhalfs.conf file having the proper packages
34 and patches versions for the book version
35 being processed.
[24530379]36
[a41ce58]37 -D, --download-client CLIENT use CLIENT as the program for retrieving
[24530379]38 packages (for use in conjunction with -P)
39
[a41ce58]40 -W, --working-copy DIR use the local working copy placed in DIR
[24530379]41 as the LFS book
42
[daedcfc]43 -L, --LFS-version VER ckeckout VER version of the LFS book.
44 Supported versions at this time are:
45
46 dev* | trunk | SVN alias for Development LFS
47 testing | 6.1.1 alias for the testing 6.1.1 branch
[24530379]48
49 -T, --testsuites add support to run the optional testsuites
50
[01e51a1]51 --no-toolchain-test don't run the toolchain testsuites. This
52 disables also the build of TCL, Expect
53 and DejaGNU
[50408d5]54
55 --timezone TIMEZONE set TIMEZONE as the local timezone. If not
[6e31ef7]56 specified, Europe/London will be used.
[01e51a1]57
[6e31ef7]58 --page_size PAGE set PAGE as the default page size (letter
59 or A4). This setting is required to
[af47a19]60 build Groff. If not specified, \"letter\"
61 will be used.
[cf7f294]62
[50408d5]63 --fstab FILE use FILE as the /etc/fstab file for the
64 LFS system. If not specified, a default
65 /etc/fstab file with dummy values is
66 created.
67
[cf7f294]68 -C, --kernel-config FILE use the kernel configuration file specified
69 in FILE to build the kernel. If not found,
70 the kernel build is skipped.
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
[0fd8a9d]174 # If we are buildind the UTF-8 branch, the glibc-libidn package is required
175 if grep -q "man-db-version" $BOOK/general.ent ; then
176 echo `grep "glibc" packages | sed 's@glibc@glibc-libidn@'` >> packages
177 fi
[24530379]178 grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
[1236262]179
180 # Done. Moving on...
181 echo -ne "done\n"
182 get_sources
183}
184
[49aea5e]185#----------------------------#
[1236262]186download() {
[49aea5e]187#----------------------------#
[1236262]188 cd $BUILDDIR/sources
189
[0fd8a9d]190 # Hackish fix for the bash-doc and glibc-{linuxthreads,libidn} packages that
[0a9117e]191 # doesn't conform to norms in the URL scheme.
[0fd8a9d]192 DIR=`echo $1 | sed -e 's@-doc@@' -e 's@-linuxthreads@@' -e 's@-libidn@@'`
[1236262]193
194 # Find the md5 sum for this package.
195 if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
196
197 if [ ! -f $2 ] ; then
[557fe91]198 case $DL in
199 wget )
200 wget $HTTP/$DIR/$2
201 ;;
202 curl )
203 `curl -# $HTTP/$DIR/$2 -o $2`
204 ;;
205 * )
206 echo "$DL not supported at this time."
207 ;;
208 esac
[1236262]209 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
[557fe91]210 case $DL in
211 wget )
212 wget -c $HTTP/$DIR/$2
213 ;;
214 curl )
215 `curl -# -C - $HTTP/$DIR/$2 -o $2`
216 ;;
217 * )
218 echo "$DL not supported at this time."
219 ;;
220 esac
[1236262]221 fi
222 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
223 exit 1
224 fi
225}
226
[49aea5e]227#----------------------------#
[1236262]228get_sources() {
[49aea5e]229#----------------------------#
[1236262]230
[07f47df]231 # Test if the packages must be downloaded
[d310939]232 if [ "$HPKG" = "1" ] ; then
[1236262]233
[07f47df]234 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
235 # separates each iteration by lines. It is necessary to have the second
236 # ' on the next line.
237 IFS='
238'
[1236262]239
[07f47df]240 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
241 cd $BUILDDIR/sources
242 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
243
244 download "" MD5SUMS
245
246 # Iterate through each package and grab it, along with any patches it needs.
247 for i in `cat $JHALFSDIR/packages` ; do
248 PKG=`echo $i | sed 's/-version.*//'`
[0fd8a9d]249 # Needed for Groff patchlevel patch on UTF-8 branch
[8742984]250 GROFFLEVEL=`grep "groff-patchlevel" $JHALFSDIR/packages | sed -e 's/groff-patchlevel //' -e 's/"//g'`
[07f47df]251
[aebe03a]252 # There is some entities that aren't valid package entities.
[7d4b863]253 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" -o "$PKG" = "groff-patchlevel" ] ; then continue ; fi
[07f47df]254
255 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
256 if [ "$PKG" = "tcl" ] ; then
257 FILE="$PKG$VRS-src.tar.bz2"
258 else
259 FILE="$PKG-$VRS.tar.bz2"
260 fi
261 download $PKG $FILE
262 for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
[7d4b863]263 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
264 download $PKG $PATCH
[07f47df]265 done
[0fd8a9d]266 # Needed for Groff patchlevel patch on UTF-8 branch
[8742984]267 for patch in `grep "patchlevel" $JHALFSDIR/patches` ; do
[0fd8a9d]268 PATCH=`echo $patch | sed 's@&'$PKG'-version;-&'$PKG'-patchlevel;@'$VRS'-'$GROFFLEVEL'@'`
269 download $PKG $PATCH
270 done
[fbb6b78]271 done
[0a9117e]272 # Hardcoded Udev configuration file until find a better way
[d4c6056]273 download udev udev-config-4.rules
[07f47df]274 fi
[1236262]275}
276
[e1093cd]277#-----------------------------------------------#
278_IS_() # Function to test build scripts names
279#-----------------------------------------------#
280{
281 # Returns substr $2 or null str
282 # Must use string testing
283 case $1 in
284 *$2*) echo "$2" ;;
285 *) echo "" ;;
286 esac
287}
288
[49aea5e]289#----------------------------#
290chapter4_Makefiles() {
291#----------------------------#
292(
293 cat << EOF
294020-creatingtoolsdir:
295 @\$(call echo_message, Building)
296 @mkdir -v \$(LFS)/tools && \\
297 ln -sv \$(LFS)/tools / && \\
298 touch \$@
[fbb6b78]299
[49aea5e]300021-addinguser: 020-creatingtoolsdir
301 @\$(call echo_message, Building)
302 @groupadd lfs && \\
303 useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
304 chown lfs \$(LFS)/tools && \\
305 chown lfs \$(LFS)/sources && \\
306 touch \$@
307
308022-settingenvironment: 021-addinguser
309 @\$(call echo_message, Building)
310 @echo "set +h" > /home/lfs/.bashrc && \\
311 echo "umask 022" >> /home/lfs/.bashrc && \\
312 echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
313 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
314 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
315 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
316 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
317 chown lfs:lfs /home/lfs/.bashrc && \\
318 touch envars && \\
319 touch \$@
320EOF
321) >> $MKFILE.tmp
322}
[f8de156]323
[49aea5e]324#----------------------------#
325chapter5_Makefiles() {
326#----------------------------#
[0bad6ba]327 for file in chapter05/* ; do
[71642ef]328 # Keep the script file name
329 i=`basename $file`
[63b2859]330
[01e51a1]331 # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
332 if [ "$TOOLCHAINTEST" = "0" ]; then
[e1093cd]333 if [[ `_IS_ $i tcl` ]] || [[ `_IS_ $i expect` ]] || [[ `_IS_ $i dejagnu` ]] ; then
[01e51a1]334 continue
335 fi
336 fi
337
[71642ef]338 # First append each name of the script files to a list (this will become
339 # the names of the targets in the Makefile
340 chapter5="$chapter5 $i"
[557fe91]341
[71642ef]342 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
343 # and binutils in chapter 5)
344 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
[557fe91]345
[e909d9d]346 # Set the dependency for the first target.
347 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
348
349 # Drop in the name of the target on a new line, and the previous target
[0fc4c75]350 # as a dependency. Also call the echo_message function.
[3f990d1]351(
352 cat << EOF
353
354$i: $PREV
355 @\$(call echo_message, Building)
356EOF
357) >> $MKFILE.tmp
[557fe91]358
[71642ef]359 # Find the version of the command files, if it corresponds with the building of
360 # a specific package
361 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
[557fe91]362
[71642ef]363 # If $vrs isn't empty, we've got a package...
364 if [ "$vrs" != "" ] ; then
365 if [ "$name" = "tcl" ] ; then
[be9970b]366 FILE="$name$vrs-src.tar"
[71642ef]367 else
[be9970b]368 FILE="$name-$vrs.tar"
[71642ef]369 fi
[557fe91]370
[71642ef]371 # Insert instructions for unpacking the package and to set
372 # the PKGDIR variable.
[3f990d1]373(
374 cat << EOF
375 @\$(call unpack,$FILE)
[eaa021a]376 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]377 chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
378 echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
379 echo "export PKGDIR" >> envars && \\
380EOF
381) >> $MKFILE.tmp
382
[71642ef]383 fi
[557fe91]384
[4c62c61]385 # Dump the path to the Binutils or TCL sources directory.
[e1093cd]386 if [[ `_IS_ $i binutils` ]] || [[ `_IS_ $i tcl` ]] ; then
[3f990d1]387(
388 cat << EOF
389 echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
390EOF
391) >> $MKFILE.tmp
[88dcce5]392
[71642ef]393 # For the Adjusting phase we must to cd to the binutils-build directory.
[e1093cd]394 elif [[ `_IS_ $i adjusting` ]] ; then
[3f990d1]395(
396 cat << EOF
397 @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
398 echo "export PKGDIR" >> envars
399EOF
400) >> $MKFILE.tmp
[0209bb7]401
[97a3ffc]402 # For the Expect build we need to set the TCLPATH envar.
[e1093cd]403 elif [[ `_IS_ $i expect` ]] ; then
[3f990d1]404(
405 cat << EOF
406 echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
407 echo "export TCLPATH" >> envars
408EOF
409) >> $MKFILE.tmp
[0fc4c75]410
411 # Everything else, add a true statment so we don't confuse make
412 else
[3f990d1]413(
414 cat << EOF
415 true
416EOF
417) >> $MKFILE.tmp
[71642ef]418 fi
[557fe91]419
[3f990d1]420 # Insert date and disk usage at the top of the log file, the script run
421 # and date and disk usage again at the bottom of the log file.
422(
423 cat << EOF
[43757c2]424 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[3f990d1]425 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
[43757c2]426 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[3f990d1]427EOF
428) >> $MKFILE.tmp
[71642ef]429
[cf7f294]430 # Remove the build directory(ies) except if the package build fails
431 # (to can review config.cache, config.log, and like.)
432 # For Binutils and TCL the sources must be retained some time.
[71642ef]433 if [ "$vrs" != "" ] ; then
[e1093cd]434 if [[ ! `_IS_ $i binutils` ]] && [[ ! `_IS_ $i tcl` ]] ; then
[3f990d1]435(
436 cat << EOF
[eaa021a]437 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]438 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
439 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
440 rm -r \$(LFS)\$(SRC)/$name-build; \\
441 fi;
442EOF
443) >> $MKFILE.tmp
[71642ef]444 fi
445 fi
[7bbd436]446
447 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
[e1093cd]448 if [[ `_IS_ $i adjusting` ]] ; then
[3f990d1]449(
450 cat << EOF
451 @rm -r \`cat sources-dir\` && \\
452 rm -r \$(LFS)\$(SRC)/binutils-build && \\
453 rm sources-dir
454EOF
455) >> $MKFILE.tmp
[7bbd436]456 fi
457
458 # Remove the TCL sources after a successful Expect build.
[e1093cd]459 if [[ `_IS_ $i expect` ]] ; then
[3f990d1]460(
461 cat << EOF
462 @rm -r \`cat sources-dir\` && \\
463 rm sources-dir
464EOF
465) >> $MKFILE.tmp
[7bbd436]466 fi
467
468 # Include a touch of the target name so make can check
469 # if it's already been made.
[3f990d1]470(
471 cat << EOF
472 @touch \$@
473EOF
474) >> $MKFILE.tmp
[7bbd436]475
[e909d9d]476 # Keep the script file name for Makefile dependencies.
477 PREV=$i
[49aea5e]478 done # end for file in chapter05/*
479}
[9e406b5]480
[49aea5e]481#----------------------------#
482chapter6_Makefiles() {
483#----------------------------#
[97a3ffc]484 for file in chapter06/* ; do
485 # Keep the script file name
486 i=`basename $file`
487
[16c67ed]488 # We'll run the chroot commands differently than the others, so skip them in the
489 # dependencies and target creation.
[e1093cd]490 if [[ `_IS_ $i chroot` ]] ; then
[16c67ed]491 continue
492 fi
493
[97a3ffc]494 # First append each name of the script files to a list (this will become
495 # the names of the targets in the Makefile
496 chapter6="$chapter6 $i"
497
498 # Grab the name of the target
499 name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
500
501 # Drop in the name of the target on a new line, and the previous target
[4c62c61]502 # as a dependency. Also call the echo_message function.
[3f990d1]503(
504 cat << EOF
505
506$i: $PREV
507 @\$(call echo_message, Building)
508EOF
509) >> $MKFILE.tmp
[97a3ffc]510
511 # Find the version of the command files, if it corresponds with the building of
512 # a specific package
513 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
514
515 # If $vrs isn't empty, we've got a package...
[3f990d1]516 # Insert instructions for unpacking the package and changing directories
[97a3ffc]517 if [ "$vrs" != "" ] ; then
[be9970b]518 FILE="$name-$vrs.tar.*"
[3f990d1]519(
520 cat << EOF
[be9970b]521 @\$(call unpack2,$FILE)
[eaa021a]522 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]523 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
[2e51f44]524 echo "export PKGDIR" >> envars
[3f990d1]525EOF
526) >> $MKFILE.tmp
[97a3ffc]527 fi
528
529 # For the Re-Adjusting phase we must to cd to the binutils-build directory.
[e1093cd]530 if [[ `_IS_ $i readjusting` ]] ; then
[3f990d1]531(
532 cat << EOF
533 @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
534 echo "export PKGDIR" >> envars
535EOF
536) >> $MKFILE.tmp
[97a3ffc]537
[2a54650]538 # For Glibc we need to set TIMEZONE envar.
[e1093cd]539 elif [[ `_IS_ $i glibc` ]] ; then
[2a54650]540(
541 cat << EOF
542 @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
543 echo "export TIMEZONE" >> envars
544EOF
545) >> $MKFILE.tmp
546
[a41ce58]547 # For Groff we need to set PAGE envar.
[e1093cd]548 elif [[ `_IS_ $i groff` ]] ; then
[a41ce58]549(
550 cat << EOF
551 @echo "PAGE=\$(PAGE)" >> envars && \\
552 echo "export PAGE" >> envars
553EOF
554) >> $MKFILE.tmp
555 fi
556
[50408d5]557 # In the mount of kernel filesystems we need to set LFS
[80c00fc]558 # and not to use chroot.
[e1093cd]559 if [[ `_IS_ $i kernfs` ]] ; then
[3f990d1]560(
561 cat << EOF
[43757c2]562 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[b51d2ec]563 export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
[43757c2]564 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[3f990d1]565EOF
[a7d20b8]566) >> $MKFILE.tmp
567
568 # The rest of Chapter06
[7ecd166]569 else
[3f990d1]570(
571 cat << EOF
[43757c2]572 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[2e51f44]573 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
[43757c2]574 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[3f990d1]575EOF
576) >> $MKFILE.tmp
[7ecd166]577 fi
[97a3ffc]578
[cf7f294]579 # Remove the build directory(ies) except if the package build fails.
[97a3ffc]580 if [ "$vrs" != "" ] ; then
[3f990d1]581(
582 cat << EOF
[eaa021a]583 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]584 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
585 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
586 rm -r \$(LFS)\$(SRC)/$name-build; \\
587 fi;
588EOF
589) >> $MKFILE.tmp
[97a3ffc]590 fi
591
[4e4a8d5]592 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
[e1093cd]593 if [[ `_IS_ $i readjusting` ]] ; then
[3f990d1]594(
595 cat << EOF
596 @rm -r \`cat sources-dir\` && \\
597 rm -r \$(LFS)\$(SRC)/binutils-build && \\
598 rm sources-dir
599EOF
600) >> $MKFILE.tmp
[97a3ffc]601 fi
602
[732d1f1]603 # Include a touch of the target name so make can check
604 # if it's already been made.
[3f990d1]605(
606 cat << EOF
607 @touch \$@
608EOF
609) >> $MKFILE.tmp
[732d1f1]610
[97a3ffc]611 # Keep the script file name for Makefile dependencies.
612 PREV=$i
[49aea5e]613 done # end for file in chapter06/*
614}
[97a3ffc]615
[49aea5e]616#----------------------------#
617chapter789_Makefiles() {
618#----------------------------#
[cf7f294]619 for file in chapter0{7,8,9}/* ; do
620 # Keep the script file name
621 i=`basename $file`
622
[e1093cd]623 # Grub must be configured manually.
624 # The filesystems can't be unmounted via Makefile and the user
625 # should to enter to the chroot environment to create the root
626 # password, edit several files and setup Grub,
627 if [[ `_IS_ $i grub` ]] || [[ `_IS_ $i reboot` ]] ; then
[83f64dc]628 continue
[cf7f294]629 fi
630
631 # If no .config file is supplied, the kernel build is skipped
[e1093cd]632 if [ -z $CONFIG ] && [[ `_IS_ $i kernel` ]] ; then
633 continue
[cf7f294]634 fi
635
636 # First append each name of the script files to a list (this will become
637 # the names of the targets in the Makefile
638 chapter789="$chapter789 $i"
639
640 # Drop in the name of the target on a new line, and the previous target
641 # as a dependency. Also call the echo_message function.
642(
643 cat << EOF
644
645$i: $PREV
646 @\$(call echo_message, Building)
647EOF
648) >> $MKFILE.tmp
649
650 # Find the the bootscripts and kernel package names
[e1093cd]651 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
652 if [[ `_IS_ $i bootscripts` ]] ; then
[cf7f294]653 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
[be9970b]654 FILE="lfs-bootscripts-$vrs.tar.*"
[e1093cd]655 elif [[ `_IS_ $i kernel` ]] ; then
[cf7f294]656 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
[be9970b]657 FILE="linux-$vrs.tar.*"
[cf7f294]658 fi
659(
660 cat << EOF
[be9970b]661 @\$(call unpack2,$FILE)
[cf7f294]662 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
663 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
664 echo "export PKGDIR" >> envars
665EOF
666) >> $MKFILE.tmp
667 fi
[50408d5]668
[cf7f294]669 # Put in place the kernel .config file
[e1093cd]670 if [[ `_IS_ $i kernel` ]] ; then
[cf7f294]671(
672 cat << EOF
[f0f60d0]673 @cp $CONFIG \$(LFS)/sources/kernel-config
[cf7f294]674EOF
675) >> $MKFILE.tmp
676 fi
677
[50408d5]678 # Check if we have a real /etc/fstab file
[e1093cd]679 if [[ `_IS_ $i fstab` ]] && [[ -n "$FSTAB" ]] ; then
[50408d5]680(
681 cat << EOF
[43757c2]682 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[50408d5]683 cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
[43757c2]684 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[50408d5]685EOF
686) >> $MKFILE.tmp
687 else
[cf7f294]688 # Initialize the log an run the script
689(
690 cat << EOF
[43757c2]691 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[cf7f294]692 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
[43757c2]693 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[cf7f294]694EOF
695) >> $MKFILE.tmp
[50408d5]696 fi
[cf7f294]697
698 # Remove the build directory except if the package build fails.
[e1093cd]699 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
[cf7f294]700(
701 cat << EOF
702 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[50408d5]703 rm -r \$(LFS)\$(SRC)/\$\$ROOT
[cf7f294]704EOF
705) >> $MKFILE.tmp
706 fi
707
708 # Include a touch of the target name so make can check
709 # if it's already been made.
710(
711 cat << EOF
712 @touch \$@
713EOF
714) >> $MKFILE.tmp
715
716 # Keep the script file name for Makefile dependencies.
717 PREV=$i
[49aea5e]718 done # for file in chapter0{7,8,9}/*
719}
720
721
722#----------------------------#
723build_Makefile() {
724#----------------------------#
725 echo -n "Creating Makefile... "
726 cd $JHALFSDIR/commands
727
728 # Start with a clean Makefile.tmp file
729 >$MKFILE.tmp
730
731 chapter4_Makefiles
732 chapter5_Makefiles
733 chapter6_Makefiles
734 chapter789_Makefiles
735
[cf7f294]736
[3f990d1]737 # Add a header, some variables and include the function file
738 # to the top of the real Makefile.
739(
740 cat << EOF
741$HEADER
742
743SRC= /sources
744LFS= $BUILDDIR
[a41ce58]745PAGE= $PAGE
[2a54650]746TIMEZONE= $TIMEZONE
[3f990d1]747
748include functions
749
750EOF
751) > $MKFILE
[8bb92e7]752
[c08d23b]753
754 # Add chroot commands
755 i=1
756 for file in chapter06/*chroot* ; do
757 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
[49aea5e]758 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
759 -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
[d7fd195]760 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
[c08d23b]761 i=`expr $i + 1`
762 done
[9e406b5]763
[0bad6ba]764 # Drop in the main target 'all:' and the chapter targets with each sub-target
765 # as a dependency.
[3f990d1]766(
767 cat << EOF
[cf7f294]768all: chapter4 chapter5 chapter6 chapter789
[898f47a]769 @\$(call echo_finished,$VERSION)
[3f990d1]770
771chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
772
773chapter5: chapter4 $chapter5
774
775chapter6: chapter5 $chapter6
776
[cf7f294]777chapter789: chapter6 $chapter789
778
[3f990d1]779clean-all: clean
780 rm -rf ./*
781
[0bd7b91]782clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
[3f990d1]783
784clean-chapter4:
785 -userdel lfs
786 rm -rf /home/lfs
787 rm -rf \$(LFS)/tools
788 rm -f /tools
789 rm -f envars
790 rm -f 02* logs/02*.log
791
792clean-chapter5:
793 rm -rf \$(LFS)/tools/*
794 rm -f $chapter5
795 cd logs && rm -f $chapter5 && cd ..
[0bd7b91]796
797clean-chapter6:
798 umount \$(LFS)/sys
799 umount \$(LFS)/proc
800 umount \$(LFS)/dev/shm
801 umount \$(LFS)/dev/pts
802 umount \$(LFS)/dev
803 rm -rf \$(LFS)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
804 rm -f $chapter6
805 cd logs && rm -f $chapter6 && cd ..
806
807clean-chapter789:
808 rm -f $chapter789
809 cd logs && rm -f $chapter789 && cd ..
810
[3f990d1]811
812EOF
813) >> $MKFILE
[0bad6ba]814
[9e406b5]815 # Bring over the items from the Makefile.tmp
816 cat $MKFILE.tmp >> $MKFILE
817 rm $MKFILE.tmp
818 echo -ne "done\n"
[f8de156]819}
820
[49aea5e]821#----------------------------#
[88dcce5]822run_make() {
[49aea5e]823#----------------------------#
[d310939]824 # Test if make must be run.
825 if [ "$RUNMAKE" = "1" ] ; then
826 # Build the system
827 if [ -e $MKFILE ] ; then
[e3e1db0]828 echo -ne "Building the LFS system...\n"
[d310939]829 cd $JHALFSDIR && make
830 echo -ne "done\n"
831 fi
[88dcce5]832 fi
833}
[1236262]834
835
[49aea5e]836
837###################################
838### MAIN ###
839###################################
840
841# Test to make sure we're running the build as root
842
843if [ "$UID" != "0" ] ; then
844 echo "You must be logged in as root to successfully build LFS."
845 exit 1
[a5e49c6]846fi
847
[49aea5e]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
982[[ "$PWD" != "$JHALFSDIR" ]] && cp -v $0 $XSL $FILES $JHALFSDIR/
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.