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. Default is \"/mnt/lfs\".
|
---|
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 | --no-toolchain-test don't run the toolchain testsuites. This
|
---|
38 | disables also the build of TCL, Expect
|
---|
39 | and DejaGNU
|
---|
40 |
|
---|
41 | -M, --run-make run make on the generated Makefile
|
---|
42 |
|
---|
43 | --page_size PAGE set PAGE as the default page size (letter,
|
---|
44 | A4, or others). This setting is required to
|
---|
45 | build Groff. If not specified, \"letter\"
|
---|
46 | will be used.
|
---|
47 | "
|
---|
48 |
|
---|
49 | help="\
|
---|
50 | Try '$0 --help' for more information."
|
---|
51 |
|
---|
52 | exit_missing_arg="\
|
---|
53 | echo \"Option '\$1' requires an argument\" >&2
|
---|
54 | echo \"\$help\" >&2
|
---|
55 | exit 1"
|
---|
56 |
|
---|
57 | no_dl_client="\
|
---|
58 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
59 | echo \"Attempting to continue.\" >&2"
|
---|
60 |
|
---|
61 | while test $# -gt 0 ; do
|
---|
62 | case $1 in
|
---|
63 | --version | -V )
|
---|
64 | echo "$version"
|
---|
65 | exit 0
|
---|
66 | ;;
|
---|
67 |
|
---|
68 | --help | -h )
|
---|
69 | echo "$usage"
|
---|
70 | exit 0
|
---|
71 | ;;
|
---|
72 |
|
---|
73 | --LFS-version | -L )
|
---|
74 | test $# = 1 && eval "$exit_missing_arg"
|
---|
75 | shift
|
---|
76 | case $1 in
|
---|
77 | dev* | SVN | trunk )
|
---|
78 | LFSVRS=development
|
---|
79 | ;;
|
---|
80 | * )
|
---|
81 | echo "$1 is an unsupported version at this time."
|
---|
82 | exit 1
|
---|
83 | ;;
|
---|
84 | esac
|
---|
85 | shift
|
---|
86 | ;;
|
---|
87 |
|
---|
88 | --directory | -d )
|
---|
89 | test $# = 1 && eval "$exit_missing_arg"
|
---|
90 | shift
|
---|
91 | BUILDDIR=$1
|
---|
92 | shift
|
---|
93 | ;;
|
---|
94 |
|
---|
95 | --download-client | -D )
|
---|
96 | test $# = 1 && eval "$exit_missing_arg"
|
---|
97 | shift
|
---|
98 | DL=$1
|
---|
99 | shift
|
---|
100 | ;;
|
---|
101 |
|
---|
102 | --working-copy | -W )
|
---|
103 | test $# = 1 && eval "$exit_missing_arg"
|
---|
104 | shift
|
---|
105 | WC=1
|
---|
106 | BOOK=$1
|
---|
107 | shift
|
---|
108 | ;;
|
---|
109 |
|
---|
110 | --testsuites | -T )
|
---|
111 | TEST=1
|
---|
112 | shift
|
---|
113 | ;;
|
---|
114 |
|
---|
115 | --get-packages | -P )
|
---|
116 | HPKG=1
|
---|
117 | shift
|
---|
118 | ;;
|
---|
119 |
|
---|
120 | --run-make | -M )
|
---|
121 | RUNMAKE=1
|
---|
122 | shift
|
---|
123 | ;;
|
---|
124 |
|
---|
125 | --page_size )
|
---|
126 | test $# = 1 && eval "$exit_missing_arg"
|
---|
127 | shift
|
---|
128 | PAGE=$1
|
---|
129 | shift
|
---|
130 | ;;
|
---|
131 |
|
---|
132 | --no-toolchain-test )
|
---|
133 | TOOLCHAINTEST=0
|
---|
134 | shift
|
---|
135 | ;;
|
---|
136 |
|
---|
137 | * )
|
---|
138 | echo "$usage"
|
---|
139 | exit 1
|
---|
140 | ;;
|
---|
141 | esac
|
---|
142 | done
|
---|
143 |
|
---|
144 | # Test to make sure we're running the build as root
|
---|
145 |
|
---|
146 | if [ "$UID" != "0" ] ; then
|
---|
147 | echo "You must be logged in as root to successfully build LFS."
|
---|
148 | exit 1
|
---|
149 | fi
|
---|
150 |
|
---|
151 | # Find the download client to use, if not already specified.
|
---|
152 |
|
---|
153 | if [ -z $DL ] ; then
|
---|
154 | if [ `type -p wget` ] ; then
|
---|
155 | DL=wget
|
---|
156 | elif [ `type -p curl` ] ; then
|
---|
157 | DL=curl
|
---|
158 | else
|
---|
159 | eval "$no_dl_client"
|
---|
160 | fi
|
---|
161 | fi
|
---|
162 |
|
---|
163 | SVN="svn://svn.linuxfromscratch.org"
|
---|
164 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
165 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
166 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
167 | LOGDIR=$JHALFSDIR/logs
|
---|
168 | LOG=000-jhalfs.log
|
---|
169 | MKFILE=$JHALFSDIR/Makefile
|
---|
170 | XSL=dump-lfs-scripts.xsl
|
---|
171 | FNC=functions
|
---|
172 | if [ -z $TEST ] ; then TEST=0 ; fi
|
---|
173 | if [ -z $TOOLCHAINTEST ] ; then TOOLCHAINTEST=1 ; fi
|
---|
174 | if [ -z $PAGE ] ; then PAGE=letter ; fi
|
---|
175 |
|
---|
176 | HEADER="# This file is automatically generated by jhalfs
|
---|
177 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
178 | #
|
---|
179 | # Generated on `date \"+%F %X %Z\"`"
|
---|
180 |
|
---|
181 | get_book() {
|
---|
182 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
183 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
184 | exit 1"
|
---|
185 | cd $JHALFSDIR
|
---|
186 |
|
---|
187 | # Test to make sure the LFS version is set
|
---|
188 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
189 |
|
---|
190 | # Set the book's sources directory
|
---|
191 | if [ -z $BOOK ] ; then BOOK=lfs-$LFSVRS ; fi
|
---|
192 |
|
---|
193 | if [ -z $WC ] ; then
|
---|
194 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
195 |
|
---|
196 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
197 | # repo. If we've already extracted the commands, move on to getting the
|
---|
198 | # sources.
|
---|
199 | if [ -d lfs-$LFSVRS ] ; then
|
---|
200 | cd lfs-$LFSVRS
|
---|
201 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
202 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
203 | echo -ne "done\n"
|
---|
204 | get_sources
|
---|
205 | else
|
---|
206 | echo -ne "done\n"
|
---|
207 | extract_commands
|
---|
208 | fi
|
---|
209 | else
|
---|
210 | if [ $LFSVRS = development ] ; then
|
---|
211 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
212 | else
|
---|
213 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
214 | fi
|
---|
215 | echo -ne "done\n"
|
---|
216 | extract_commands
|
---|
217 | fi
|
---|
218 | else
|
---|
219 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
220 | extract_commands
|
---|
221 | fi
|
---|
222 | }
|
---|
223 |
|
---|
224 | extract_commands() {
|
---|
225 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
226 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
227 | exit 1"
|
---|
228 | cd $JHALFSDIR
|
---|
229 |
|
---|
230 | # Start clean
|
---|
231 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
232 | echo -n "Extracting commands... "
|
---|
233 |
|
---|
234 | # Dump the commands in shell script form from the LFS book.
|
---|
235 | xsltproc --nonet --xinclude --stringparam testsuite $TEST \
|
---|
236 | --stringparam toolchaintest $TOOLCHAINTEST -o ./commands/ \
|
---|
237 | $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
238 |
|
---|
239 | # Make the scripts executable.
|
---|
240 | chmod -R +x $JHALFSDIR/commands
|
---|
241 |
|
---|
242 | # Grab the patches and package names.
|
---|
243 | cd $JHALFSDIR
|
---|
244 | for i in patches packages ; do rm -f $i ; done
|
---|
245 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
246 | -e '/generic/d' >> packages
|
---|
247 | echo `grep "glibc" packages | sed 's@glibc@glibc-linuxthreads@'` >> packages
|
---|
248 | grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
249 |
|
---|
250 | # Done. Moving on...
|
---|
251 | echo -ne "done\n"
|
---|
252 | get_sources
|
---|
253 | }
|
---|
254 |
|
---|
255 | download() {
|
---|
256 | cd $BUILDDIR/sources
|
---|
257 |
|
---|
258 | # Hackish fix for the bash-doc and glibc-linuxthreads packages that
|
---|
259 | # doesn't conform to norms in the URL scheme.
|
---|
260 | DIR=`echo $1 | sed -e 's@-doc@@' -e 's@-linuxthreads@@'`
|
---|
261 |
|
---|
262 | # Find the md5 sum for this package.
|
---|
263 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
264 |
|
---|
265 | if [ ! -f $2 ] ; then
|
---|
266 | case $DL in
|
---|
267 | wget )
|
---|
268 | wget $HTTP/$DIR/$2
|
---|
269 | ;;
|
---|
270 | curl )
|
---|
271 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
272 | ;;
|
---|
273 | * )
|
---|
274 | echo "$DL not supported at this time."
|
---|
275 | ;;
|
---|
276 | esac
|
---|
277 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
278 | case $DL in
|
---|
279 | wget )
|
---|
280 | wget -c $HTTP/$DIR/$2
|
---|
281 | ;;
|
---|
282 | curl )
|
---|
283 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
284 | ;;
|
---|
285 | * )
|
---|
286 | echo "$DL not supported at this time."
|
---|
287 | ;;
|
---|
288 | esac
|
---|
289 | fi
|
---|
290 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
291 | exit 1
|
---|
292 | fi
|
---|
293 | }
|
---|
294 |
|
---|
295 | get_sources() {
|
---|
296 |
|
---|
297 | # Test if the packages must be downloaded
|
---|
298 | if [ "$HPKG" = "1" ] ; then
|
---|
299 |
|
---|
300 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
301 | # separates each iteration by lines. It is necessary to have the second
|
---|
302 | # ' on the next line.
|
---|
303 | IFS='
|
---|
304 | '
|
---|
305 |
|
---|
306 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
307 | cd $BUILDDIR/sources
|
---|
308 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
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
|
---|
314 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
315 |
|
---|
316 | # Someone used some silly entities right next to the valid package entities.
|
---|
317 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
318 |
|
---|
319 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
320 | if [ "$PKG" = "tcl" ] ; then
|
---|
321 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
322 | else
|
---|
323 | FILE="$PKG-$VRS.tar.bz2"
|
---|
324 | fi
|
---|
325 | download $PKG $FILE
|
---|
326 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
327 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
328 | download $PKG $PATCH
|
---|
329 | done
|
---|
330 | done
|
---|
331 | # Hardcoded Udev configuration file until find a better way
|
---|
332 | download udev udev-config-3.rules
|
---|
333 | fi
|
---|
334 | }
|
---|
335 |
|
---|
336 | build_Makefile() {
|
---|
337 | echo -n "Creating Makefile... "
|
---|
338 | cd $JHALFSDIR/commands
|
---|
339 |
|
---|
340 | # Start with a clean Makefile.tmp file
|
---|
341 | >$MKFILE.tmp
|
---|
342 |
|
---|
343 | for file in chapter05/* ; do
|
---|
344 | # Keep the script file name
|
---|
345 | i=`basename $file`
|
---|
346 |
|
---|
347 | # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
|
---|
348 | if [ "$TOOLCHAINTEST" = "0" ]; then
|
---|
349 | if echo $i | grep -q "tcl" ; then
|
---|
350 | continue
|
---|
351 | elif echo $i | grep -q "expect" ; then
|
---|
352 | continue
|
---|
353 | elif echo $i | grep -q "dejagnu" ; then
|
---|
354 | continue
|
---|
355 | fi
|
---|
356 | fi
|
---|
357 |
|
---|
358 | # First append each name of the script files to a list (this will become
|
---|
359 | # the names of the targets in the Makefile
|
---|
360 | chapter5="$chapter5 $i"
|
---|
361 |
|
---|
362 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
363 | # and binutils in chapter 5)
|
---|
364 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
365 |
|
---|
366 | # Set the dependency for the first target.
|
---|
367 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
368 |
|
---|
369 | # Drop in the name of the target on a new line, and the previous target
|
---|
370 | # as a dependency. Also call the echo_message function.
|
---|
371 | (
|
---|
372 | cat << EOF
|
---|
373 |
|
---|
374 | $i: $PREV
|
---|
375 | @\$(call echo_message, Building)
|
---|
376 | EOF
|
---|
377 | ) >> $MKFILE.tmp
|
---|
378 |
|
---|
379 | # Find the version of the command files, if it corresponds with the building of
|
---|
380 | # a specific package
|
---|
381 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
382 |
|
---|
383 | # If $vrs isn't empty, we've got a package...
|
---|
384 | if [ "$vrs" != "" ] ; then
|
---|
385 | if [ "$name" = "tcl" ] ; then
|
---|
386 | FILE="$name$vrs-src.tar.bz2"
|
---|
387 | else
|
---|
388 | FILE="$name-$vrs.tar.bz2"
|
---|
389 | fi
|
---|
390 |
|
---|
391 | # Insert instructions for unpacking the package and to set
|
---|
392 | # the PKGDIR variable.
|
---|
393 | (
|
---|
394 | cat << EOF
|
---|
395 | @\$(call unpack,$FILE)
|
---|
396 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
397 | chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
398 | echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
|
---|
399 | echo "export PKGDIR" >> envars && \\
|
---|
400 | EOF
|
---|
401 | ) >> $MKFILE.tmp
|
---|
402 |
|
---|
403 | fi
|
---|
404 |
|
---|
405 | # Dump the path to the Binutils or TCL sources directory.
|
---|
406 | if [ "$i" = "027-binutils-pass1" -o "$i" = "032-tcl" -o "$i" = "036-binutils-pass2" ] ; then
|
---|
407 | (
|
---|
408 | cat << EOF
|
---|
409 | echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
|
---|
410 | EOF
|
---|
411 | ) >> $MKFILE.tmp
|
---|
412 |
|
---|
413 | # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
414 | elif [ "$i" = "031-adjusting" ] ; then
|
---|
415 | (
|
---|
416 | cat << EOF
|
---|
417 | @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
|
---|
418 | echo "export PKGDIR" >> envars
|
---|
419 | EOF
|
---|
420 | ) >> $MKFILE.tmp
|
---|
421 |
|
---|
422 | # For the Expect build we need to set the TCLPATH envar.
|
---|
423 | elif [ "$i" = "033-expect" ] ; then
|
---|
424 | (
|
---|
425 | cat << EOF
|
---|
426 | echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
|
---|
427 | echo "export TCLPATH" >> envars
|
---|
428 | EOF
|
---|
429 | ) >> $MKFILE.tmp
|
---|
430 |
|
---|
431 | # Everything else, add a true statment so we don't confuse make
|
---|
432 | else
|
---|
433 | (
|
---|
434 | cat << EOF
|
---|
435 | true
|
---|
436 | EOF
|
---|
437 | ) >> $MKFILE.tmp
|
---|
438 | fi
|
---|
439 |
|
---|
440 | # Insert date and disk usage at the top of the log file, the script run
|
---|
441 | # and date and disk usage again at the bottom of the log file.
|
---|
442 | (
|
---|
443 | cat << EOF
|
---|
444 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
445 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
|
---|
446 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >>logs/$i
|
---|
447 | EOF
|
---|
448 | ) >> $MKFILE.tmp
|
---|
449 |
|
---|
450 | # Remove the build directory(ies) even if the package build fails, except for
|
---|
451 | # Binutils and TCL. In that cases the sources directories are removed
|
---|
452 | # only if the build fails.
|
---|
453 | if [ "$vrs" != "" ] ; then
|
---|
454 | if [ "$i" != "027-binutils-pass1" ] && [ "$i" != "032-tcl" ] && [ "$i" != "036-binutils-pass2" ] ; then
|
---|
455 | (
|
---|
456 | cat << EOF
|
---|
457 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
458 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
459 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
460 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
461 | fi;
|
---|
462 | EOF
|
---|
463 | ) >> $MKFILE.tmp
|
---|
464 | fi
|
---|
465 | fi
|
---|
466 |
|
---|
467 | # Remove the Binutils pass 1 sources after a successful Adjusting phase.
|
---|
468 | if [ "$i" = "031-adjusting" ] ; then
|
---|
469 | (
|
---|
470 | cat << EOF
|
---|
471 | @rm -r \`cat sources-dir\` && \\
|
---|
472 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
473 | rm sources-dir
|
---|
474 | EOF
|
---|
475 | ) >> $MKFILE.tmp
|
---|
476 | fi
|
---|
477 |
|
---|
478 | # Remove the TCL sources after a successful Expect build.
|
---|
479 | if [ "$i" = "033-expect" ] ; then
|
---|
480 | (
|
---|
481 | cat << EOF
|
---|
482 | @rm -r \`cat sources-dir\` && \\
|
---|
483 | rm sources-dir
|
---|
484 | EOF
|
---|
485 | ) >> $MKFILE.tmp
|
---|
486 | fi
|
---|
487 |
|
---|
488 | # Include a touch of the target name so make can check
|
---|
489 | # if it's already been made.
|
---|
490 | (
|
---|
491 | cat << EOF
|
---|
492 | @touch \$@
|
---|
493 | EOF
|
---|
494 | ) >> $MKFILE.tmp
|
---|
495 |
|
---|
496 | # The next two "if" must be after the touch to can check if the sources
|
---|
497 | # directories should be retained or deleted.
|
---|
498 | if [ "$i" = "027-binutils-pass1" -o "$i" = "036-binutils-pass2" ] ; then
|
---|
499 | (
|
---|
500 | cat << EOF
|
---|
501 | @if [ ! -e \$@ ] ; then \\
|
---|
502 | ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
503 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
504 | rm -r \$(LFS)\$(SRC)/binutils-build; \\
|
---|
505 | fi;
|
---|
506 | EOF
|
---|
507 | ) >> $MKFILE.tmp
|
---|
508 | fi
|
---|
509 |
|
---|
510 | if [ "$i" = "032-tcl" ] ; then
|
---|
511 | (
|
---|
512 | cat << EOF
|
---|
513 | @if [ ! -e \$@ ] ; then \\
|
---|
514 | ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
515 | rm -r \$(LFS)\$(SRC)/\$\$ROOT; \\
|
---|
516 | fi;
|
---|
517 | EOF
|
---|
518 | ) >> $MKFILE.tmp
|
---|
519 | fi
|
---|
520 |
|
---|
521 | # Keep the script file name for Makefile dependencies.
|
---|
522 | PREV=$i
|
---|
523 | done
|
---|
524 |
|
---|
525 | for file in chapter06/* ; do
|
---|
526 | # Keep the script file name
|
---|
527 | i=`basename $file`
|
---|
528 |
|
---|
529 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
530 | # dependencies and target creation.
|
---|
531 | if echo $i | grep -q "chroot" ; then
|
---|
532 | continue
|
---|
533 | fi
|
---|
534 |
|
---|
535 | # First append each name of the script files to a list (this will become
|
---|
536 | # the names of the targets in the Makefile
|
---|
537 | chapter6="$chapter6 $i"
|
---|
538 |
|
---|
539 | # Grab the name of the target
|
---|
540 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
|
---|
541 |
|
---|
542 | # Set the dependency for the first target.
|
---|
543 | if [ -z $PREV ] ; then PREV=055-stripping ; fi
|
---|
544 |
|
---|
545 | # Drop in the name of the target on a new line, and the previous target
|
---|
546 | # as a dependency. Also call the echo_message function.
|
---|
547 | (
|
---|
548 | cat << EOF
|
---|
549 |
|
---|
550 | $i: $PREV
|
---|
551 | @\$(call echo_message, Building)
|
---|
552 | EOF
|
---|
553 | ) >> $MKFILE.tmp
|
---|
554 |
|
---|
555 | # Find the version of the command files, if it corresponds with the building of
|
---|
556 | # a specific package
|
---|
557 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
558 |
|
---|
559 | # If $vrs isn't empty, we've got a package...
|
---|
560 | # Insert instructions for unpacking the package and changing directories
|
---|
561 | if [ "$vrs" != "" ] ; then
|
---|
562 | FILE="$name-$vrs.tar.bz2"
|
---|
563 | (
|
---|
564 | cat << EOF
|
---|
565 | @\$(call unpack,$FILE)
|
---|
566 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
567 | echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
|
---|
568 | echo "export PKGDIR" >> envars
|
---|
569 | EOF
|
---|
570 | ) >> $MKFILE.tmp
|
---|
571 | fi
|
---|
572 |
|
---|
573 | # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
574 | if [ "$i" = "067-readjusting" ] ; then
|
---|
575 | (
|
---|
576 | cat << EOF
|
---|
577 | @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
|
---|
578 | echo "export PKGDIR" >> envars
|
---|
579 | EOF
|
---|
580 | ) >> $MKFILE.tmp
|
---|
581 | fi
|
---|
582 |
|
---|
583 | # For Groff we need to set PAGE envar.
|
---|
584 | if [ "$i" = "082-groff" ] ; then
|
---|
585 | (
|
---|
586 | cat << EOF
|
---|
587 | @echo "PAGE=\$(PAGE)" >> envars && \\
|
---|
588 | echo "export PAGE" >> envars
|
---|
589 | EOF
|
---|
590 | ) >> $MKFILE.tmp
|
---|
591 | fi
|
---|
592 |
|
---|
593 | # In the mount of kernel filesystems we need to set LFS for CHROOT1
|
---|
594 | # and not to use chroot.
|
---|
595 | if [ "$i" = "057-kernfs" ] ; then
|
---|
596 | (
|
---|
597 | cat << EOF
|
---|
598 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
599 | commands/$file >>logs/$i 2>&1 && \\
|
---|
600 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\n" >>logs/$i
|
---|
601 | EOF
|
---|
602 | ) >> $MKFILE.tmp
|
---|
603 |
|
---|
604 | # The rest of Chapter06
|
---|
605 | else
|
---|
606 | (
|
---|
607 | cat << EOF
|
---|
608 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=0??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
609 | \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
|
---|
610 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude=0??-* \$(LFS)\`\n" >>logs/$i
|
---|
611 | EOF
|
---|
612 | ) >> $MKFILE.tmp
|
---|
613 |
|
---|
614 | fi
|
---|
615 |
|
---|
616 | # Remove the build directory(ies) even if the package build fails.
|
---|
617 | if [ "$vrs" != "" ] ; then
|
---|
618 | (
|
---|
619 | cat << EOF
|
---|
620 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
621 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
622 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
623 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
624 | fi;
|
---|
625 | EOF
|
---|
626 | ) >> $MKFILE.tmp
|
---|
627 | fi
|
---|
628 |
|
---|
629 | # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
|
---|
630 | if [ "$i" = "067-readjusting" ] ; then
|
---|
631 | (
|
---|
632 | cat << EOF
|
---|
633 | @rm -r \`cat sources-dir\` && \\
|
---|
634 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
635 | rm sources-dir
|
---|
636 | EOF
|
---|
637 | ) >> $MKFILE.tmp
|
---|
638 | fi
|
---|
639 |
|
---|
640 | # Include a touch of the target name so make can check
|
---|
641 | # if it's already been made.
|
---|
642 | (
|
---|
643 | cat << EOF
|
---|
644 | @touch \$@
|
---|
645 | EOF
|
---|
646 | ) >> $MKFILE.tmp
|
---|
647 |
|
---|
648 | # Keep the script file name for Makefile dependencies.
|
---|
649 | PREV=$i
|
---|
650 | done
|
---|
651 |
|
---|
652 | # Add a header, some variables and include the function file
|
---|
653 | # to the top of the real Makefile.
|
---|
654 | (
|
---|
655 | cat << EOF
|
---|
656 | $HEADER
|
---|
657 |
|
---|
658 | SRC= /sources
|
---|
659 | LFS= $BUILDDIR
|
---|
660 | PAGE= $PAGE
|
---|
661 |
|
---|
662 | include functions
|
---|
663 |
|
---|
664 | EOF
|
---|
665 | ) > $MKFILE
|
---|
666 |
|
---|
667 |
|
---|
668 | # Add chroot commands
|
---|
669 | i=1
|
---|
670 | for file in chapter06/*chroot* ; do
|
---|
671 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
|
---|
672 | -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|&&exit||g' -e 's|$| -c|' -e 's|"$$LFS"|$(LFS)|'`
|
---|
673 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
674 | i=`expr $i + 1`
|
---|
675 | done
|
---|
676 |
|
---|
677 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
678 | # as a dependency.
|
---|
679 | (
|
---|
680 | cat << EOF
|
---|
681 | all: chapter4 chapter5 chapter6
|
---|
682 | @echo -e "\n\tYour new LFS system has been successfully built"
|
---|
683 |
|
---|
684 | chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
685 |
|
---|
686 | chapter5: chapter4 $chapter5
|
---|
687 |
|
---|
688 | chapter6: chapter5 $chapter6
|
---|
689 |
|
---|
690 | clean-all: clean
|
---|
691 | rm -rf ./*
|
---|
692 |
|
---|
693 | clean: clean-chapter5 clean-chapter4
|
---|
694 |
|
---|
695 | clean-chapter4:
|
---|
696 | -userdel lfs
|
---|
697 | rm -rf /home/lfs
|
---|
698 | rm -rf \$(LFS)/tools
|
---|
699 | rm -f /tools
|
---|
700 | rm -f envars
|
---|
701 | rm -f 02* logs/02*.log
|
---|
702 |
|
---|
703 | clean-chapter5:
|
---|
704 | rm -rf \$(LFS)/tools/*
|
---|
705 | rm -f envars
|
---|
706 | rm -f $chapter5
|
---|
707 | cd logs && rm -f $chapter5 && cd ..
|
---|
708 |
|
---|
709 | 020-creatingtoolsdir:
|
---|
710 | @\$(call echo_message, Building)
|
---|
711 | @mkdir -v \$(LFS)/tools && \\
|
---|
712 | ln -sv \$(LFS)/tools / && \\
|
---|
713 | touch \$@
|
---|
714 |
|
---|
715 | 021-addinguser: 020-creatingtoolsdir
|
---|
716 | @\$(call echo_message, Building)
|
---|
717 | @groupadd lfs && \\
|
---|
718 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
|
---|
719 | chown lfs \$(LFS)/tools && \\
|
---|
720 | chown lfs \$(LFS)/sources && \\
|
---|
721 | touch \$@
|
---|
722 |
|
---|
723 | 022-settingenvironment: 021-addinguser
|
---|
724 | @\$(call echo_message, Building)
|
---|
725 | @echo "exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash" > /home/lfs/.bash_profile && \\
|
---|
726 | echo "set +h" > /home/lfs/.bashrc && \\
|
---|
727 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
728 | echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
|
---|
729 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
730 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
731 | echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
732 | echo ". $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
733 | chown lfs:lfs /home/lfs/.bash* && \\
|
---|
734 | touch envars && \\
|
---|
735 | touch \$@
|
---|
736 | EOF
|
---|
737 | ) >> $MKFILE
|
---|
738 |
|
---|
739 | # Bring over the items from the Makefile.tmp
|
---|
740 | cat $MKFILE.tmp >> $MKFILE
|
---|
741 | rm $MKFILE.tmp
|
---|
742 | echo -ne "done\n"
|
---|
743 | }
|
---|
744 |
|
---|
745 | run_make() {
|
---|
746 | # Test if make must be run.
|
---|
747 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
748 | # Build the system
|
---|
749 | if [ -e $MKFILE ] ; then
|
---|
750 | echo -ne "Building the LFS system...\n"
|
---|
751 | cd $JHALFSDIR && make
|
---|
752 | echo -ne "done\n"
|
---|
753 | fi
|
---|
754 | fi
|
---|
755 | }
|
---|
756 |
|
---|
757 | if [ ! -d $JHALFSDIR ] ; then
|
---|
758 | mkdir -p $JHALFSDIR
|
---|
759 | fi
|
---|
760 |
|
---|
761 | if [ ! -d $LOGDIR ] ; then
|
---|
762 | mkdir $LOGDIR
|
---|
763 | fi
|
---|
764 |
|
---|
765 | >$LOGDIR/$LOG
|
---|
766 |
|
---|
767 | if [ "$PWD" != "$JHALFSDIR" ] ; then
|
---|
768 | cp $0 $XSL $FNC $JHALFSDIR/
|
---|
769 | fi
|
---|
770 |
|
---|
771 | get_book
|
---|
772 | build_Makefile
|
---|
773 | run_make
|
---|