source: jhalfs@ da5860a

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

Added --rebuild switch.

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