source: jhalfs@ 741fbe5

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

Fixed a small issue when procesing the Spanish book translation.

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