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