source: jhalfs@ be9970b

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

Now packages in tar.gz format are supported also.

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