source: jhalfs@ e1093cd

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

Changed the "if" test to use a cunstomized function.
Thanks to George B.

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