source: jhalfs@ 9349479

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

No need to retain TCL's directory anymore, and a few typo fixes.

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