source: jhalfs@ 478880c

0.2
Last change on this file since 478880c was 478880c, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Merged r2190 from trunk.

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