source: jhalfs@ 70a223e

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 70a223e was 70a223e, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Making the stripping phases optional.

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