source: jhalfs@ e90c0c3

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

For LFS-6.1.1, jhalfs-0.2 must be used.

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