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