source: jhalfs@ c563174

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

Merged r2192 from trunk.

  • Property mode set to 100755
File size: 28.4 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 rm -fv /tools && \\
336 ln -sv \$(LFS)/tools / && \\
337 touch \$@
338
339021-addinguser: 020-creatingtoolsdir
340 @\$(call echo_message, Building)
341 @groupadd lfs && \\
342 useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
343 chown lfs \$(LFS)/tools && \\
344 chown lfs \$(LFS)/sources && \\
345 touch \$@
346
347022-settingenvironment: 021-addinguser
348 @\$(call echo_message, Building)
349 @echo "set +h" > /home/lfs/.bashrc && \\
350 echo "umask 022" >> /home/lfs/.bashrc && \\
351 echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
352 echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
353 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
354 echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
355 echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
356 chown lfs:lfs /home/lfs/.bashrc && \\
357 touch envars && \\
358 touch \$@
359EOF
360) >> $MKFILE.tmp
361}
362
363#----------------------------#
364chapter5_Makefiles() {
365#----------------------------#
366 for file in chapter05/* ; do
367 # Keep the script file name
368 i=`basename $file`
369
370 # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
371 if [ "$TOOLCHAINTEST" = "0" ]; then
372 if [[ `_IS_ $i tcl` ]] || [[ `_IS_ $i expect` ]] || [[ `_IS_ $i dejagnu` ]] ; then
373 continue
374 fi
375 fi
376
377 # Test if the stripping phase must be skipped
378 if [ "$STRIP" = "0" ] && [[ `_IS_ $i stripping` ]] ; then
379 continue
380 fi
381
382 # First append each name of the script files to a list (this will become
383 # the names of the targets in the Makefile
384 chapter5="$chapter5 $i"
385
386 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
387 # and binutils in chapter 5)
388 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
389
390 # Set the dependency for the first target.
391 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
392
393 # Drop in the name of the target on a new line, and the previous target
394 # as a dependency. Also call the echo_message function.
395(
396 cat << EOF
397
398$i: $PREV
399 @\$(call echo_message, Building)
400EOF
401) >> $MKFILE.tmp
402
403 # Find the version of the command files, if it corresponds with the building of
404 # a specific package
405 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
406
407 # If $vrs isn't empty, we've got a package...
408 if [ "$vrs" != "" ] ; then
409 if [ "$name" = "tcl" ] ; then
410 FILE="$name$vrs-src.tar"
411 else
412 FILE="$name-$vrs.tar"
413 fi
414
415 # Insert instructions for unpacking the package and to set
416 # the PKGDIR variable.
417(
418 cat << EOF
419 @\$(call unpack,$FILE)
420 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
421 chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
422 echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
423 echo "export PKGDIR" >> envars && \\
424EOF
425) >> $MKFILE.tmp
426
427 fi
428
429 # Dump the path to the Binutils or TCL sources directory.
430 if [[ `_IS_ $i binutils` ]] || [[ `_IS_ $i tcl` ]] ; then
431(
432 cat << EOF
433 echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
434EOF
435) >> $MKFILE.tmp
436
437 # For the Adjusting phase we must to cd to the binutils-build directory.
438 elif [[ `_IS_ $i adjusting` ]] ; then
439(
440 cat << EOF
441 @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
442 echo "export PKGDIR" >> envars
443EOF
444) >> $MKFILE.tmp
445
446 # For the Expect build we need to set the TCLPATH envar.
447 elif [[ `_IS_ $i expect` ]] ; then
448(
449 cat << EOF
450 echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
451 echo "export TCLPATH" >> envars
452EOF
453) >> $MKFILE.tmp
454
455 # Everything else, add a true statment so we don't confuse make
456 else
457(
458 cat << EOF
459 true
460EOF
461) >> $MKFILE.tmp
462 fi
463
464 # Insert date and disk usage at the top of the log file, the script run
465 # and date and disk usage again at the bottom of the log file.
466(
467 cat << EOF
468 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
469 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
470 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
471EOF
472) >> $MKFILE.tmp
473
474 # Remove the build directory(ies) except if the package build fails
475 # (to can review config.cache, config.log, and like.)
476 # For Binutils and TCL the sources must be retained some time.
477 if [ "$vrs" != "" ] ; then
478 if [[ ! `_IS_ $i binutils` ]] && [[ ! `_IS_ $i tcl` ]] ; then
479(
480 cat << EOF
481 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
482 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
483 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
484 rm -r \$(LFS)\$(SRC)/$name-build; \\
485 fi;
486EOF
487) >> $MKFILE.tmp
488 fi
489 fi
490
491 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
492 if [[ `_IS_ $i adjusting` ]] ; then
493(
494 cat << EOF
495 @rm -r \`cat sources-dir\` && \\
496 rm -r \$(LFS)\$(SRC)/binutils-build && \\
497 rm sources-dir
498EOF
499) >> $MKFILE.tmp
500 fi
501
502 # Remove the TCL sources after a successful Expect build.
503 if [[ `_IS_ $i expect` ]] ; then
504(
505 cat << EOF
506 @rm -r \`cat sources-dir\` && \\
507 rm sources-dir
508EOF
509) >> $MKFILE.tmp
510 fi
511
512 # Include a touch of the target name so make can check
513 # if it's already been made.
514(
515 cat << EOF
516 @touch \$@
517EOF
518) >> $MKFILE.tmp
519
520 # Keep the script file name for Makefile dependencies.
521 PREV=$i
522 done # end for file in chapter05/*
523}
524
525#----------------------------#
526chapter6_Makefiles() {
527#----------------------------#
528 for file in chapter06/* ; do
529 # Keep the script file name
530 i=`basename $file`
531
532 # We'll run the chroot commands differently than the others, so skip them in the
533 # dependencies and target creation.
534 if [[ `_IS_ $i chroot` ]] ; then
535 continue
536 fi
537
538 # Test if the stripping phase must be skipped
539 if [ "$STRIP" = "0" ] && [[ `_IS_ $i stripping` ]] ; then
540 continue
541 fi
542
543 # First append each name of the script files to a list (this will become
544 # the names of the targets in the Makefile
545 chapter6="$chapter6 $i"
546
547 # Grab the name of the target
548 name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
549
550 # Drop in the name of the target on a new line, and the previous target
551 # as a dependency. Also call the echo_message function.
552(
553 cat << EOF
554
555$i: $PREV
556 @\$(call echo_message, Building)
557EOF
558) >> $MKFILE.tmp
559
560 # Find the version of the command files, if it corresponds with the building of
561 # a specific package
562 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
563
564 # If $vrs isn't empty, we've got a package...
565 # Insert instructions for unpacking the package and changing directories
566 if [ "$vrs" != "" ] ; then
567 FILE="$name-$vrs.tar.*"
568(
569 cat << EOF
570 @\$(call unpack2,$FILE)
571 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
572 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
573 echo "export PKGDIR" >> envars
574EOF
575) >> $MKFILE.tmp
576 fi
577
578 # For the Re-Adjusting phase we must to cd to the binutils-build directory.
579 if [[ `_IS_ $i readjusting` ]] ; then
580(
581 cat << EOF
582 @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
583 echo "export PKGDIR" >> envars
584EOF
585) >> $MKFILE.tmp
586
587 # For Glibc we need to set TIMEZONE envar.
588 elif [[ `_IS_ $i glibc` ]] ; then
589(
590 cat << EOF
591 @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
592 echo "export TIMEZONE" >> envars
593EOF
594) >> $MKFILE.tmp
595
596 # For Groff we need to set PAGE envar.
597 elif [[ `_IS_ $i groff` ]] ; then
598(
599 cat << EOF
600 @echo "PAGE=\$(PAGE)" >> envars && \\
601 echo "export PAGE" >> envars
602EOF
603) >> $MKFILE.tmp
604 fi
605
606 # In the mount of kernel filesystems we need to set LFS
607 # and not to use chroot.
608 if [[ `_IS_ $i kernfs` ]] ; then
609(
610 cat << EOF
611 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
612 export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
613 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
614EOF
615) >> $MKFILE.tmp
616
617 # The rest of Chapter06
618 else
619(
620 cat << EOF
621 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
622 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
623 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
624EOF
625) >> $MKFILE.tmp
626 fi
627
628 # Remove the build directory(ies) except if the package build fails.
629 if [ "$vrs" != "" ] ; then
630(
631 cat << EOF
632 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
633 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
634 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
635 rm -r \$(LFS)\$(SRC)/$name-build; \\
636 fi;
637EOF
638) >> $MKFILE.tmp
639 fi
640
641 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
642 if [[ `_IS_ $i readjusting` ]] ; then
643(
644 cat << EOF
645 @rm -r \`cat sources-dir\` && \\
646 rm -r \$(LFS)\$(SRC)/binutils-build && \\
647 rm sources-dir
648EOF
649) >> $MKFILE.tmp
650 fi
651
652 # Include a touch of the target name so make can check
653 # if it's already been made.
654(
655 cat << EOF
656 @touch \$@
657EOF
658) >> $MKFILE.tmp
659
660 # Keep the script file name for Makefile dependencies.
661 PREV=$i
662 done # end for file in chapter06/*
663}
664
665#----------------------------#
666chapter789_Makefiles() {
667#----------------------------#
668 for file in chapter0{7,8,9}/* ; do
669 # Keep the script file name
670 i=`basename $file`
671
672 # Grub must be configured manually.
673 # The filesystems can't be unmounted via Makefile and the user
674 # should to enter to the chroot environment to create the root
675 # password, edit several files and setup Grub,
676 if [[ `_IS_ $i grub` ]] || [[ `_IS_ $i reboot` ]] ; then
677 continue
678 fi
679
680 # If no .config file is supplied, the kernel build is skipped
681 if [ -z $CONFIG ] && [[ `_IS_ $i kernel` ]] ; then
682 continue
683 fi
684
685 # First append each name of the script files to a list (this will become
686 # the names of the targets in the Makefile
687 chapter789="$chapter789 $i"
688
689 # Drop in the name of the target on a new line, and the previous target
690 # as a dependency. Also call the echo_message function.
691(
692 cat << EOF
693
694$i: $PREV
695 @\$(call echo_message, Building)
696EOF
697) >> $MKFILE.tmp
698
699 # Find the the bootscripts and kernel package names
700 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
701 if [[ `_IS_ $i bootscripts` ]] ; then
702 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
703 FILE="lfs-bootscripts-$vrs.tar.*"
704 elif [[ `_IS_ $i kernel` ]] ; then
705 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
706 FILE="linux-$vrs.tar.*"
707 fi
708(
709 cat << EOF
710 @\$(call unpack2,$FILE)
711 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
712 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
713 echo "export PKGDIR" >> envars
714EOF
715) >> $MKFILE.tmp
716 fi
717
718 # Put in place the kernel .config file
719 if [[ `_IS_ $i kernel` ]] ; then
720(
721 cat << EOF
722 @cp $CONFIG \$(LFS)/sources/kernel-config
723EOF
724) >> $MKFILE.tmp
725 fi
726
727 # Check if we have a real /etc/fstab file
728 if [[ `_IS_ $i fstab` ]] && [[ -n "$FSTAB" ]] ; then
729(
730 cat << EOF
731 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
732 cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
733 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
734EOF
735) >> $MKFILE.tmp
736 else
737 # Initialize the log an run the script
738(
739 cat << EOF
740 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
741 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
742 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
743EOF
744) >> $MKFILE.tmp
745 fi
746
747 # Remove the build directory except if the package build fails.
748 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
749(
750 cat << EOF
751 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
752 rm -r \$(LFS)\$(SRC)/\$\$ROOT
753EOF
754) >> $MKFILE.tmp
755 fi
756
757 # Include a touch of the target name so make can check
758 # if it's already been made.
759(
760 cat << EOF
761 @touch \$@
762EOF
763) >> $MKFILE.tmp
764
765 # Keep the script file name for Makefile dependencies.
766 PREV=$i
767 done # for file in chapter0{7,8,9}/*
768}
769
770
771#----------------------------#
772build_Makefile() {
773#----------------------------#
774 echo -n "Creating Makefile... "
775 cd $JHALFSDIR/commands
776
777 # Start with a clean Makefile.tmp file
778 >$MKFILE.tmp
779
780 chapter4_Makefiles
781 chapter5_Makefiles
782 chapter6_Makefiles
783 chapter789_Makefiles
784
785
786 # Add a header, some variables and include the function file
787 # to the top of the real Makefile.
788(
789 cat << EOF
790$HEADER
791
792SRC= /sources
793LFS= $BUILDDIR
794PAGE= $PAGE
795TIMEZONE= $TIMEZONE
796
797include functions
798
799EOF
800) > $MKFILE
801
802
803 # Add chroot commands
804 i=1
805 for file in chapter06/*chroot* ; do
806 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
807 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
808 -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
809 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
810 i=`expr $i + 1`
811 done
812
813 # Drop in the main target 'all:' and the chapter targets with each sub-target
814 # as a dependency.
815(
816 cat << EOF
817all: chapter4 chapter5 chapter6 chapter789
818 @\$(call echo_finished,$VERSION)
819
820chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
821
822chapter5: chapter4 $chapter5
823
824chapter6: chapter5 $chapter6
825
826chapter789: chapter6 $chapter789
827
828clean-all: clean
829 rm -rf ./*
830
831clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
832
833clean-chapter4:
834 -userdel lfs
835 rm -rf /home/lfs
836 rm -rf \$(LFS)/tools
837 rm -f /tools
838 rm -f envars
839 rm -f 02* logs/02*.log
840
841clean-chapter5:
842 rm -rf \$(LFS)/tools/*
843 rm -f $chapter5
844 cd logs && rm -f $chapter5 && cd ..
845
846clean-chapter6:
847 -umount \$(LFS)/sys
848 -umount \$(LFS)/proc
849 -umount \$(LFS)/dev/shm
850 -umount \$(LFS)/dev/pts
851 -umount \$(LFS)/dev
852 rm -rf \$(LFS)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
853 rm -f $chapter6
854 cd logs && rm -f $chapter6 && cd ..
855
856clean-chapter789:
857 rm -f $chapter789
858 cd logs && rm -f $chapter789 && cd ..
859
860
861EOF
862) >> $MKFILE
863
864 # Bring over the items from the Makefile.tmp
865 cat $MKFILE.tmp >> $MKFILE
866 rm $MKFILE.tmp
867 echo -ne "done\n"
868}
869
870#----------------------------#
871run_make() {
872#----------------------------#
873 # Test if make must be run.
874 if [ "$RUNMAKE" = "1" ] ; then
875 # Test to make sure we're running the build as root
876 if [ "$UID" != "0" ] ; then
877 echo "You must be logged in as root to successfully build LFS."
878 exit 1
879 fi
880 # Build the system
881 if [ -e $MKFILE ] ; then
882 echo -ne "Building the LFS system...\n"
883 cd $JHALFSDIR && make
884 echo -ne "done\n"
885 fi
886 fi
887}
888
889
890
891###################################
892### MAIN ###
893###################################
894
895# Evaluate any command line switches
896
897while test $# -gt 0 ; do
898 case $1 in
899 --version | -V )
900 echo "$version"
901 exit 0
902 ;;
903
904 --help | -h )
905 echo "$usage"
906 exit 0
907 ;;
908
909 --LFS-version | -L )
910 test $# = 1 && eval "$exit_missing_arg"
911 shift
912 case $1 in
913 dev* | SVN | trunk )
914 LFSVRS=development
915 ;;
916 testing | 6.1.1 )
917 LFSVRS=6.1.1
918 ;;
919
920 alpha*)
921 LFSVRS=alphabetical
922 ;;
923 * )
924 echo "$1 is an unsupported version at this time."
925 exit 1
926 ;;
927 esac
928 ;;
929
930 --directory | -d )
931 test $# = 1 && eval "$exit_missing_arg"
932 shift
933 BUILDDIR=$1
934 ;;
935
936 --download-client | -D )
937 test $# = 1 && eval "$exit_missing_arg"
938 shift
939 DL=$1
940 ;;
941
942 --working-copy | -W )
943 test $# = 1 && eval "$exit_missing_arg"
944 shift
945 if [ -f $1/patches.ent ] ; then
946 WC=1
947 BOOK=$1
948 else
949 echo -e "\nLook like $1 isn't a supported working copy."
950 echo -e "Verify your selection and the command line.\n"
951 exit 1
952 fi
953 ;;
954
955 --testsuites | -T ) TEST=1 ;;
956
957 --get-packages | -P ) HPKG=1 ;;
958
959 --run-make | -M ) RUNMAKE=1 ;;
960
961 --no-toolchain-test ) TOOLCHAINTEST=0 ;;
962
963 --no-strip ) STRIP=0 ;;
964
965 --no-vim-lang ) VIMLANG=0 ;;
966
967 --page_size )
968 test $# = 1 && eval "$exit_missing_arg"
969 shift
970 case $1 in
971 letter | A4 )
972 PAGE=$1
973 ;;
974 * )
975 echo "$1 isn't a supported page size."
976 exit 1
977 ;;
978 esac
979 ;;
980
981
982 --timezone )
983 test $# = 1 && eval "$exit_missing_arg"
984 shift
985 if [ -f /usr/share/zoneinfo/$1 ] ; then
986 TIMEZONE=$1
987 else
988 echo -e "\nLook like $1 isn't a valid timezone description."
989 echo -e "Verify your selection and the command line.\n"
990 exit 1
991 fi
992 ;;
993
994 --fstab )
995 test $# = 1 && eval "$exit_missing_arg"
996 shift
997 if [ -f $1 ] ; then
998 FSTAB=$1
999 else
1000 echo -e "\nFile $1 not found. Verify your command line.\n"
1001 exit 1
1002 fi
1003 ;;
1004
1005 --kernel-config | -C )
1006 test $# = 1 && eval "$exit_missing_arg"
1007 shift
1008 if [ -f $1 ] ; then
1009 CONFIG=$1
1010 else
1011 echo -e "\nFile $1 not found. Verify your command line.\n"
1012 exit 1
1013 fi
1014 ;;
1015
1016 * )
1017 echo "$usage"
1018 exit 1
1019 ;;
1020 esac
1021 shift
1022done
1023
1024# If $BUILDDIR have subdirectories like tools/ or bin/, stop the run
1025# and notify the user about that. This also prevent to set "-d /"
1026# by mistake.
1027
1028if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] ; then
1029 eval "$no_empty_builddir"
1030fi
1031
1032# Find the download client to use, if not already specified.
1033
1034if [ -z $DL ] ; then
1035 if [ `type -p wget` ] ; then
1036 DL=wget
1037 elif [ `type -p curl` ] ; then
1038 DL=curl
1039 else
1040 eval "$no_dl_client"
1041 fi
1042fi
1043
1044[[ ! -d $JHALFSDIR ]] && mkdir -pv $JHALFSDIR
1045[[ "$PWD" != "$JHALFSDIR" ]] && cp -v $FILES $JHALFSDIR/ && \
1046 sed -e 's/FAKEDIR/'$BOOK'/' $XSL > $JHALFSDIR/dump-lfs-scripts.xsl && \
1047 export XSL=$JHALFSDIR/dump-lfs-scripts.xsl
1048[[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
1049>$LOGDIR/$LOG
1050
1051get_book
1052build_Makefile
1053run_make
1054
Note: See TracBrowser for help on using the repository browser.