source: jhalfs@ 1a17f94

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

Creating the MD5SUMS-$VERSION file.

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