source: jhalfs@ 3cfe871

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

Renamed the stylesheet to diferentiate it from the ones in the {B,H,Cross}LFS books.

  • Property mode set to 100755
File size: 15.5 KB
Line 
1#!/bin/sh
2
3version="
4jhalfs development
5
6Originally written by Jeremy Huntwork.
7Maintained by Manuel Canales Esparcia.
8
9This program is published under the \
10Gnu General Public License, Version 2.
11"
12
13usage="\
14Usage: $0 [OPTION]
15
16Options:
17 -h, --help print this help, then exit
18 -V, --version print version number, then exit
19 -L, --LFS-version=VER use VER version of the LFS book
20 -d --directory=DIR use DIR directory for building LFS; all files
21 jhalfs produces will be in the directory
22 DIR/jhalfs
23 -D, --download-client=CLIENT use CLIENT as the program for retrieving
24 packages
25 -T, --testsuites run the optional testsuites
26 -P, --get-packages download the packages
27 -M, --run-make run make on the generated Makefile
28"
29
30help="\
31Try '$0 --help' for more information."
32
33exit_missing_arg="\
34echo \"Option '\$1' requires an argument\" >&2
35echo \"\$help\" >&2
36exit 1"
37
38no_dl_client="\
39echo \"Could not find a way to download the LFS sources.\" >&2
40echo \"Attempting to continue.\" >&2"
41
42while test $# -gt 0 ; do
43 case $1 in
44 --version | -V )
45 echo "$version"
46 exit 0
47 ;;
48
49 --help | -h )
50 echo "$usage"
51 exit 0
52 ;;
53
54 --LFS-version | -L )
55 test $# = 1 && eval "$exit_missing_arg"
56 shift
57 case $1 in
58 dev* | SVN | trunk )
59 LFSVRS=development
60 ;;
61 * )
62 echo "$1 is an unsupported version at this time."
63 exit 1
64 ;;
65 esac
66 shift
67 ;;
68
69 --directory | -d )
70 test $# = 1 && eval "$exit_missing_arg"
71 shift
72 BUILDDIR=$1
73 shift
74 ;;
75
76 --download-client | -D )
77 test $# = 1 && eval "$exit_missing_arg"
78 shift
79 DL=$1
80 shift
81 ;;
82
83 --testsuites | -T )
84 TEST=1
85 shift
86 ;;
87
88 --get-packages | -P )
89 HPKG=1
90 shift
91 ;;
92
93 --run-make | -M )
94 RUNMAKE=1
95 shift
96 ;;
97
98 * )
99 echo "$usage"
100 exit 1
101 ;;
102 esac
103done
104
105# Test to make sure we're running the build as root
106
107if [ "$UID" != "0" ] ; then
108 echo "You must be logged in as root to successfully build LFS."
109 exit 1
110fi
111
112# Find the download client to use, if not already specified.
113
114if [ -z $DL ] ; then
115 if [ `type -p wget` ] ; then
116 DL=wget
117 elif [ `type -p curl` ] ; then
118 DL=curl
119 else
120 eval "$no_dl_client"
121 fi
122fi
123
124SVN="svn://svn.linuxfromscratch.org"
125HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
126if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
127JHALFSDIR=$BUILDDIR/jhalfs
128LOGDIR=$JHALFSDIR/logs
129LOG=000-jhalfs.log
130MKFILE=$JHALFSDIR/Makefile
131XSL=dump-lfs-scripts.xsl
132if [ -z $TEST ] ; then TEST=0 ; fi
133
134get_book() {
135 # Check for Subversion instead of just letting the script hit 'svn' and fail.
136 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
137 exit 1"
138 cd $JHALFSDIR
139
140 # Test to make sure the LFS version is set
141 if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
142 echo -n "Downloading the LFS Book, version $LFSVRS... "
143
144 # Grab the LFS book fresh if it's missing, otherwise, update it from the
145 # repo. If we've already extracted the commands, move on to getting the
146 # sources.
147 if [ -d lfs-$LFSVRS ] ; then
148 cd lfs-$LFSVRS
149 if svn up | grep -q At && test -d $JHALFSDIR/commands && \
150 test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
151 echo -ne "done\n"
152 get_sources
153 else
154 echo -ne "done\n"
155 extract_commands
156 fi
157 else
158 if [ $LFSVRS = development ] ; then
159 svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
160 else
161 svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
162 fi
163 echo -ne "done\n"
164 extract_commands
165 fi
166}
167
168extract_commands() {
169 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
170 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
171 exit 1"
172 cd $JHALFSDIR
173
174 # Start clean
175 if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
176 echo -n "Extracting commands... "
177
178 # Dump the commands in shell script form from the LFS book.
179 xsltproc --nonet --xinclude --stringparam testsuite $TEST -o ./commands/ \
180 $XSL lfs-$LFSVRS/index.xml >>$LOGDIR/$LOG 2>&1
181
182 # Grab the patches and package names.
183 cd $JHALFSDIR
184 for i in patches packages ; do rm -f $i ; done
185 grep "\-version" lfs-$LFSVRS/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
186 -e '/generic/d' >> packages
187 grep "ENTITY" lfs-$LFSVRS/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
188
189 # Done. Moving on...
190 echo -ne "done\n"
191 get_sources
192}
193
194download() {
195 cd $BUILDDIR/sources
196
197 # Hackish fix for the bash-doc package that doesn't conform
198 # to norms in the URL scheme.
199 DIR=`echo $1 | sed 's@-doc@@'`
200
201 # Find the md5 sum for this package.
202 if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
203
204 if [ ! -f $2 ] ; then
205 case $DL in
206 wget )
207 wget $HTTP/$DIR/$2
208 ;;
209 curl )
210 `curl -# $HTTP/$DIR/$2 -o $2`
211 ;;
212 * )
213 echo "$DL not supported at this time."
214 ;;
215 esac
216 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
217 case $DL in
218 wget )
219 wget -c $HTTP/$DIR/$2
220 ;;
221 curl )
222 `curl -# -C - $HTTP/$DIR/$2 -o $2`
223 ;;
224 * )
225 echo "$DL not supported at this time."
226 ;;
227 esac
228 fi
229 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
230 exit 1
231 fi
232}
233
234get_sources() {
235
236 # Test if the packages must be downloaded
237 if [ "$HPKG" = "1" ] ; then
238
239 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
240 # separates each iteration by lines. It is necessary to have the second
241 # ' on the next line.
242 IFS='
243'
244
245 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
246 cd $BUILDDIR/sources
247 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
248
249 download "" MD5SUMS
250
251 # Iterate through each package and grab it, along with any patches it needs.
252 for i in `cat $JHALFSDIR/packages` ; do
253 PKG=`echo $i | sed 's/-version.*//'`
254
255 # Someone used some silly entities right next to the valid package entities.
256 if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
257
258 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
259 if [ "$PKG" = "tcl" ] ; then
260 FILE="$PKG$VRS-src.tar.bz2"
261 else
262 FILE="$PKG-$VRS.tar.bz2"
263 fi
264 download $PKG $FILE
265 for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
266 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
267 download $PKG $PATCH
268 done
269 done
270 fi
271}
272
273build_Makefile() {
274 echo -n "Creating Makefile... "
275 cd $JHALFSDIR/commands
276
277 # Start with a clean Makefile.tmp file
278 >$MKFILE.tmp
279
280 for file in chapter05/* ; do
281 # Keep the script file name
282 i=`basename $file`
283
284 # First append each name of the script files to a list (this will become
285 # the names of the targets in the Makefile
286 chapter5="$chapter5 $i"
287
288 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
289 # and binutils in chapter 5)
290 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
291
292 # Drop in the name of the target on a new line.
293 echo -e "\n$i:" >> $MKFILE.tmp
294
295 # Find the version of the command files, if it corresponds with the building of
296 # a specific package
297 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
298
299 # If $vrs isn't empty, we've got a package...
300 if [ "$vrs" != "" ] ; then
301 if [ "$name" = "tcl" ] ; then
302 FILE="$name$vrs-src.tar.bz2"
303 else
304 FILE="$name-$vrs.tar.bz2"
305 fi
306
307 # Insert instructions for unpacking the package and to set
308 # the PKGDIR variable.
309 echo -e "\t\$(call unpack-lfs,$FILE)" >> $MKFILE.tmp
310 echo -e "\t-ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
311 echo -e "\tchown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
312 echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
313 echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
314 fi
315
316 # Dump the path to the Binutils or TCL sources directory.
317 if [ "$i" = "027-binutils-pass1" -o "$i" = "032-tcl" -o "$i" = "036-binutils-pass2" ] ; then
318 echo -e "\techo \"\$(LFS)\$(SRC)/\$\$ROOT\" > sources-dir && \\" >> $MKFILE.tmp
319 fi
320
321 # Inser date and disk usage at the top of the log file.
322 echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >\$(LOGDIR)/$i && \\" >> $MKFILE.tmp
323
324 # For the Adjusting phase we must to cd to the binutils-build directory.
325 if [ "$i" = "031-adjusting" ] ; then
326 echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/binutils-build\" > envars && \\" >> $MKFILE.tmp
327 echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
328 fi
329
330 # For the Exp0ect build we need to set the TCLPATH envar.
331 if [ "$i" = "033-expect" ] ; then
332 echo -e "\techo \"TCLPATH=\`cat sources-dir\`\" >> envars && \\" >> $MKFILE.tmp
333 echo -e "\techo \"export TCLPATH\" >> envars && \\" >> $MKFILE.tmp
334 fi
335
336 # Insert the script run
337 echo -e "\tsu - lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" >>\$(LOGDIR)/$i 2>&1 && \\" >> $MKFILE.tmp
338
339 # Inser date and disk usage at the bottom of the log file.
340 echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >>\$(LOGDIR)/$i && \\" >> $MKFILE.tmp
341
342 # Include a touch of the target name so make can check
343 # if it's already been made.
344 echo -e "\ttouch \$@" >> $MKFILE.tmp
345
346 # Remove the build directory(ies) even if the package build fails, except for
347 # Binutils and TCL. In that cases the sources directories are removed
348 # only if the build fails.
349 if [ "$vrs" != "" ] ; then
350 if [ "$i" != "027-binutils-pass1" ] && [ "$i" != "032-tcl" ] && [ "$i" != "036-binutils-pass2" ] ; then
351 echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
352 echo -e "\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
353 echo -e "\tif [ -e \$(LFS)\$(SRC)/$name-build ]; then \\" >> $MKFILE.tmp
354 echo -e "\t\trm -r \$(LFS)\$(SRC)/$name-build; \\" >> $MKFILE.tmp
355 echo -e "\tfi;" >> $MKFILE.tmp
356 fi
357 fi
358 if [ "$i" = "027-binutils-pass1" -o "$i" = "036-binutils-pass2" ] ; then
359 echo -e "\tif [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
360 echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
361 echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
362 echo -e "\t\trm -r \$(LFS)\$(SRC)/binutils-build; \\" >> $MKFILE.tmp
363 echo -e "\tfi;" >> $MKFILE.tmp
364 fi
365 if [ "$i" = "032-tcl" ] ; then
366 echo -e "\tif [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
367 echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
368 echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT; \\" >> $MKFILE.tmp
369 echo -e "\tfi;" >> $MKFILE.tmp
370 fi
371
372 # Remove the Binutils pass 1 sources after a sucessfull Adjusting phase.
373 if [ "$i" = "031-adjusting" ] ; then
374 echo -e "\tif [ -e \$@ ] ; then \\" >> $MKFILE.tmp
375 echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
376 echo -e "\t\trm -r \$(LFS)\$(SRC)/binutils-build && \\" >> $MKFILE.tmp
377 echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
378 echo -e "\tfi;" >> $MKFILE.tmp
379 fi
380
381 # Remove the TCL sources after a sucessfull Expect build.
382 if [ "$i" = "033-expect" ] ; then
383 echo -e "\tif [ -e \$@ ] ; then \\" >> $MKFILE.tmp
384 echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
385 echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
386 echo -e "\tfi;" >> $MKFILE.tmp
387 fi
388
389 # Check if the package has been sucessfully build.
390 echo -e "\tif [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
391 echo -e "\t\techo \"The build of \$@ has failed\" && exit 1; \\" >> $MKFILE.tmp
392 echo -e "\tfi;" >> $MKFILE.tmp
393 done
394
395 # Stick variables and some defines at the top of the real makefile
396 echo "export SRC := /sources" > $MKFILE
397 echo "export LFS := $BUILDDIR" >> $MKFILE
398 echo -e "export LOGDIR := $LOGDIR\n" >> $MKFILE
399 echo "define unpack-lfs" >> $MKFILE
400 echo -e "\t@cd \$(LFS)\$(SRC) ; tar -xvjf \$(1) > /tmp/unpacked" >> $MKFILE
401 echo -e "endef\n" >> $MKFILE
402 echo "define unpack" >> $MKFILE
403 echo -e "\t@cd \$(SRC) ; tar -xvf \$(1) > /tmp/unpacked" >> $MKFILE
404 echo -e "endef\n" >> $MKFILE
405
406 # Drop in the main target 'all:' and the chapter targets with each sub-target
407 # as a dependency.
408 echo -e "all: chapter4 chapter5\n" >> $MKFILE
409 echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
410 echo -e "chapter5: chapter4 $chapter5\n" >> $MKFILE
411
412 # Clean targets
413 echo "clean-all: clean" >> $MKFILE
414 echo -e "\trm -rfv ./*\n" >> $MKFILE
415
416 echo -e "clean: clean-chapter5 clean-chapter4\n" >> $MKFILE
417
418 echo "clean-chapter4:" >> $MKFILE
419 echo -e "\t-userdel lfs" >> $MKFILE
420 echo -e "\trm -rfv /home/lfs" >> $MKFILE
421 echo -e "\trm -rfv \$(LFS)/tools" >> $MKFILE
422 echo -e "\trm -fv /tools" >> $MKFILE
423 echo -e "\trm -fv envars" >> $MKFILE
424 echo -e "\trm -fv 02* logs/02*.log\n" >> $MKFILE
425
426 echo "clean-chapter5:" >> $MKFILE
427 echo -e "\trm -rfv \$(LFS)/tools/*" >> $MKFILE
428 echo -e "\trm -fv envars" >> $MKFILE
429 echo -e "\trm -fv $chapter5" >> $MKFILE
430 echo -e "\tcd logs && rm -fv $chapter5 && cd ..\n" >> $MKFILE
431
432 # The chapter4 sub-targets are hard-coded to can create the lfs user,
433 # to make the scripts executables, and to create a clean environment
434 # for the lfs user.
435 echo "020-creatingtoolsdir:" >> $MKFILE
436 echo -e "\tmkdir -v \$(LFS)/tools && \\" >> $MKFILE
437 echo -e "\tln -sv \$(LFS)/tools / && \\" >> $MKFILE
438 echo -e "\ttouch \$@\n" >> $MKFILE
439
440 echo "021-addinguser:" >> $MKFILE
441 echo -e "\tgroupadd lfs && \\" >> $MKFILE
442 echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
443 echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
444 echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
445 # Make the scripts executables
446 echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
447 echo -e "\ttouch \$@\n" >> $MKFILE
448
449 echo "022-settingenvironment:" >> $MKFILE
450 echo -e "\techo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
451 echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
452 echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
453 echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
454 echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
455 echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
456 echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
457 # Source the file where we place changing variables.
458 echo -e "\techo \". $JHALFSDIR/envars\" >> /home/lfs/.bashrc && \\" >> $MKFILE
459 echo -e "\tchown lfs:lfs /home/lfs/.bash* && \\" >> $MKFILE
460 echo -e "\ttouch envars && \\" >> $MKFILE
461 echo -e "\ttouch \$@" >> $MKFILE
462
463 # Bring over the items from the Makefile.tmp
464 cat $MKFILE.tmp >> $MKFILE
465 rm $MKFILE.tmp
466 echo -ne "done\n"
467}
468
469run_make() {
470 # Test if make must be run.
471 if [ "$RUNMAKE" = "1" ] ; then
472 # Build the system
473 if [ -e $MKFILE ] ; then
474 echo -ne "Building the LFS system\n"
475 cd $JHALFSDIR && make
476 echo -ne "done\n"
477 fi
478 fi
479}
480
481if [ ! -d $JHALFSDIR ] ; then
482 mkdir -p $JHALFSDIR
483fi
484
485if [ ! -d $LOGDIR ] ; then
486 mkdir $LOGDIR
487fi
488
489>$LOGDIR/$LOG
490
491if [ "$PWD" != "$JHALFSDIR" ] ; then
492 cp $0 $XSL $JHALFSDIR/
493fi
494
495get_book
496build_Makefile
497run_make
Note: See TracBrowser for help on using the repository browser.