1 | #!/bin/sh
|
---|
2 |
|
---|
3 | version="
|
---|
4 | jhalfs development
|
---|
5 |
|
---|
6 | Originally written by Jeremy Huntwork.
|
---|
7 | Maintained by Manuel Canales Esparcia.
|
---|
8 |
|
---|
9 | This program is published under the \
|
---|
10 | Gnu General Public License, Version 2.
|
---|
11 | "
|
---|
12 |
|
---|
13 | usage="\
|
---|
14 | Usage: $0 [OPTION]
|
---|
15 |
|
---|
16 | Options:
|
---|
17 | -h, --help print this help, then exit
|
---|
18 |
|
---|
19 | -V, --version print version number, then exit
|
---|
20 |
|
---|
21 | -d --directory=DIR use DIR directory for building LFS; all files
|
---|
22 | jhalfs produces will be in the directory
|
---|
23 | DIR/jhalfs
|
---|
24 |
|
---|
25 | -P, --get-packages download the packages and patches
|
---|
26 |
|
---|
27 | -D, --download-client=CLIENT use CLIENT as the program for retrieving
|
---|
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 |
|
---|
37 | -M, --run-make run make on the generated Makefile
|
---|
38 | "
|
---|
39 |
|
---|
40 | help="\
|
---|
41 | Try '$0 --help' for more information."
|
---|
42 |
|
---|
43 | exit_missing_arg="\
|
---|
44 | echo \"Option '\$1' requires an argument\" >&2
|
---|
45 | echo \"\$help\" >&2
|
---|
46 | exit 1"
|
---|
47 |
|
---|
48 | no_dl_client="\
|
---|
49 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
50 | echo \"Attempting to continue.\" >&2"
|
---|
51 |
|
---|
52 | while test $# -gt 0 ; do
|
---|
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 |
|
---|
93 | --working-copy | -W )
|
---|
94 | test $# = 1 && eval "$exit_missing_arg"
|
---|
95 | shift
|
---|
96 | WC=1
|
---|
97 | BOOK=$1
|
---|
98 | shift
|
---|
99 | ;;
|
---|
100 |
|
---|
101 | --testsuites | -T )
|
---|
102 | TEST=1
|
---|
103 | shift
|
---|
104 | ;;
|
---|
105 |
|
---|
106 | --get-packages | -P )
|
---|
107 | HPKG=1
|
---|
108 | shift
|
---|
109 | ;;
|
---|
110 |
|
---|
111 | --run-make | -M )
|
---|
112 | RUNMAKE=1
|
---|
113 | shift
|
---|
114 | ;;
|
---|
115 |
|
---|
116 | * )
|
---|
117 | echo "$usage"
|
---|
118 | exit 1
|
---|
119 | ;;
|
---|
120 | esac
|
---|
121 | done
|
---|
122 |
|
---|
123 | # Test to make sure we're running the build as root
|
---|
124 |
|
---|
125 | if [ "$UID" != "0" ] ; then
|
---|
126 | echo "You must be logged in as root to successfully build LFS."
|
---|
127 | exit 1
|
---|
128 | fi
|
---|
129 |
|
---|
130 | # Find the download client to use, if not already specified.
|
---|
131 |
|
---|
132 | if [ -z $DL ] ; then
|
---|
133 | if [ `type -p wget` ] ; then
|
---|
134 | DL=wget
|
---|
135 | elif [ `type -p curl` ] ; then
|
---|
136 | DL=curl
|
---|
137 | else
|
---|
138 | eval "$no_dl_client"
|
---|
139 | fi
|
---|
140 | fi
|
---|
141 |
|
---|
142 | SVN="svn://svn.linuxfromscratch.org"
|
---|
143 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
144 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
145 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
146 | LOGDIR=$JHALFSDIR/logs
|
---|
147 | LOG=000-jhalfs.log
|
---|
148 | MKFILE=$JHALFSDIR/Makefile
|
---|
149 | XSL=dump-lfs-scripts.xsl
|
---|
150 | FNC=functions
|
---|
151 | if [ -z $TEST ] ; then TEST=0 ; fi
|
---|
152 |
|
---|
153 | HEADER="# This file is automatically generated by jhalfs
|
---|
154 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
155 | #
|
---|
156 | # Generated on `date \"+%F %X %Z\"`"
|
---|
157 |
|
---|
158 | get_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.\"
|
---|
161 | exit 1"
|
---|
162 | cd $JHALFSDIR
|
---|
163 |
|
---|
164 | # Test to make sure the LFS version is set
|
---|
165 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
166 |
|
---|
167 | # Set the book's sources directory
|
---|
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
|
---|
186 | else
|
---|
187 | if [ $LFSVRS = development ] ; then
|
---|
188 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
189 | else
|
---|
190 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
191 | fi
|
---|
192 | echo -ne "done\n"
|
---|
193 | extract_commands
|
---|
194 | fi
|
---|
195 | else
|
---|
196 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
197 | extract_commands
|
---|
198 | fi
|
---|
199 | }
|
---|
200 |
|
---|
201 | extract_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.\"
|
---|
204 | exit 1"
|
---|
205 | cd $JHALFSDIR
|
---|
206 |
|
---|
207 | # Start clean
|
---|
208 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
209 | echo -n "Extracting commands... "
|
---|
210 |
|
---|
211 | # Dump the commands in shell script form from the LFS book.
|
---|
212 | xsltproc --nonet --xinclude --stringparam testsuite $TEST -o ./commands/ \
|
---|
213 | $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
214 |
|
---|
215 | # Grab the patches and package names.
|
---|
216 | cd $JHALFSDIR
|
---|
217 | for i in patches packages ; do rm -f $i ; done
|
---|
218 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
219 | -e '/generic/d' >> packages
|
---|
220 | grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
221 |
|
---|
222 | # Done. Moving on...
|
---|
223 | echo -ne "done\n"
|
---|
224 | get_sources
|
---|
225 | }
|
---|
226 |
|
---|
227 | download() {
|
---|
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
|
---|
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
|
---|
249 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
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
|
---|
261 | fi
|
---|
262 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
263 | exit 1
|
---|
264 | fi
|
---|
265 | }
|
---|
266 |
|
---|
267 | get_sources() {
|
---|
268 |
|
---|
269 | # Test if the packages must be downloaded
|
---|
270 | if [ "$HPKG" = "1" ] ; then
|
---|
271 |
|
---|
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 | '
|
---|
277 |
|
---|
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
|
---|
302 | done
|
---|
303 | fi
|
---|
304 | }
|
---|
305 |
|
---|
306 | build_Makefile() {
|
---|
307 | echo -n "Creating Makefile... "
|
---|
308 | cd $JHALFSDIR/commands
|
---|
309 |
|
---|
310 | # Start with a clean Makefile.tmp file
|
---|
311 | >$MKFILE.tmp
|
---|
312 |
|
---|
313 | for file in chapter05/* ; do
|
---|
314 | # Keep the script file name
|
---|
315 | i=`basename $file`
|
---|
316 |
|
---|
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"
|
---|
320 |
|
---|
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\}@@'`
|
---|
324 |
|
---|
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
|
---|
329 | # as a dependency. Also call the echo_message function.
|
---|
330 | echo -e "\n$i: $PREV" >> $MKFILE.tmp
|
---|
331 | echo -e "\t@\$(call echo_message, Building)" >> $MKFILE.tmp
|
---|
332 |
|
---|
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'`
|
---|
336 |
|
---|
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
|
---|
344 |
|
---|
345 | # Insert instructions for unpacking the package and to set
|
---|
346 | # the PKGDIR variable.
|
---|
347 | echo -e "\t@\$(call unpack,$FILE)" >> $MKFILE.tmp
|
---|
348 | echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
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
|
---|
353 |
|
---|
354 | # Dump the path to the Binutils or TCL sources directory.
|
---|
355 | if [ "$i" = "027-binutils-pass1" -o "$i" = "032-tcl" -o "$i" = "036-binutils-pass2" ] ; then
|
---|
356 | echo -e "\techo \"\$(LFS)\$(SRC)/\$\$ROOT\" > sources-dir" >> $MKFILE.tmp
|
---|
357 |
|
---|
358 | # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
359 | elif [ "$i" = "031-adjusting" ] ; then
|
---|
360 | echo -e "\t@echo \"PKGDIR=\$(LFS)\$(SRC)/binutils-build\" > envars && \\" >> $MKFILE.tmp
|
---|
361 | echo -e "\techo \"export PKGDIR\" >> envars" >> $MKFILE.tmp
|
---|
362 |
|
---|
363 | # For the Expect build we need to set the TCLPATH envar.
|
---|
364 | elif [ "$i" = "033-expect" ] ; then
|
---|
365 | echo -e "\techo \"TCLPATH=\`cat sources-dir\`\" >> envars && \\" >> $MKFILE.tmp
|
---|
366 | echo -e "\techo \"export TCLPATH\" >> envars" >> $MKFILE.tmp
|
---|
367 |
|
---|
368 | # Everything else, add a true statment so we don't confuse make
|
---|
369 | else
|
---|
370 | echo -e "\ttrue" >> $MKFILE.tmp
|
---|
371 | fi
|
---|
372 |
|
---|
373 | # Insert date and disk usage at the top of the log file.
|
---|
374 | echo -e "\t@echo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >logs/$i && \\" >> $MKFILE.tmp
|
---|
375 |
|
---|
376 | # Insert the script run
|
---|
377 | echo -e "\tsu - lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" >>logs/$i 2>&1 && \\" >> $MKFILE.tmp
|
---|
378 |
|
---|
379 | # Insert date and disk usage at the bottom of the log file.
|
---|
380 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >>logs/$i" >> $MKFILE.tmp
|
---|
381 |
|
---|
382 | # Remove the build directory(ies) even if the package build fails, except for
|
---|
383 | # Binutils and TCL. In that cases the sources directories are removed
|
---|
384 | # only if the build fails.
|
---|
385 | if [ "$vrs" != "" ] ; then
|
---|
386 | if [ "$i" != "027-binutils-pass1" ] && [ "$i" != "032-tcl" ] && [ "$i" != "036-binutils-pass2" ] ; then
|
---|
387 | echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
388 | echo -e "\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
389 | echo -e "\tif [ -e \$(LFS)\$(SRC)/$name-build ]; then \\" >> $MKFILE.tmp
|
---|
390 | echo -e "\t\trm -r \$(LFS)\$(SRC)/$name-build; \\" >> $MKFILE.tmp
|
---|
391 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
392 | fi
|
---|
393 | fi
|
---|
394 |
|
---|
395 | # Remove the Binutils pass 1 sources after a successful Adjusting phase.
|
---|
396 | if [ "$i" = "031-adjusting" ] ; then
|
---|
397 | echo -e "\t@rm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
|
---|
398 | echo -e "\trm -r \$(LFS)\$(SRC)/binutils-build && \\" >> $MKFILE.tmp
|
---|
399 | echo -e "\trm sources-dir" >> $MKFILE.tmp
|
---|
400 | fi
|
---|
401 |
|
---|
402 | # Remove the TCL sources after a successful Expect build.
|
---|
403 | if [ "$i" = "033-expect" ] ; then
|
---|
404 | echo -e "\t@rm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
|
---|
405 | echo -e "\trm sources-dir" >> $MKFILE.tmp
|
---|
406 | fi
|
---|
407 |
|
---|
408 | # Include a touch of the target name so make can check
|
---|
409 | # if it's already been made.
|
---|
410 | echo -e "\t@touch \$@" >> $MKFILE.tmp
|
---|
411 |
|
---|
412 | # The next two "if" must be after the touch to can check if the sources
|
---|
413 | # directories should be retained or deleted.
|
---|
414 | if [ "$i" = "027-binutils-pass1" -o "$i" = "036-binutils-pass2" ] ; then
|
---|
415 | echo -e "\t@if [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
416 | echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
417 | echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
418 | echo -e "\t\trm -r \$(LFS)\$(SRC)/binutils-build; \\" >> $MKFILE.tmp
|
---|
419 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
420 | fi
|
---|
421 | if [ "$i" = "032-tcl" ] ; then
|
---|
422 | echo -e "\t@if [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
423 | echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
424 | echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT; \\" >> $MKFILE.tmp
|
---|
425 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
426 | fi
|
---|
427 |
|
---|
428 | # Keep the script file name for Makefile dependencies.
|
---|
429 | PREV=$i
|
---|
430 | done
|
---|
431 |
|
---|
432 | for file in chapter06/* ; do
|
---|
433 | # Keep the script file name
|
---|
434 | i=`basename $file`
|
---|
435 |
|
---|
436 | # First append each name of the script files to a list (this will become
|
---|
437 | # the names of the targets in the Makefile
|
---|
438 | chapter6="$chapter6 $i"
|
---|
439 |
|
---|
440 | # Grab the name of the target
|
---|
441 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
|
---|
442 |
|
---|
443 | # Set the dependency for the first target.
|
---|
444 | if [ -z $PREV ] ; then PREV=055-stripping ; fi
|
---|
445 |
|
---|
446 | # Drop in the name of the target on a new line, and the previous target
|
---|
447 | # as a dependency. Also call the echo_message function.
|
---|
448 | if echo $i | grep -q "chroot" ; then
|
---|
449 | continue
|
---|
450 | else
|
---|
451 | echo -e "\n$i: $PREV" >> $MKFILE.tmp
|
---|
452 | echo -e "\t@\$(call echo_message, Building)" >> $MKFILE.tmp
|
---|
453 | fi
|
---|
454 |
|
---|
455 | # Find the version of the command files, if it corresponds with the building of
|
---|
456 | # a specific package
|
---|
457 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
458 |
|
---|
459 | # If $vrs isn't empty, we've got a package...
|
---|
460 | if [ "$vrs" != "" ] ; then
|
---|
461 | FILE="$name-$vrs.tar.bz2"
|
---|
462 |
|
---|
463 | # Insert instructions for unpacking the package and changing directories
|
---|
464 | echo -e "\t@\$(call unpack,$FILE)" >> $MKFILE.tmp
|
---|
465 | echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
466 | echo -e "\techo \"PKGDIR=\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
|
---|
467 | echo -e "\techo \"export PKGDIR\" >> envars\\" >> $MKFILE.tmp
|
---|
468 | fi
|
---|
469 |
|
---|
470 | # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
471 | if [ "$i" = "067-readjusting" ] ; then
|
---|
472 | echo -e "\t@echo \"PKGDIR=\$(SRC)/binutils-build\" > envars && \\" >> $MKFILE.tmp
|
---|
473 | echo -e "\techo \"export PKGDIR\" >> envars" >> $MKFILE.tmp
|
---|
474 | fi
|
---|
475 |
|
---|
476 | # For the mount of kernel filesystems we need to set LFS and not to use
|
---|
477 | # chroot.
|
---|
478 | if [ "$i" = "057-kernfs" ] ; then
|
---|
479 | echo -e "\t@echo \"LFS=\$(LFS)\" > envars && \\" >> $MKFILE.tmp
|
---|
480 | echo -e "\techo \"export LFS\" >> envars && \\" >> $MKFILE.tmp
|
---|
481 | # Insert date and disk usage at the top of the log file.
|
---|
482 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >logs/$i && \\" >> $MKFILE.tmp
|
---|
483 | # Insert the script run
|
---|
484 | echo -e "\t. envars && commands/$file >>logs/$i 2>&1 && \\" >> $MKFILE.tmp
|
---|
485 | # Insert date and disk usage at the bottom of the log file.
|
---|
486 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >>logs/$i" >> $MKFILE.tmp
|
---|
487 | # The rest of Chapter06 use CHROOT1 function
|
---|
488 | else
|
---|
489 | # Insert date and disk usage at the top of the log file.
|
---|
490 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -skx --exclude=0??-* \$(LFS)\`\\\n\" >logs/$i && \\" >> $MKFILE.tmp
|
---|
491 | # Insert the script run
|
---|
492 | echo -e "\t\$(CHROOT1) 'cd /jhalfs && . envars && commands/$file >>logs/$i 2>&1' && \\" >> $MKFILE.tmp
|
---|
493 | # Insert date and disk usage at the bottom of the log file.
|
---|
494 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -skx --exclude=0??-* \$(LFS)\`\\\n\" >>logs/$i" >> $MKFILE.tmp
|
---|
495 | fi
|
---|
496 |
|
---|
497 | # Remove the build directory(ies) even if the package build fails.
|
---|
498 | if [ "$vrs" != "" ] ; then
|
---|
499 | echo -e "\t@ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
500 | echo -e "\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
501 | echo -e "\tif [ -e \$(LFS)\$(SRC)/$name-build ]; then \\" >> $MKFILE.tmp
|
---|
502 | echo -e "\t\trm -r \$(LFS)\$(SRC)/$name-build; \\" >> $MKFILE.tmp
|
---|
503 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
504 | fi
|
---|
505 |
|
---|
506 | # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
|
---|
507 | if [ "$i" = "067-readjusting" ] ; then
|
---|
508 | echo -e "\t@rm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
|
---|
509 | echo -e "\trm -r \$(LFS)\$(SRC)/binutils-build && \\" >> $MKFILE.tmp
|
---|
510 | echo -e "\trm sources-dir" >> $MKFILE.tmp
|
---|
511 | fi
|
---|
512 |
|
---|
513 | # Include a touch of the target name so make can check
|
---|
514 | # if it's already been made.
|
---|
515 | echo -e "\t@touch \$@" >> $MKFILE.tmp
|
---|
516 |
|
---|
517 | # Keep the script file name for Makefile dependencies.
|
---|
518 | PREV=$i
|
---|
519 | done
|
---|
520 |
|
---|
521 | # Add a header to the top of the real Makefile
|
---|
522 | echo -e "$HEADER\n" > $MKFILE
|
---|
523 |
|
---|
524 | # Add some variables and include the functions file
|
---|
525 | echo "SRC= /sources" >> $MKFILE
|
---|
526 | echo -e "LFS= $BUILDDIR\n" >> $MKFILE
|
---|
527 | echo -e "include functions\n" >> $MKFILE
|
---|
528 |
|
---|
529 | # Add chroot commands
|
---|
530 | i=1
|
---|
531 | for file in chapter06/*chroot* ; do
|
---|
532 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
|
---|
533 | -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|$| -c|'`
|
---|
534 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
535 | i=`expr $i + 1`
|
---|
536 | done
|
---|
537 |
|
---|
538 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
539 | # as a dependency.
|
---|
540 | echo "all: chapter4 chapter5" >> $MKFILE
|
---|
541 | echo -e "\t@echo -e \"\\\n\\\tYour new LFS system has been successfully built\"\n" >> $MKFILE
|
---|
542 | echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
|
---|
543 | echo -e "chapter5: chapter4 $chapter5\n" >> $MKFILE
|
---|
544 | echo -e "chapter6: chapter5 $chapter6\n" >> $MKFILE
|
---|
545 |
|
---|
546 | # Clean targets
|
---|
547 | echo "clean-all: clean" >> $MKFILE
|
---|
548 | echo -e "\trm -rf ./*\n" >> $MKFILE
|
---|
549 |
|
---|
550 | echo -e "clean: clean-chapter5 clean-chapter4\n" >> $MKFILE
|
---|
551 |
|
---|
552 | echo "clean-chapter4:" >> $MKFILE
|
---|
553 | echo -e "\t-userdel lfs" >> $MKFILE
|
---|
554 | echo -e "\trm -rf /home/lfs" >> $MKFILE
|
---|
555 | echo -e "\trm -rf \$(LFS)/tools" >> $MKFILE
|
---|
556 | echo -e "\trm -f /tools" >> $MKFILE
|
---|
557 | echo -e "\trm -f envars" >> $MKFILE
|
---|
558 | echo -e "\trm -f 02* logs/02*.log\n" >> $MKFILE
|
---|
559 |
|
---|
560 | echo "clean-chapter5:" >> $MKFILE
|
---|
561 | echo -e "\trm -rf \$(LFS)/tools/*" >> $MKFILE
|
---|
562 | echo -e "\trm -f envars" >> $MKFILE
|
---|
563 | echo -e "\trm -f $chapter5" >> $MKFILE
|
---|
564 | echo -e "\tcd logs && rm -f $chapter5 && cd ..\n" >> $MKFILE
|
---|
565 |
|
---|
566 | # The chapter4 sub-targets are hard-coded to create the lfs user,
|
---|
567 | # to make the scripts executable, and to create a clean environment
|
---|
568 | # for the lfs user.
|
---|
569 | echo "020-creatingtoolsdir:" >> $MKFILE
|
---|
570 | echo -e "\t@\$(call echo_message, Building)" >> $MKFILE
|
---|
571 | echo -e "\t@mkdir -v \$(LFS)/tools && \\" >> $MKFILE
|
---|
572 | echo -e "\tln -sv \$(LFS)/tools / && \\" >> $MKFILE
|
---|
573 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
574 |
|
---|
575 | echo "021-addinguser: 020-creatingtoolsdir" >> $MKFILE
|
---|
576 | echo -e "\t@\$(call echo_message, Building)" >> $MKFILE
|
---|
577 | echo -e "\t@groupadd lfs && \\" >> $MKFILE
|
---|
578 | echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
|
---|
579 | echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
|
---|
580 | echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
|
---|
581 | # Make the scripts executable
|
---|
582 | echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
|
---|
583 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
584 |
|
---|
585 | echo "022-settingenvironment: 021-addinguser" >> $MKFILE
|
---|
586 | echo -e "\t@\$(call echo_message, Building)" >> $MKFILE
|
---|
587 | echo -e "\t@echo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
|
---|
588 | echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
589 | echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
590 | echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
591 | echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
592 | echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
593 | echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
594 | # Source the file where we place changing variables.
|
---|
595 | echo -e "\techo \". $JHALFSDIR/envars\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
596 | echo -e "\tchown lfs:lfs /home/lfs/.bash* && \\" >> $MKFILE
|
---|
597 | echo -e "\ttouch envars && \\" >> $MKFILE
|
---|
598 | echo -e "\ttouch \$@" >> $MKFILE
|
---|
599 |
|
---|
600 | # Bring over the items from the Makefile.tmp
|
---|
601 | cat $MKFILE.tmp >> $MKFILE
|
---|
602 | rm $MKFILE.tmp
|
---|
603 | echo -ne "done\n"
|
---|
604 | }
|
---|
605 |
|
---|
606 | run_make() {
|
---|
607 | # Test if make must be run.
|
---|
608 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
609 | # Build the system
|
---|
610 | if [ -e $MKFILE ] ; then
|
---|
611 | echo -ne "Building the LFS system...\n"
|
---|
612 | cd $JHALFSDIR && make
|
---|
613 | echo -ne "done\n"
|
---|
614 | fi
|
---|
615 | fi
|
---|
616 | }
|
---|
617 |
|
---|
618 | if [ ! -d $JHALFSDIR ] ; then
|
---|
619 | mkdir -p $JHALFSDIR
|
---|
620 | fi
|
---|
621 |
|
---|
622 | if [ ! -d $LOGDIR ] ; then
|
---|
623 | mkdir $LOGDIR
|
---|
624 | fi
|
---|
625 |
|
---|
626 | >$LOGDIR/$LOG
|
---|
627 |
|
---|
628 | if [ "$PWD" != "$JHALFSDIR" ] ; then
|
---|
629 | cp $0 $XSL $FNC $JHALFSDIR/
|
---|
630 | fi
|
---|
631 |
|
---|
632 | get_book
|
---|
633 | build_Makefile
|
---|
634 | run_make
|
---|