source: jhalfs@ 9349479

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 9349479 was 9349479, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

No need to retain TCL's directory anymore, and a few typo fixes.

  • Property mode set to 100755
File size: 30.7 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 are some entities that aren't valid packages.
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 aren'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 sources directory.
483 if [[ `_IS_ $i binutils` ]] ; 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 # Everything else, add a true statment so we don't confuse make
500 else
501(
502 cat << EOF
503 true
504EOF
505) >> $MKFILE.tmp
506 fi
507
508 # Insert date and disk usage at the top of the log file, the script run
509 # and date and disk usage again at the bottom of the log file.
510(
511 cat << EOF
512 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
513 su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
514 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
515EOF
516) >> $MKFILE.tmp
517
518 # Remove the build directory(ies) except if the package build fails
519 # (so we can review config.cache, config.log, etc.)
520 # For Binutils the sources must be retained for some time.
521 if [ "$vrs" != "" ] ; then
522 if [[ ! `_IS_ $i binutils` ]] ; then
523(
524 cat << EOF
525 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
526 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
527 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
528 rm -r \$(LFS)\$(SRC)/$name-build; \\
529 fi;
530EOF
531) >> $MKFILE.tmp
532 fi
533 fi
534
535 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
536 if [[ `_IS_ $i adjusting` ]] ; then
537(
538 cat << EOF
539 @rm -r \`cat sources-dir\` && \\
540 rm -r \$(LFS)\$(SRC)/binutils-build && \\
541 rm sources-dir
542EOF
543) >> $MKFILE.tmp
544 fi
545
546 # Include a touch of the target name so make can check
547 # if it's already been made.
548(
549 cat << EOF
550 @touch \$@
551EOF
552) >> $MKFILE.tmp
553
554 # Keep the script file name for Makefile dependencies.
555 PREV=$i
556 done # end for file in chapter05/*
557}
558
559#----------------------------#
560chapter6_Makefiles() {
561#----------------------------#
562 for file in chapter06/* ; do
563 # Keep the script file name
564 i=`basename $file`
565
566 # We'll run the chroot commands differently than the others, so skip them in the
567 # dependencies and target creation.
568 if [[ `_IS_ $i chroot` ]] ; then
569 continue
570 fi
571
572 # Test if the stripping phase must be skipped
573 if [ "$STRIP" = "0" ] && [[ `_IS_ $i stripping` ]] ; then
574 continue
575 fi
576
577 # First append each name of the script files to a list (this will become
578 # the names of the targets in the Makefile
579 chapter6="$chapter6 $i"
580
581 # Grab the name of the target
582 name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
583
584 # Drop in the name of the target on a new line, and the previous target
585 # as a dependency. Also call the echo_message function.
586(
587 cat << EOF
588
589$i: $PREV
590 @\$(call echo_message, Building)
591EOF
592) >> $MKFILE.tmp
593
594 # Find the version of the command files, if it corresponds with the building of
595 # a specific package
596 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
597
598 # If $vrs isn't empty, we've got a package...
599 # Insert instructions for unpacking the package and changing directories
600 if [ "$vrs" != "" ] ; then
601 FILE="$name-$vrs.tar.*"
602(
603 cat << EOF
604 @\$(call unpack2,$FILE)
605 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
606 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
607 echo "export PKGDIR" >> envars
608EOF
609) >> $MKFILE.tmp
610 fi
611
612 # For the Re-Adjusting phase we must to cd to the binutils-build directory.
613 if [[ `_IS_ $i readjusting` ]] ; then
614(
615 cat << EOF
616 @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
617 echo "export PKGDIR" >> envars
618EOF
619) >> $MKFILE.tmp
620
621 # For Glibc we need to set TIMEZONE envar.
622 elif [[ `_IS_ $i glibc` ]] ; then
623(
624 cat << EOF
625 @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
626 echo "export TIMEZONE" >> envars
627EOF
628) >> $MKFILE.tmp
629
630 # For Groff we need to set PAGE envar.
631 elif [[ `_IS_ $i groff` ]] ; then
632(
633 cat << EOF
634 @echo "PAGE=\$(PAGE)" >> envars && \\
635 echo "export PAGE" >> envars
636EOF
637) >> $MKFILE.tmp
638 fi
639
640 # In the mount of kernel filesystems we need to set LFS
641 # and not to use chroot.
642 if [[ `_IS_ $i kernfs` ]] ; then
643(
644 cat << EOF
645 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
646 export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
647 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
648EOF
649) >> $MKFILE.tmp
650
651 # The rest of Chapter06
652 else
653(
654 cat << EOF
655 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
656 \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
657 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
658EOF
659) >> $MKFILE.tmp
660 fi
661
662 # Remove the build directory(ies) except if the package build fails.
663 if [ "$vrs" != "" ] ; then
664(
665 cat << EOF
666 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
667 rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
668 if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
669 rm -r \$(LFS)\$(SRC)/$name-build; \\
670 fi;
671EOF
672) >> $MKFILE.tmp
673 fi
674
675 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
676 if [[ `_IS_ $i readjusting` ]] ; then
677(
678 cat << EOF
679 @rm -r \`cat sources-dir\` && \\
680 rm -r \$(LFS)\$(SRC)/binutils-build && \\
681 rm sources-dir
682EOF
683) >> $MKFILE.tmp
684 fi
685
686 # Include a touch of the target name so make can check
687 # if it's already been made.
688(
689 cat << EOF
690 @touch \$@
691EOF
692) >> $MKFILE.tmp
693
694 # Keep the script file name for Makefile dependencies.
695 PREV=$i
696 done # end for file in chapter06/*
697}
698
699#----------------------------#
700chapter789_Makefiles() {
701#----------------------------#
702 for file in chapter0{7,8,9}/* ; do
703 # Keep the script file name
704 i=`basename $file`
705
706 # Grub must be configured manually.
707 # The filesystems can't be unmounted via Makefile and the user
708 # should to enter to the chroot environment to create the root
709 # password, edit several files and setup Grub,
710 if [[ `_IS_ $i grub` ]] || [[ `_IS_ $i reboot` ]] ; then
711 continue
712 fi
713
714 # If no .config file is supplied, the kernel build is skipped
715 if [ -z $CONFIG ] && [[ `_IS_ $i kernel` ]] ; then
716 continue
717 fi
718
719 # First append each name of the script files to a list (this will become
720 # the names of the targets in the Makefile
721 chapter789="$chapter789 $i"
722
723 # Drop in the name of the target on a new line, and the previous target
724 # as a dependency. Also call the echo_message function.
725(
726 cat << EOF
727
728$i: $PREV
729 @\$(call echo_message, Building)
730EOF
731) >> $MKFILE.tmp
732
733 # Find the the bootscripts and kernel package names
734 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
735 if [[ `_IS_ $i bootscripts` ]] ; then
736 vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
737 FILE="lfs-bootscripts-$vrs.tar.*"
738 elif [[ `_IS_ $i kernel` ]] ; then
739 vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
740 FILE="linux-$vrs.tar.*"
741 fi
742(
743 cat << EOF
744 @\$(call unpack2,$FILE)
745 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
746 echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
747 echo "export PKGDIR" >> envars
748EOF
749) >> $MKFILE.tmp
750 fi
751
752 # Put in place the kernel .config file
753 if [[ `_IS_ $i kernel` ]] ; then
754(
755 cat << EOF
756 @cp $CONFIG \$(LFS)/sources/kernel-config
757EOF
758) >> $MKFILE.tmp
759 fi
760
761 # Check if we have a real /etc/fstab file
762 if [[ `_IS_ $i fstab` ]] && [[ -n "$FSTAB" ]] ; then
763(
764 cat << EOF
765 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
766 cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
767 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
768EOF
769) >> $MKFILE.tmp
770 else
771 # Initialize the log an run the script
772(
773 cat << EOF
774 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
775 \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
776 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
777EOF
778) >> $MKFILE.tmp
779 fi
780
781 # Remove the build directory except if the package build fails.
782 if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
783(
784 cat << EOF
785 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
786 rm -r \$(LFS)\$(SRC)/\$\$ROOT
787EOF
788) >> $MKFILE.tmp
789 fi
790
791 # Include a touch of the target name so make can check
792 # if it's already been made.
793(
794 cat << EOF
795 @touch \$@
796EOF
797) >> $MKFILE.tmp
798
799 # Keep the script file name for Makefile dependencies.
800 PREV=$i
801 done # for file in chapter0{7,8,9}/*
802}
803
804
805#----------------------------#
806build_Makefile() {
807#----------------------------#
808 echo -n "Creating Makefile... "
809 cd $JHALFSDIR/commands
810
811 # Start with a clean Makefile.tmp file
812 >$MKFILE.tmp
813
814 chapter4_Makefiles
815 chapter5_Makefiles
816 chapter6_Makefiles
817 chapter789_Makefiles
818
819
820 # Add a header, some variables and include the function file
821 # to the top of the real Makefile.
822(
823 cat << EOF
824$HEADER
825
826SRC= /sources
827LFS= $BUILDDIR
828PAGE= $PAGE
829TIMEZONE= $TIMEZONE
830
831include functions
832
833EOF
834) > $MKFILE
835
836
837 # Add chroot commands
838 i=1
839 for file in chapter06/*chroot* ; do
840 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
841 -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
842 -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
843 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
844 i=`expr $i + 1`
845 done
846
847 # Drop in the main target 'all:' and the chapter targets with each sub-target
848 # as a dependency.
849(
850 cat << EOF
851all: chapter4 chapter5 chapter6 chapter789
852 @\$(call echo_finished,$VERSION)
853
854chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
855
856chapter5: chapter4 $chapter5 restore-lfs-env
857
858chapter6: chapter5 $chapter6
859
860chapter789: chapter6 $chapter789
861
862clean-all: clean
863 rm -rf ./{commands,logs,Makefile,dump-lfs-scripts.xsl,functions,packages,patches}
864
865clean: clean-chapter789 clean-chapter6 clean-chapter5 clean-chapter4
866
867clean-chapter4:
868 -if [ ! -f user-lfs-exist ]; then \\
869 userdel lfs; \\
870 rm -rf /home/lfs; \\
871 fi;
872 rm -rf \$(LFS)/tools
873 rm -f /tools
874 rm -f envars user-lfs-exist
875 rm -f 02* logs/02*.log
876
877clean-chapter5:
878 rm -rf \$(LFS)/tools/*
879 rm -f $chapter5 restore-lfs-env sources-dir
880 cd logs && rm -f $chapter5 && cd ..
881
882clean-chapter6:
883 -umount \$(LFS)/sys
884 -umount \$(LFS)/proc
885 -umount \$(LFS)/dev/shm
886 -umount \$(LFS)/dev/pts
887 -umount \$(LFS)/dev
888 rm -rf \$(LFS)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
889 rm -f $chapter6
890 cd logs && rm -f $chapter6 && cd ..
891
892clean-chapter789:
893 rm -f $chapter789
894 cd logs && rm -f $chapter789 && cd ..
895
896restore-lfs-env:
897 @\$(call echo_message, Building)
898 @if [ -f /home/lfs/.bashrc.XXX ]; then \\
899 mv -fv /home/lfs/.bashrc.XXX /home/lfs/.bashrc; \\
900 fi;
901 @if [ -f /home/lfs/.bash_profile.XXX ]; then \\
902 mv -v /home/lfs/.bash_profile.XXX /home/lfs/.bash_profile; \\
903 fi;
904 @chown lfs:lfs /home/lfs/.bash* && \\
905 touch \$@
906
907EOF
908) >> $MKFILE
909
910 # Bring over the items from the Makefile.tmp
911 cat $MKFILE.tmp >> $MKFILE
912 rm $MKFILE.tmp
913 echo -ne "done\n"
914}
915
916#----------------------------#
917run_make() {
918#----------------------------#
919 # Test if make must be run.
920 if [ "$RUNMAKE" = "1" ] ; then
921 # Test to make sure we're running the build as root
922 if [ "$UID" != "0" ] ; then
923 echo "You must be logged in as root to successfully build LFS."
924 exit 1
925 fi
926 # Build the system
927 if [ -e $MKFILE ] ; then
928 echo -ne "Building the LFS system...\n"
929 cd $JHALFSDIR && make
930 echo -ne "done\n"
931 fi
932 fi
933}
934
935
936
937###################################
938### MAIN ###
939###################################
940
941# Evaluate any command line switches
942
943while test $# -gt 0 ; do
944 case $1 in
945 --version | -V )
946 echo "$version"
947 exit 0
948 ;;
949
950 --help | -h )
951 echo "$usage"
952 exit 0
953 ;;
954
955 --LFS-version | -L )
956 test $# = 1 && eval "$exit_missing_arg"
957 shift
958 case $1 in
959 dev* | SVN | trunk )
960 LFSVRS=development
961 ;;
962 6.1.1 )
963 LFSVRS=6.1.1
964 ;;
965
966 alpha*)
967 LFSVRS=alphabetical
968 ;;
969 * )
970 echo "$1 is an unsupported version at this time."
971 exit 1
972 ;;
973 esac
974 ;;
975
976 --directory | -d )
977 test $# = 1 && eval "$exit_missing_arg"
978 shift
979 BUILDDIR=$1
980 JHALFSDIR=$BUILDDIR/jhalfs
981 LOGDIR=$JHALFSDIR/logs
982 MKFILE=$JHALFSDIR/Makefile
983 ;;
984
985 --rebuild ) CLEAN=1 ;;
986
987 --download-client | -D )
988 test $# = 1 && eval "$exit_missing_arg"
989 shift
990 DL=$1
991 ;;
992
993 --working-copy | -W )
994 test $# = 1 && eval "$exit_missing_arg"
995 shift
996 if [ -f $1/patches.ent ] ; then
997 WC=1
998 BOOK=$1
999 else
1000 echo -e "\nLook like $1 isn't a supported working copy."
1001 echo -e "Verify your selection and the command line.\n"
1002 exit 1
1003 fi
1004 ;;
1005
1006 --testsuites | -T ) TEST=1 ;;
1007
1008 --get-packages | -P ) HPKG=1 ;;
1009
1010 --run-make | -M ) RUNMAKE=1 ;;
1011
1012 --no-toolchain-test ) TOOLCHAINTEST=0 ;;
1013
1014 --no-strip ) STRIP=0 ;;
1015
1016 --no-vim-lang ) VIMLANG=0 ;;
1017
1018 --page_size )
1019 test $# = 1 && eval "$exit_missing_arg"
1020 shift
1021 case $1 in
1022 letter | A4 )
1023 PAGE=$1
1024 ;;
1025 * )
1026 echo "$1 isn't a supported page size."
1027 exit 1
1028 ;;
1029 esac
1030 ;;
1031
1032
1033 --timezone )
1034 test $# = 1 && eval "$exit_missing_arg"
1035 shift
1036 if [ -f /usr/share/zoneinfo/$1 ] ; then
1037 TIMEZONE=$1
1038 else
1039 echo -e "\nLook like $1 isn't a valid timezone description."
1040 echo -e "Verify your selection and the command line.\n"
1041 exit 1
1042 fi
1043 ;;
1044
1045 --fstab )
1046 test $# = 1 && eval "$exit_missing_arg"
1047 shift
1048 if [ -f $1 ] ; then
1049 FSTAB=$1
1050 else
1051 echo -e "\nFile $1 not found. Verify your command line.\n"
1052 exit 1
1053 fi
1054 ;;
1055
1056 --kernel-config | -C )
1057 test $# = 1 && eval "$exit_missing_arg"
1058 shift
1059 if [ -f $1 ] ; then
1060 CONFIG=$1
1061 else
1062 echo -e "\nFile $1 not found. Verify your command line.\n"
1063 exit 1
1064 fi
1065 ;;
1066
1067 * )
1068 echo "$usage"
1069 exit 1
1070 ;;
1071 esac
1072 shift
1073done
1074
1075# Prevents setting "-d /" by mistake.
1076
1077if [ $BUILDDIR = / ] ; then
1078 echo -ne "\nThe root directory can't be used to build LFS.\n\n"
1079 exit 1
1080fi
1081
1082# If $BUILDDIR have subdirectories like tools/ or bin/, stop the run
1083# and notify the user about that.
1084
1085if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
1086 eval "$no_empty_builddir"
1087fi
1088
1089# If requested, clean the build directory
1090clean_builddir
1091
1092# Find the download client to use, if not already specified.
1093
1094if [ -z $DL ] ; then
1095 if [ `type -p wget` ] ; then
1096 DL=wget
1097 elif [ `type -p curl` ] ; then
1098 DL=curl
1099 else
1100 eval "$no_dl_client"
1101 fi
1102fi
1103
1104if [ -z $BOOK ] ; then
1105 BOOK=lfs-$LFSVRS
1106fi
1107
1108[[ ! -d $JHALFSDIR ]] && mkdir -pv $JHALFSDIR
1109[[ "$PWD" != "$JHALFSDIR" ]] && cp -v $FILES $JHALFSDIR/ && \
1110 sed 's,FAKEDIR,'$BOOK',' $XSL > $JHALFSDIR/dump-lfs-scripts.xsl && \
1111 export XSL=$JHALFSDIR/dump-lfs-scripts.xsl
1112[[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
1113>$LOGDIR/$LOG
1114
1115get_book
1116build_Makefile
1117run_make
1118
Note: See TracBrowser for help on using the repository browser.