source: jhalfs@ 5aa36d5

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

Added support for udev_update branch (but not tested the build.)

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