source: jhalfs@ b287536

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

Changed how the testsuites are handled and fixed the missing locales installation for chapter05 testsuites.

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