source: jhalfs@ d13460c

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

Typo fixes pointed by Jeremy.

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