source: jhalfs@ bf3ad3a

0.2 1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since bf3ad3a was 9383fd6, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

Changed credits - I'm somewhat active again and Manuel has written enough code to be considered a co-author

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