source: jhalfs@ 3d82fb5

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

Some fixes not full tested yet: Removed all 6.1.1-related code (that LFS version is supported only by jhalfs-0.2) and the i18n branch has been merged to trunk.

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