source: jhalfs@ 8bb92e7

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

Add a header to the generated Makefile

  • Property mode set to 100755
File size: 20.8 KB
RevLine 
[fbb6b78]1#!/bin/sh
[1236262]2
3version="
[63b2859]4jhalfs development
5
[db9cec6]6Originally written by Jeremy Huntwork.
[557fe91]7Maintained by Manuel Canales Esparcia.
[1236262]8
9This program is published under the \
[557fe91]10Gnu General Public License, Version 2.
11"
[1236262]12
13usage="\
14Usage: $0 [OPTION]
15
16Options:
[557fe91]17 -h, --help print this help, then exit
[24530379]18
[557fe91]19 -V, --version print version number, then exit
[24530379]20
[557fe91]21 -d --directory=DIR use DIR directory for building LFS; all files
22 jhalfs produces will be in the directory
23 DIR/jhalfs
[24530379]24
25 -P, --get-packages download the packages and patches
26
[557fe91]27 -D, --download-client=CLIENT use CLIENT as the program for retrieving
[24530379]28 packages (for use in conjunction with -P)
29
30 -W, --working-copy=DIR use the local working copy placed in DIR
31 as the LFS book
32
33 -L, --LFS-version=VER ckeckout VER version of the LFS book
34
35 -T, --testsuites add support to run the optional testsuites
36
[d310939]37 -M, --run-make run make on the generated Makefile
[1236262]38"
39
40help="\
41Try '$0 --help' for more information."
42
43exit_missing_arg="\
44echo \"Option '\$1' requires an argument\" >&2
45echo \"\$help\" >&2
46exit 1"
47
48no_dl_client="\
49echo \"Could not find a way to download the LFS sources.\" >&2
50echo \"Attempting to continue.\" >&2"
51
52while test $# -gt 0 ; do
[557fe91]53 case $1 in
54 --version | -V )
55 echo "$version"
56 exit 0
57 ;;
58
59 --help | -h )
60 echo "$usage"
61 exit 0
62 ;;
63
64 --LFS-version | -L )
65 test $# = 1 && eval "$exit_missing_arg"
66 shift
67 case $1 in
68 dev* | SVN | trunk )
69 LFSVRS=development
70 ;;
71 * )
72 echo "$1 is an unsupported version at this time."
73 exit 1
74 ;;
75 esac
76 shift
77 ;;
78
79 --directory | -d )
80 test $# = 1 && eval "$exit_missing_arg"
81 shift
82 BUILDDIR=$1
83 shift
84 ;;
85
86 --download-client | -D )
87 test $# = 1 && eval "$exit_missing_arg"
88 shift
89 DL=$1
90 shift
91 ;;
92
[24530379]93 --working-copy | -W )
94 test $# = 1 && eval "$exit_missing_arg"
95 shift
96 WC=1
97 BOOK=$1
98 shift
99 ;;
100
[d310939]101 --testsuites | -T )
[db9cec6]102 TEST=1
103 shift
104 ;;
105
[d310939]106 --get-packages | -P )
[07f47df]107 HPKG=1
108 shift
109 ;;
110
[d310939]111 --run-make | -M )
112 RUNMAKE=1
113 shift
114 ;;
115
[557fe91]116 * )
117 echo "$usage"
118 exit 1
119 ;;
120 esac
[1236262]121done
122
123# Test to make sure we're running the build as root
124
125if [ "$UID" != "0" ] ; then
[557fe91]126 echo "You must be logged in as root to successfully build LFS."
127 exit 1
[1236262]128fi
129
130# Find the download client to use, if not already specified.
131
132if [ -z $DL ] ; then
133 if [ `type -p wget` ] ; then
[557fe91]134 DL=wget
[1236262]135 elif [ `type -p curl` ] ; then
[557fe91]136 DL=curl
[1236262]137 else
[557fe91]138 eval "$no_dl_client"
[1236262]139 fi
140fi
141
142SVN="svn://svn.linuxfromscratch.org"
143HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
[48d7968]144if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
[4dafc45]145JHALFSDIR=$BUILDDIR/jhalfs
[97a3ffc]146LOGDIR=/jhalfs/logs
[a5e49c6]147LOG=000-jhalfs.log
[f8de156]148MKFILE=$JHALFSDIR/Makefile
[3cfe871]149XSL=dump-lfs-scripts.xsl
[0fc4c75]150FNC=functions
[db9cec6]151if [ -z $TEST ] ; then TEST=0 ; fi
[1236262]152
[8bb92e7]153HEADER="# This file is automatically generated by jhalfs
154# DO NOT EDIT THIS FILE MANUALLY
155#
156# Generated on `date \"+%F %X %Z\"`"
157
[1236262]158get_book() {
159 # Check for Subversion instead of just letting the script hit 'svn' and fail.
160 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
[557fe91]161 exit 1"
[4dafc45]162 cd $JHALFSDIR
[fbb6b78]163
[1236262]164 # Test to make sure the LFS version is set
165 if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
[24530379]166
[56dd1e2]167 # Set the book's sources directory
[24530379]168 if [ -z $BOOK ] ; then BOOK=lfs-$LFSVRS ; fi
169
170 if [ -z $WC ] ; then
171 echo -n "Downloading the LFS Book, version $LFSVRS... "
172
173 # Grab the LFS book fresh if it's missing, otherwise, update it from the
174 # repo. If we've already extracted the commands, move on to getting the
175 # sources.
176 if [ -d lfs-$LFSVRS ] ; then
177 cd lfs-$LFSVRS
178 if svn up | grep -q At && test -d $JHALFSDIR/commands && \
179 test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
180 echo -ne "done\n"
181 get_sources
182 else
183 echo -ne "done\n"
184 extract_commands
185 fi
[557fe91]186 else
[24530379]187 if [ $LFSVRS = development ] ; then
188 svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$BUILDDIR$LOGDIR/$LOG 2>&1
189 else
190 svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$BUILDDIR$LOGDIR/$LOG 2>&1
191 fi
[557fe91]192 echo -ne "done\n"
193 extract_commands
194 fi
[1236262]195 else
[24530379]196 echo -ne "Using $BOOK as book's sources ...\n"
[557fe91]197 extract_commands
[1236262]198 fi
199}
200
201extract_commands() {
202 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
203 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
[557fe91]204 exit 1"
[4dafc45]205 cd $JHALFSDIR
[1236262]206
207 # Start clean
208 if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
209 echo -n "Extracting commands... "
210
[dc2fee8]211 # Dump the commands in shell script form from the LFS book.
[db9cec6]212 xsltproc --nonet --xinclude --stringparam testsuite $TEST -o ./commands/ \
[24530379]213 $XSL $BOOK/index.xml >>$BUILDDIR$LOGDIR/$LOG 2>&1
[1236262]214
215 # Grab the patches and package names.
[4dafc45]216 cd $JHALFSDIR
[1236262]217 for i in patches packages ; do rm -f $i ; done
[24530379]218 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
[557fe91]219 -e '/generic/d' >> packages
[24530379]220 grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
[1236262]221
222 # Done. Moving on...
223 echo -ne "done\n"
224 get_sources
225}
226
227download() {
228 cd $BUILDDIR/sources
229
230 # Hackish fix for the bash-doc package that doesn't conform
231 # to norms in the URL scheme.
232 DIR=`echo $1 | sed 's@-doc@@'`
233
234 # Find the md5 sum for this package.
235 if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
236
237 if [ ! -f $2 ] ; then
[557fe91]238 case $DL in
239 wget )
240 wget $HTTP/$DIR/$2
241 ;;
242 curl )
243 `curl -# $HTTP/$DIR/$2 -o $2`
244 ;;
245 * )
246 echo "$DL not supported at this time."
247 ;;
248 esac
[1236262]249 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
[557fe91]250 case $DL in
251 wget )
252 wget -c $HTTP/$DIR/$2
253 ;;
254 curl )
255 `curl -# -C - $HTTP/$DIR/$2 -o $2`
256 ;;
257 * )
258 echo "$DL not supported at this time."
259 ;;
260 esac
[1236262]261 fi
262 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
263 exit 1
264 fi
265}
266
267get_sources() {
268
[07f47df]269 # Test if the packages must be downloaded
[d310939]270 if [ "$HPKG" = "1" ] ; then
[1236262]271
[07f47df]272 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
273 # separates each iteration by lines. It is necessary to have the second
274 # ' on the next line.
275 IFS='
276'
[1236262]277
[07f47df]278 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
279 cd $BUILDDIR/sources
280 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
281
282 download "" MD5SUMS
283
284 # Iterate through each package and grab it, along with any patches it needs.
285 for i in `cat $JHALFSDIR/packages` ; do
286 PKG=`echo $i | sed 's/-version.*//'`
287
288 # Someone used some silly entities right next to the valid package entities.
289 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
290
291 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
292 if [ "$PKG" = "tcl" ] ; then
293 FILE="$PKG$VRS-src.tar.bz2"
294 else
295 FILE="$PKG-$VRS.tar.bz2"
296 fi
297 download $PKG $FILE
298 for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
299 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
300 download $PKG $PATCH
301 done
[fbb6b78]302 done
[07f47df]303 fi
[1236262]304}
305
[f8de156]306build_Makefile() {
[9e406b5]307 echo -n "Creating Makefile... "
[f8de156]308 cd $JHALFSDIR/commands
[fbb6b78]309
[f8de156]310 # Start with a clean Makefile.tmp file
311 >$MKFILE.tmp
312
[0bad6ba]313 for file in chapter05/* ; do
[71642ef]314 # Keep the script file name
315 i=`basename $file`
[63b2859]316
[71642ef]317 # First append each name of the script files to a list (this will become
318 # the names of the targets in the Makefile
319 chapter5="$chapter5 $i"
[557fe91]320
[71642ef]321 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
322 # and binutils in chapter 5)
323 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
[557fe91]324
[e909d9d]325 # Set the dependency for the first target.
326 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
327
328 # Drop in the name of the target on a new line, and the previous target
[0fc4c75]329 # as a dependency. Also call the echo_message function.
[e909d9d]330 echo -e "\n$i: $PREV" >> $MKFILE.tmp
[0fc4c75]331 echo -e "\t@\$(call echo_message, Building)" >> $MKFILE.tmp
[557fe91]332
[71642ef]333 # Find the version of the command files, if it corresponds with the building of
334 # a specific package
335 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
[557fe91]336
[71642ef]337 # If $vrs isn't empty, we've got a package...
338 if [ "$vrs" != "" ] ; then
339 if [ "$name" = "tcl" ] ; then
340 FILE="$name$vrs-src.tar.bz2"
341 else
342 FILE="$name-$vrs.tar.bz2"
343 fi
[557fe91]344
[71642ef]345 # Insert instructions for unpacking the package and to set
346 # the PKGDIR variable.
[0fc4c75]347 echo -e "\t@\$(call unpack-lfs,$FILE)" >> $MKFILE.tmp
348 echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
[71642ef]349 echo -e "\tchown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
350 echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
351 echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
352 fi
[557fe91]353
[97a3ffc]354 # Dump the path to the Binutils pass1 or TCL sources directory.
355 if [ "$i" = "027-binutils-pass1" -o "$i" = "032-tcl" ] ; then
[0fc4c75]356 echo -e "\techo \"\$(LFS)\$(SRC)/\$\$ROOT\" > sources-dir" >> $MKFILE.tmp
[88dcce5]357
[97a3ffc]358 # Dump the path to the Binutils pass2 sources directory.
[0fc4c75]359 elif [ "$i" = "036-binutils-pass2" ] ; then
360 echo -e "\techo \"\$(SRC)/\$\$ROOT\" > sources-dir" >> $MKFILE.tmp
[97a3ffc]361
[71642ef]362 # For the Adjusting phase we must to cd to the binutils-build directory.
[0fc4c75]363 elif [ "$i" = "031-adjusting" ] ; then
[d310939]364 echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/binutils-build\" > envars && \\" >> $MKFILE.tmp
[0fc4c75]365 echo -e "\techo \"export PKGDIR\" >> envars" >> $MKFILE.tmp
[0209bb7]366
[97a3ffc]367 # For the Expect build we need to set the TCLPATH envar.
[0fc4c75]368 elif [ "$i" = "033-expect" ] ; then
[71642ef]369 echo -e "\techo \"TCLPATH=\`cat sources-dir\`\" >> envars && \\" >> $MKFILE.tmp
[0fc4c75]370 echo -e "\techo \"export TCLPATH\" >> envars" >> $MKFILE.tmp
371
372 # Everything else, add a true statment so we don't confuse make
373 else
374 echo -e "\ttrue" >> $MKFILE.tmp
[71642ef]375 fi
[557fe91]376
[4e4a8d5]377 # Insert date and disk usage at the top of the log file.
[0fc4c75]378 echo -e "\t@echo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >logs/$i && \\" >> $MKFILE.tmp
[133ecac]379
[71642ef]380 # Insert the script run
[7ecd166]381 echo -e "\tsu - lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" >>logs/$i 2>&1 && \\" >> $MKFILE.tmp
[71642ef]382
[4e4a8d5]383 # Insert date and disk usage at the bottom of the log file.
[0fc4c75]384 echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >>logs/$i" >> $MKFILE.tmp
[71642ef]385
386 # Remove the build directory(ies) even if the package build fails, except for
[d310939]387 # Binutils and TCL. In that cases the sources directories are removed
[71642ef]388 # only if the build fails.
389 if [ "$vrs" != "" ] ; then
[d310939]390 if [ "$i" != "027-binutils-pass1" ] && [ "$i" != "032-tcl" ] && [ "$i" != "036-binutils-pass2" ] ; then
[0fc4c75]391 echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
[71642ef]392 echo -e "\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
[d310939]393 echo -e "\tif [ -e \$(LFS)\$(SRC)/$name-build ]; then \\" >> $MKFILE.tmp
394 echo -e "\t\trm -r \$(LFS)\$(SRC)/$name-build; \\" >> $MKFILE.tmp
[71642ef]395 echo -e "\tfi;" >> $MKFILE.tmp
396 fi
397 fi
[d310939]398 if [ "$i" = "027-binutils-pass1" -o "$i" = "036-binutils-pass2" ] ; then
[0fc4c75]399 echo -e "\t@if [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
[71642ef]400 echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
401 echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
[d310939]402 echo -e "\t\trm -r \$(LFS)\$(SRC)/binutils-build; \\" >> $MKFILE.tmp
403 echo -e "\tfi;" >> $MKFILE.tmp
404 fi
405 if [ "$i" = "032-tcl" ] ; then
[0fc4c75]406 echo -e "\t@if [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
[d310939]407 echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
408 echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT; \\" >> $MKFILE.tmp
[71642ef]409 echo -e "\tfi;" >> $MKFILE.tmp
410 fi
[44f88e3]411
[4e4a8d5]412 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
[71642ef]413 if [ "$i" = "031-adjusting" ] ; then
[0fc4c75]414 echo -e "\t@if [ -e \$@ ] ; then \\" >> $MKFILE.tmp
[71642ef]415 echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
[d310939]416 echo -e "\t\trm -r \$(LFS)\$(SRC)/binutils-build && \\" >> $MKFILE.tmp
417 echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
[71642ef]418 echo -e "\tfi;" >> $MKFILE.tmp
419 fi
[0209bb7]420
[4e4a8d5]421 # Remove the TCL sources after a successful Expect build.
[71642ef]422 if [ "$i" = "033-expect" ] ; then
[0fc4c75]423 echo -e "\t@if [ -e \$@ ] ; then \\" >> $MKFILE.tmp
[71642ef]424 echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
[d310939]425 echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
[71642ef]426 echo -e "\tfi;" >> $MKFILE.tmp
427 fi
[a5e49c6]428
[968dafd]429 # Include a touch of the target name so make can check
430 # if it's already been made.
[0fc4c75]431 echo -e "\t@touch \$@" >> $MKFILE.tmp
[e909d9d]432
433 # Keep the script file name for Makefile dependencies.
434 PREV=$i
[f8de156]435 done
[9e406b5]436
[97a3ffc]437 for file in chapter06/* ; do
438 # Keep the script file name
439 i=`basename $file`
440
441 # First append each name of the script files to a list (this will become
442 # the names of the targets in the Makefile
443 chapter6="$chapter6 $i"
444
445 # Grab the name of the target
446 name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
447
448 # Set the dependency for the first target.
449 if [ -z $PREV ] ; then PREV=055-stripping ; fi
450
451 # Drop in the name of the target on a new line, and the previous target
452 # as a dependency.
[1936487]453 if echo $i | grep -q "chroot" ; then
454 continue
455 else
[c08d23b]456 echo -e "\n$i: $PREV" >> $MKFILE.tmp
457 fi
[97a3ffc]458
459 # Find the version of the command files, if it corresponds with the building of
460 # a specific package
461 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
462
463 # If $vrs isn't empty, we've got a package...
464 if [ "$vrs" != "" ] ; then
465 FILE="$name-$vrs.tar.bz2"
466
467 # Insert instructions for unpacking the package and changing directories
[0fc4c75]468 echo -e "\t@\$(call unpack,$FILE)" >> $MKFILE.tmp
469 echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
[56dd1e2]470 echo -e "\techo \"PKGDIR=\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
471 echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
[97a3ffc]472 fi
473
474 # For the Re-Adjusting phase we must to cd to the binutils-build directory.
475 if [ "$i" = "067-readjusting" ] ; then
[56dd1e2]476 echo -e "\techo \"PKGDIR=\$(SRC)/binutils-build\" > envars && \\" >> $MKFILE.tmp
[0fc4c75]477 echo -e "\techo \"export PKGDIR\" >> envars" >> $MKFILE.tmp
[97a3ffc]478
479 # Insert the script run
[7ecd166]480 # For the mount of kernel filesystems we need to set LFS.
[0fc4c75]481 elif [ "$i" = "057-kernfs" ] ; then
[7ecd166]482 echo -e "\techo \"LFS=\$(LFS)\" > envars && \\" >> $MKFILE.tmp
483 echo -e "\techo \"export LFS\" >> envars && \\" >> $MKFILE.tmp
[4e4a8d5]484 # Insert date and disk usage at the top of the log file.
[7ecd166]485 echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >logs/$i && \\" >> $MKFILE.tmp
486 echo -e "\t. envars && commands/$file >>logs/$i 2>&1 && \\" >> $MKFILE.tmp
[4e4a8d5]487 # Insert date and disk usage at the bottom of the log file.
[0fc4c75]488 echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >>logs/$i" >> $MKFILE.tmp
[7ecd166]489 else
[4e4a8d5]490 # Insert date and disk usage at the top of the log file.
[7ecd166]491 echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* /\`\\\n\" >logs/$i && \\" >> $MKFILE.tmp
[c08d23b]492 echo -e "\t. envars && \$(CHROOT1) 'cd /jhalfs && commands/$file >>logs/$i 2>&1' && \\" >> $MKFILE.tmp
[4e4a8d5]493 # Insert date and disk usage at the bottom of the log file.
[0fc4c75]494 echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* /\`\\\n\" >>logs/$i" >> $MKFILE.tmp
[7ecd166]495 fi
[97a3ffc]496
[6299c11]497 # Remove the build directory(ies) even if the package build fails.
[97a3ffc]498 if [ "$vrs" != "" ] ; then
[0fc4c75]499 echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
[97a3ffc]500 echo -e "\trm -r \$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
501 echo -e "\tif [ -e \$(SRC)/$name-build ]; then \\" >> $MKFILE.tmp
502 echo -e "\t\trm -r \$(SRC)/$name-build; \\" >> $MKFILE.tmp
503 echo -e "\tfi;" >> $MKFILE.tmp
504 fi
505
[4e4a8d5]506 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
[6299c11]507 if [ "$i" = "067-readjusting" ] ; then
[0fc4c75]508 echo -e "\t@if [ -e \$@ ] ; then \\" >> $MKFILE.tmp
[97a3ffc]509 echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
510 echo -e "\t\trm -r \$(SRC)/binutils-build && \\" >> $MKFILE.tmp
511 echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
512 echo -e "\tfi;" >> $MKFILE.tmp
513 fi
514
[732d1f1]515 # Include a touch of the target name so make can check
516 # if it's already been made.
[0fc4c75]517 echo -e "\t@touch \$@" >> $MKFILE.tmp
[732d1f1]518
[97a3ffc]519 # Keep the script file name for Makefile dependencies.
520 PREV=$i
521 done
522
[8bb92e7]523 # Add a header to the top of the real Makefile
524 echo -e "$HEADER\n" > $MKFILE
525
526 # Add some variables and include the functions file
527 echo "export SRC := /sources" >> $MKFILE
[9e406b5]528 echo "export LFS := $BUILDDIR" >> $MKFILE
[a5e49c6]529 echo -e "export LOGDIR := $LOGDIR\n" >> $MKFILE
[c08d23b]530 echo -e "include functions\n" >> $MKFILE
531
532 # Add chroot commands
533 i=1
534 for file in chapter06/*chroot* ; do
535 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
536 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|$| -c|'`
537 echo -e "export CHROOT$i := $chroot\n" >> $MKFILE
538 i=`expr $i + 1`
539 done
[9e406b5]540
[0bad6ba]541 # Drop in the main target 'all:' and the chapter targets with each sub-target
542 # as a dependency.
[6299c11]543 echo "all: chapter4 chapter5" >> $MKFILE
[4e4a8d5]544 echo -e "\t@echo -e \"\\\n\\\tYour new LFS system has been successfully built\"\n" >> $MKFILE
[0bad6ba]545 echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
[97a3ffc]546 echo -e "chapter5: chapter4 $chapter5\n" >> $MKFILE >> $MKFILE
547 echo -e "chapter6: chapter5 $chapter6\n" >> $MKFILE
[0bad6ba]548
549 # Clean targets
[0209bb7]550 echo "clean-all: clean" >> $MKFILE
[e3e1db0]551 echo -e "\trm -rf ./*\n" >> $MKFILE
[0209bb7]552
553 echo -e "clean: clean-chapter5 clean-chapter4\n" >> $MKFILE
[44f88e3]554
[0bad6ba]555 echo "clean-chapter4:" >> $MKFILE
[0209bb7]556 echo -e "\t-userdel lfs" >> $MKFILE
[e3e1db0]557 echo -e "\trm -rf /home/lfs" >> $MKFILE
558 echo -e "\trm -rf \$(LFS)/tools" >> $MKFILE
559 echo -e "\trm -f /tools" >> $MKFILE
560 echo -e "\trm -f envars" >> $MKFILE
561 echo -e "\trm -f 02* logs/02*.log\n" >> $MKFILE
[44f88e3]562
563 echo "clean-chapter5:" >> $MKFILE
[e3e1db0]564 echo -e "\trm -rf \$(LFS)/tools/*" >> $MKFILE
565 echo -e "\trm -f envars" >> $MKFILE
566 echo -e "\trm -f $chapter5" >> $MKFILE
567 echo -e "\tcd logs && rm -f $chapter5 && cd ..\n" >> $MKFILE
[0bad6ba]568
[732d1f1]569 # The chapter4 sub-targets are hard-coded to create the lfs user,
570 # to make the scripts executable, and to create a clean environment
[44f88e3]571 # for the lfs user.
[0bad6ba]572 echo "020-creatingtoolsdir:" >> $MKFILE
[0fc4c75]573 echo -e "\t@\$(call echo_message, Building)" >> $MKFILE
574 echo -e "\t@mkdir -v \$(LFS)/tools && \\" >> $MKFILE
[a5e49c6]575 echo -e "\tln -sv \$(LFS)/tools / && \\" >> $MKFILE
[0bad6ba]576 echo -e "\ttouch \$@\n" >> $MKFILE
577
[e909d9d]578 echo "021-addinguser: 020-creatingtoolsdir" >> $MKFILE
[0fc4c75]579 echo -e "\t@\$(call echo_message, Building)" >> $MKFILE
580 echo -e "\t@groupadd lfs && \\" >> $MKFILE
[0bad6ba]581 echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
582 echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
583 echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
[732d1f1]584 # Make the scripts executable
[0bad6ba]585 echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
586 echo -e "\ttouch \$@\n" >> $MKFILE
587
[e909d9d]588 echo "022-settingenvironment: 021-addinguser" >> $MKFILE
[0fc4c75]589 echo -e "\t@\$(call echo_message, Building)" >> $MKFILE
590 echo -e "\t@echo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
[0bad6ba]591 echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
592 echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
593 echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
594 echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
595 echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
596 echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
[44f88e3]597 # Source the file where we place changing variables.
598 echo -e "\techo \". $JHALFSDIR/envars\" >> /home/lfs/.bashrc && \\" >> $MKFILE
[88dcce5]599 echo -e "\tchown lfs:lfs /home/lfs/.bash* && \\" >> $MKFILE
[44f88e3]600 echo -e "\ttouch envars && \\" >> $MKFILE
[88dcce5]601 echo -e "\ttouch \$@" >> $MKFILE
[0bad6ba]602
[9e406b5]603 # Bring over the items from the Makefile.tmp
604 cat $MKFILE.tmp >> $MKFILE
605 rm $MKFILE.tmp
606 echo -ne "done\n"
[f8de156]607}
608
[88dcce5]609run_make() {
[d310939]610 # Test if make must be run.
611 if [ "$RUNMAKE" = "1" ] ; then
612 # Build the system
613 if [ -e $MKFILE ] ; then
[e3e1db0]614 echo -ne "Building the LFS system...\n"
[d310939]615 cd $JHALFSDIR && make
616 echo -ne "done\n"
617 fi
[88dcce5]618 fi
619}
[1236262]620
[4dafc45]621if [ ! -d $JHALFSDIR ] ; then
[557fe91]622 mkdir -p $JHALFSDIR
[1236262]623fi
624
[97a3ffc]625if [ ! -d $BUILDDIR$LOGDIR ] ; then
626 mkdir $BUILDDIR$LOGDIR
[a5e49c6]627fi
628
[97a3ffc]629>$BUILDDIR$LOGDIR/$LOG
[409488e]630
631if [ "$PWD" != "$JHALFSDIR" ] ; then
[0fc4c75]632 cp $0 $XSL $FNC $JHALFSDIR/
[409488e]633fi
634
[1236262]635get_book
[f8de156]636build_Makefile
[71642ef]637run_make
Note: See TracBrowser for help on using the repository browser.