source: jhalfs@ 4618749

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

Be sure that $BUILDDIR is clean and usable.

  • Property mode set to 100755
File size: 28.4 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
88echo \"Look like the \$BUILDDIR directory contains subdirectories\" >&2
89echo \"from a previous LFS build.\" >&2
90echo \"\" >&2
91echo \"Please, format the partition mounted on \$BUILDDIR or set\" >&2
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#----------------------------#
330(
331 cat << EOF
332020-creatingtoolsdir:
333 @\$(call echo_message, Building)
334 @mkdir -v \$(LFS)/tools && \\
335 ln -sv \$(LFS)/tools / && \\
336 touch \$@
[fbb6b78]337
[49aea5e]338021-addinguser: 020-creatingtoolsdir
339 @\$(call echo_message, Building)
340 @groupadd lfs && \\
341 useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
342 chown lfs \$(LFS)/tools && \\
343 chown lfs \$(LFS)/sources && \\
344 touch \$@
345
346022-settingenvironment: 021-addinguser
347 @\$(call echo_message, Building)
348 @echo "set +h" > /home/lfs/.bashrc && \\
349 echo "umask 022" >> /home/lfs/.bashrc && \\
350 echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
351 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
352 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
353 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
354 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
355 chown lfs:lfs /home/lfs/.bashrc && \\
356 touch envars && \\
357 touch \$@
358EOF
359) >> $MKFILE.tmp
360}
[f8de156]361
[49aea5e]362#----------------------------#
363chapter5_Makefiles() {
364#----------------------------#
[0bad6ba]365 for file in chapter05/* ; do
[71642ef]366 # Keep the script file name
367 i=`basename $file`
[63b2859]368
[01e51a1]369 # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
370 if [ "$TOOLCHAINTEST" = "0" ]; then
[e1093cd]371 if [[ `_IS_ $i tcl` ]] || [[ `_IS_ $i expect` ]] || [[ `_IS_ $i dejagnu` ]] ; then
[01e51a1]372 continue
373 fi
374 fi
375
[70a223e]376 # Test if the stripping phase must be skipped
377 if [ "$STRIP" = "0" ] && [[ `_IS_ $i stripping` ]] ; then
378 continue
379 fi
380
[71642ef]381 # First append each name of the script files to a list (this will become
382 # the names of the targets in the Makefile
383 chapter5="$chapter5 $i"
[557fe91]384
[71642ef]385 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
386 # and binutils in chapter 5)
387 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
[557fe91]388
[e909d9d]389 # Set the dependency for the first target.
390 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
391
392 # Drop in the name of the target on a new line, and the previous target
[0fc4c75]393 # as a dependency. Also call the echo_message function.
[3f990d1]394(
395 cat << EOF
396
397$i: $PREV
398 @\$(call echo_message, Building)
399EOF
400) >> $MKFILE.tmp
[557fe91]401
[71642ef]402 # Find the version of the command files, if it corresponds with the building of
403 # a specific package
404 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
[557fe91]405
[71642ef]406 # If $vrs isn't empty, we've got a package...
407 if [ "$vrs" != "" ] ; then
408 if [ "$name" = "tcl" ] ; then
[be9970b]409 FILE="$name$vrs-src.tar"
[71642ef]410 else
[be9970b]411 FILE="$name-$vrs.tar"
[71642ef]412 fi
[557fe91]413
[71642ef]414 # Insert instructions for unpacking the package and to set
415 # the PKGDIR variable.
[3f990d1]416(
417 cat << EOF
418 @\$(call unpack,$FILE)
[eaa021a]419 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]420 chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
421 echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
422 echo "export PKGDIR" >> envars && \\
423EOF
424) >> $MKFILE.tmp
425
[71642ef]426 fi
[557fe91]427
[4c62c61]428 # Dump the path to the Binutils or TCL sources directory.
[e1093cd]429 if [[ `_IS_ $i binutils` ]] || [[ `_IS_ $i tcl` ]] ; then
[3f990d1]430(
431 cat << EOF
432 echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
433EOF
434) >> $MKFILE.tmp
[88dcce5]435
[71642ef]436 # For the Adjusting phase we must to cd to the binutils-build directory.
[e1093cd]437 elif [[ `_IS_ $i adjusting` ]] ; then
[3f990d1]438(
439 cat << EOF
440 @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
441 echo "export PKGDIR" >> envars
442EOF
443) >> $MKFILE.tmp
[0209bb7]444
[97a3ffc]445 # For the Expect build we need to set the TCLPATH envar.
[e1093cd]446 elif [[ `_IS_ $i expect` ]] ; then
[3f990d1]447(
448 cat << EOF
449 echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
450 echo "export TCLPATH" >> envars
451EOF
452) >> $MKFILE.tmp
[0fc4c75]453
454 # Everything else, add a true statment so we don't confuse make
455 else
[3f990d1]456(
457 cat << EOF
458 true
459EOF
460) >> $MKFILE.tmp
[71642ef]461 fi
[557fe91]462
[3f990d1]463 # Insert date and disk usage at the top of the log file, the script run
464 # and date and disk usage again at the bottom of the log file.
465(
466 cat << EOF
[43757c2]467 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[3f990d1]468 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
[43757c2]469 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[3f990d1]470EOF
471) >> $MKFILE.tmp
[71642ef]472
[cf7f294]473 # Remove the build directory(ies) except if the package build fails
474 # (to can review config.cache, config.log, and like.)
475 # For Binutils and TCL the sources must be retained some time.
[71642ef]476 if [ "$vrs" != "" ] ; then
[e1093cd]477 if [[ ! `_IS_ $i binutils` ]] && [[ ! `_IS_ $i tcl` ]] ; then
[3f990d1]478(
479 cat << EOF
[eaa021a]480 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]481 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
482 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
483 rm -r \$(LFS)\$(SRC)/$name-build; \\
484 fi;
485EOF
486) >> $MKFILE.tmp
[71642ef]487 fi
488 fi
[7bbd436]489
490 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
[e1093cd]491 if [[ `_IS_ $i adjusting` ]] ; then
[3f990d1]492(
493 cat << EOF
494 @rm -r \`cat sources-dir\` && \\
495 rm -r \$(LFS)\$(SRC)/binutils-build && \\
496 rm sources-dir
497EOF
498) >> $MKFILE.tmp
[7bbd436]499 fi
500
501 # Remove the TCL sources after a successful Expect build.
[e1093cd]502 if [[ `_IS_ $i expect` ]] ; then
[3f990d1]503(
504 cat << EOF
505 @rm -r \`cat sources-dir\` && \\
506 rm sources-dir
507EOF
508) >> $MKFILE.tmp
[7bbd436]509 fi
510
511 # Include a touch of the target name so make can check
512 # if it's already been made.
[3f990d1]513(
514 cat << EOF
515 @touch \$@
516EOF
517) >> $MKFILE.tmp
[7bbd436]518
[e909d9d]519 # Keep the script file name for Makefile dependencies.
520 PREV=$i
[49aea5e]521 done # end for file in chapter05/*
522}
[9e406b5]523
[49aea5e]524#----------------------------#
525chapter6_Makefiles() {
526#----------------------------#
[97a3ffc]527 for file in chapter06/* ; do
528 # Keep the script file name
529 i=`basename $file`
530
[16c67ed]531 # We'll run the chroot commands differently than the others, so skip them in the
532 # dependencies and target creation.
[e1093cd]533 if [[ `_IS_ $i chroot` ]] ; then
[16c67ed]534 continue
535 fi
536
[70a223e]537 # Test if the stripping phase must be skipped
538 if [ "$STRIP" = "0" ] && [[ `_IS_ $i stripping` ]] ; then
539 continue
540 fi
541
[97a3ffc]542 # First append each name of the script files to a list (this will become
543 # the names of the targets in the Makefile
544 chapter6="$chapter6 $i"
545
546 # Grab the name of the target
547 name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
548
549 # Drop in the name of the target on a new line, and the previous target
[4c62c61]550 # as a dependency. Also call the echo_message function.
[3f990d1]551(
552 cat << EOF
553
554$i: $PREV
555 @\$(call echo_message, Building)
556EOF
557) >> $MKFILE.tmp
[97a3ffc]558
559 # Find the version of the command files, if it corresponds with the building of
560 # a specific package
561 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
562
563 # If $vrs isn't empty, we've got a package...
[3f990d1]564 # Insert instructions for unpacking the package and changing directories
[97a3ffc]565 if [ "$vrs" != "" ] ; then
[be9970b]566 FILE="$name-$vrs.tar.*"
[3f990d1]567(
568 cat << EOF
[be9970b]569 @\$(call unpack2,$FILE)
[eaa021a]570 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]571 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
[2e51f44]572 echo "export PKGDIR" >> envars
[3f990d1]573EOF
574) >> $MKFILE.tmp
[97a3ffc]575 fi
576
577 # For the Re-Adjusting phase we must to cd to the binutils-build directory.
[e1093cd]578 if [[ `_IS_ $i readjusting` ]] ; then
[3f990d1]579(
580 cat << EOF
581 @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
582 echo "export PKGDIR" >> envars
583EOF
584) >> $MKFILE.tmp
[97a3ffc]585
[2a54650]586 # For Glibc we need to set TIMEZONE envar.
[e1093cd]587 elif [[ `_IS_ $i glibc` ]] ; then
[2a54650]588(
589 cat << EOF
590 @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
591 echo "export TIMEZONE" >> envars
592EOF
593) >> $MKFILE.tmp
594
[a41ce58]595 # For Groff we need to set PAGE envar.
[e1093cd]596 elif [[ `_IS_ $i groff` ]] ; then
[a41ce58]597(
598 cat << EOF
599 @echo "PAGE=\$(PAGE)" >> envars && \\
600 echo "export PAGE" >> envars
601EOF
602) >> $MKFILE.tmp
603 fi
604
[50408d5]605 # In the mount of kernel filesystems we need to set LFS
[80c00fc]606 # and not to use chroot.
[e1093cd]607 if [[ `_IS_ $i kernfs` ]] ; then
[3f990d1]608(
609 cat << EOF
[43757c2]610 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[b51d2ec]611 export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
[43757c2]612 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[3f990d1]613EOF
[a7d20b8]614) >> $MKFILE.tmp
615
616 # The rest of Chapter06
[7ecd166]617 else
[3f990d1]618(
619 cat << EOF
[43757c2]620 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[2e51f44]621 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
[43757c2]622 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[3f990d1]623EOF
624) >> $MKFILE.tmp
[7ecd166]625 fi
[97a3ffc]626
[cf7f294]627 # Remove the build directory(ies) except if the package build fails.
[97a3ffc]628 if [ "$vrs" != "" ] ; then
[3f990d1]629(
630 cat << EOF
[eaa021a]631 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[3f990d1]632 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
633 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
634 rm -r \$(LFS)\$(SRC)/$name-build; \\
635 fi;
636EOF
637) >> $MKFILE.tmp
[97a3ffc]638 fi
639
[4e4a8d5]640 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
[e1093cd]641 if [[ `_IS_ $i readjusting` ]] ; then
[3f990d1]642(
643 cat << EOF
644 @rm -r \`cat sources-dir\` && \\
645 rm -r \$(LFS)\$(SRC)/binutils-build && \\
646 rm sources-dir
647EOF
648) >> $MKFILE.tmp
[97a3ffc]649 fi
650
[732d1f1]651 # Include a touch of the target name so make can check
652 # if it's already been made.
[3f990d1]653(
654 cat << EOF
655 @touch \$@
656EOF
657) >> $MKFILE.tmp
[732d1f1]658
[97a3ffc]659 # Keep the script file name for Makefile dependencies.
660 PREV=$i
[49aea5e]661 done # end for file in chapter06/*
662}
[97a3ffc]663
[49aea5e]664#----------------------------#
665chapter789_Makefiles() {
666#----------------------------#
[cf7f294]667 for file in chapter0{7,8,9}/* ; do
668 # Keep the script file name
669 i=`basename $file`
670
[e1093cd]671 # Grub must be configured manually.
672 # The filesystems can't be unmounted via Makefile and the user
673 # should to enter to the chroot environment to create the root
674 # password, edit several files and setup Grub,
675 if [[ `_IS_ $i grub` ]] || [[ `_IS_ $i reboot` ]] ; then
[83f64dc]676 continue
[cf7f294]677 fi
678
679 # If no .config file is supplied, the kernel build is skipped
[e1093cd]680 if [ -z $CONFIG ] && [[ `_IS_ $i kernel` ]] ; then
681 continue
[cf7f294]682 fi
683
684 # First append each name of the script files to a list (this will become
685 # the names of the targets in the Makefile
686 chapter789="$chapter789 $i"
687
688 # Drop in the name of the target on a new line, and the previous target
689 # as a dependency. Also call the echo_message function.
690(
691 cat << EOF
692
693$i: $PREV
694 @\$(call echo_message, Building)
695EOF
696) >> $MKFILE.tmp
697
698 # Find the the bootscripts and kernel package names
[e1093cd]699 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
700 if [[ `_IS_ $i bootscripts` ]] ; then
[cf7f294]701 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
[be9970b]702 FILE="lfs-bootscripts-$vrs.tar.*"
[e1093cd]703 elif [[ `_IS_ $i kernel` ]] ; then
[cf7f294]704 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
[be9970b]705 FILE="linux-$vrs.tar.*"
[cf7f294]706 fi
707(
708 cat << EOF
[be9970b]709 @\$(call unpack2,$FILE)
[cf7f294]710 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
711 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
712 echo "export PKGDIR" >> envars
713EOF
714) >> $MKFILE.tmp
715 fi
[50408d5]716
[cf7f294]717 # Put in place the kernel .config file
[e1093cd]718 if [[ `_IS_ $i kernel` ]] ; then
[cf7f294]719(
720 cat << EOF
[f0f60d0]721 @cp $CONFIG \$(LFS)/sources/kernel-config
[cf7f294]722EOF
723) >> $MKFILE.tmp
724 fi
725
[50408d5]726 # Check if we have a real /etc/fstab file
[e1093cd]727 if [[ `_IS_ $i fstab` ]] && [[ -n "$FSTAB" ]] ; then
[50408d5]728(
729 cat << EOF
[43757c2]730 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[50408d5]731 cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
[43757c2]732 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[50408d5]733EOF
734) >> $MKFILE.tmp
735 else
[cf7f294]736 # Initialize the log an run the script
737(
738 cat << EOF
[43757c2]739 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
[cf7f294]740 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
[43757c2]741 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
[cf7f294]742EOF
743) >> $MKFILE.tmp
[50408d5]744 fi
[cf7f294]745
746 # Remove the build directory except if the package build fails.
[e1093cd]747 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
[cf7f294]748(
749 cat << EOF
750 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
[50408d5]751 rm -r \$(LFS)\$(SRC)/\$\$ROOT
[cf7f294]752EOF
753) >> $MKFILE.tmp
754 fi
755
756 # Include a touch of the target name so make can check
757 # if it's already been made.
758(
759 cat << EOF
760 @touch \$@
761EOF
762) >> $MKFILE.tmp
763
764 # Keep the script file name for Makefile dependencies.
765 PREV=$i
[49aea5e]766 done # for file in chapter0{7,8,9}/*
767}
768
769
770#----------------------------#
771build_Makefile() {
772#----------------------------#
773 echo -n "Creating Makefile... "
774 cd $JHALFSDIR/commands
775
776 # Start with a clean Makefile.tmp file
777 >$MKFILE.tmp
778
779 chapter4_Makefiles
780 chapter5_Makefiles
781 chapter6_Makefiles
782 chapter789_Makefiles
783
[cf7f294]784
[3f990d1]785 # Add a header, some variables and include the function file
786 # to the top of the real Makefile.
787(
788 cat << EOF
789$HEADER
790
791SRC= /sources
792LFS= $BUILDDIR
[a41ce58]793PAGE= $PAGE
[2a54650]794TIMEZONE= $TIMEZONE
[3f990d1]795
796include functions
797
798EOF
799) > $MKFILE
[8bb92e7]800
[c08d23b]801
802 # Add chroot commands
803 i=1
804 for file in chapter06/*chroot* ; do
805 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
[49aea5e]806 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
807 -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
[d7fd195]808 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
[c08d23b]809 i=`expr $i + 1`
810 done
[9e406b5]811
[0bad6ba]812 # Drop in the main target 'all:' and the chapter targets with each sub-target
813 # as a dependency.
[3f990d1]814(
815 cat << EOF
[cf7f294]816all: chapter4 chapter5 chapter6 chapter789
[898f47a]817 @\$(call echo_finished,$VERSION)
[3f990d1]818
819chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
820
821chapter5: chapter4 $chapter5
822
823chapter6: chapter5 $chapter6
824
[cf7f294]825chapter789: chapter6 $chapter789
826
[3f990d1]827clean-all: clean
828 rm -rf ./*
829
[0bd7b91]830clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
[3f990d1]831
832clean-chapter4:
833 -userdel lfs
834 rm -rf /home/lfs
835 rm -rf \$(LFS)/tools
836 rm -f /tools
837 rm -f envars
838 rm -f 02* logs/02*.log
839
840clean-chapter5:
841 rm -rf \$(LFS)/tools/*
842 rm -f $chapter5
843 cd logs && rm -f $chapter5 && cd ..
[0bd7b91]844
845clean-chapter6:
[3338588]846 -umount \$(LFS)/sys
847 -umount \$(LFS)/proc
848 -umount \$(LFS)/dev/shm
849 -umount \$(LFS)/dev/pts
850 -umount \$(LFS)/dev
[0bd7b91]851 rm -rf \$(LFS)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
852 rm -f $chapter6
853 cd logs && rm -f $chapter6 && cd ..
854
855clean-chapter789:
856 rm -f $chapter789
857 cd logs && rm -f $chapter789 && cd ..
858
[3f990d1]859
860EOF
861) >> $MKFILE
[0bad6ba]862
[9e406b5]863 # Bring over the items from the Makefile.tmp
864 cat $MKFILE.tmp >> $MKFILE
865 rm $MKFILE.tmp
866 echo -ne "done\n"
[f8de156]867}
868
[49aea5e]869#----------------------------#
[88dcce5]870run_make() {
[49aea5e]871#----------------------------#
[d310939]872 # Test if make must be run.
873 if [ "$RUNMAKE" = "1" ] ; then
[38150e5]874 # Test to make sure we're running the build as root
875 if [ "$UID" != "0" ] ; then
876 echo "You must be logged in as root to successfully build LFS."
877 exit 1
878 fi
[d310939]879 # Build the system
880 if [ -e $MKFILE ] ; then
[e3e1db0]881 echo -ne "Building the LFS system...\n"
[d310939]882 cd $JHALFSDIR && make
883 echo -ne "done\n"
884 fi
[88dcce5]885 fi
886}
[1236262]887
888
[49aea5e]889
890###################################
891### MAIN ###
892###################################
893
894# Evaluate any command line switches
895
896while test $# -gt 0 ; do
897 case $1 in
898 --version | -V )
899 echo "$version"
900 exit 0
901 ;;
902
903 --help | -h )
904 echo "$usage"
905 exit 0
906 ;;
907
908 --LFS-version | -L )
909 test $# = 1 && eval "$exit_missing_arg"
910 shift
911 case $1 in
912 dev* | SVN | trunk )
913 LFSVRS=development
914 ;;
915 testing | 6.1.1 )
916 LFSVRS=6.1.1
917 ;;
[ef94414]918
919 alpha*)
920 LFSVRS=alphabetical
921 ;;
[49aea5e]922 * )
923 echo "$1 is an unsupported version at this time."
924 exit 1
925 ;;
926 esac
927 ;;
928
929 --directory | -d )
930 test $# = 1 && eval "$exit_missing_arg"
931 shift
932 BUILDDIR=$1
933 ;;
934
935 --download-client | -D )
936 test $# = 1 && eval "$exit_missing_arg"
937 shift
938 DL=$1
939 ;;
940
941 --working-copy | -W )
942 test $# = 1 && eval "$exit_missing_arg"
943 shift
944 if [ -f $1/patches.ent ] ; then
945 WC=1
946 BOOK=$1
947 else
948 echo -e "\nLook like $1 isn't a supported working copy."
949 echo -e "Verify your selection and the command line.\n"
950 exit 1
951 fi
952 ;;
953
954 --testsuites | -T ) TEST=1 ;;
955
956 --get-packages | -P ) HPKG=1 ;;
957
958 --run-make | -M ) RUNMAKE=1 ;;
959
960 --no-toolchain-test ) TOOLCHAINTEST=0 ;;
[db181c47]961
[70a223e]962 --no-strip ) STRIP=0 ;;
963
[db181c47]964 --no-vim-lang ) VIMLANG=0 ;;
[49aea5e]965
966 --page_size )
967 test $# = 1 && eval "$exit_missing_arg"
968 shift
969 case $1 in
970 letter | A4 )
971 PAGE=$1
972 ;;
973 * )
974 echo "$1 isn't a supported page size."
975 exit 1
976 ;;
977 esac
978 ;;
979
980
981 --timezone )
982 test $# = 1 && eval "$exit_missing_arg"
983 shift
984 if [ -f /usr/share/zoneinfo/$1 ] ; then
985 TIMEZONE=$1
986 else
987 echo -e "\nLook like $1 isn't a valid timezone description."
988 echo -e "Verify your selection and the command line.\n"
989 exit 1
990 fi
991 ;;
992
993 --fstab )
994 test $# = 1 && eval "$exit_missing_arg"
995 shift
996 if [ -f $1 ] ; then
997 FSTAB=$1
998 else
999 echo -e "\nFile $1 not found. Verify your command line.\n"
1000 exit 1
1001 fi
1002 ;;
1003
1004 --kernel-config | -C )
1005 test $# = 1 && eval "$exit_missing_arg"
1006 shift
1007 if [ -f $1 ] ; then
1008 CONFIG=$1
1009 else
1010 echo -e "\nFile $1 not found. Verify your command line.\n"
1011 exit 1
1012 fi
1013 ;;
1014
1015 * )
1016 echo "$usage"
1017 exit 1
1018 ;;
1019 esac
1020 shift
1021done
1022
[4618749]1023# If $BUILDDIR have subdirectories like tools/ or bin/, stop the run
1024# and notify the user about that. This also prevent to set "-d /"
1025# by mistake.
1026
1027if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] ; then
1028 eval "$no_empty_builddir"
1029fi
1030
[e1093cd]1031# Find the download client to use, if not already specified.
1032
1033if [ -z $DL ] ; then
1034 if [ `type -p wget` ] ; then
1035 DL=wget
1036 elif [ `type -p curl` ] ; then
1037 DL=curl
1038 else
1039 eval "$no_dl_client"
1040 fi
1041fi
1042
[49aea5e]1043[[ ! -d $JHALFSDIR ]] && mkdir -pv $JHALFSDIR
[db181c47]1044[[ "$PWD" != "$JHALFSDIR" ]] && cp -v $FILES $JHALFSDIR/ && \
1045 sed -e 's/FAKEDIR/'$BOOK'/' $XSL > $JHALFSDIR/dump-lfs-scripts.xsl && \
1046 export XSL=$JHALFSDIR/dump-lfs-scripts.xsl
[49aea5e]1047[[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
1048>$LOGDIR/$LOG
1049
[1236262]1050get_book
[f8de156]1051build_Makefile
[71642ef]1052run_make
[49aea5e]1053
Note: See TracBrowser for help on using the repository browser.