source: jhalfs@ 07f47df

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

Added switch to skipp packages dowload.

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