source: jhalfs@ d4c6056

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

Udated to udev-config-4.rules

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