source: jhalfs@ 1136382

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

Fix some temporary brokenness in extracting the commands

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