source: jhalfs@ eb81473

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

Merged r2186 from trunk.

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