source: jhalfs@ da5860a

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

Added --rebuild switch.

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