source: jhalfs@ 0fd8a9d

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

Added support for UTF-8 branch packages and patches.

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