source: jhalfs@ 8ebf154

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

Triying to manage the cases where the lfs user is already present in the host.

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