source: jhalfs@ f4a4ba5

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

Fixed an erroneous commands rebuild when the user language isn't English.

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