source: jhalfs@ 49aea5e

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

Reorganized the script.
Added jhalfs.conf to have more control over the configuration.
Many thanks to George B.

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