source: jhalfs@ c355ad1

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

Added support to run the optional testsuites.

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