source: jhalfs@ 7a18835

0.2
Last change on this file since 7a18835 was 0d5eabf, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

Merged rev 2229 to 0.2 branch

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