source: jhalfs@ 540e0c6

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

The glibc-linuxtrheads and module-init-tools-testsuite packages are required only for 6.1.1

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