source: jhalfs@ a5e49c6

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

Added logging capabilities.

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