source: jhalfs@ a0ed344

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

Changed how the testsuites are handled and fixed the missing locales installation for chapter05 testsuites.

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