source: jhalfs@ f4a4ba5

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

Fixed an erroneous commands rebuild when the user language isn't English.

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