source: jhalfs@ 44f88e3

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

Be sure that a clean environmentis used for lfs user in chapter05.

  • Property mode set to 100755
File size: 11.4 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"
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
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
81 --no-testsuites | -T )
82 shift
83 TEST=1
84 shift
85 ;;
86
87 * )
88 echo "$usage"
89 exit 1
90 ;;
91 esac
92done
93
94# Test to make sure we're running the build as root
95
96if [ "$UID" != "0" ] ; then
97 echo "You must be logged in as root to successfully build LFS."
98 exit 1
99fi
100
101# Find the download client to use, if not already specified.
102
103if [ -z $DL ] ; then
104 if [ `type -p wget` ] ; then
105 DL=wget
106 elif [ `type -p curl` ] ; then
107 DL=curl
108 else
109 eval "$no_dl_client"
110 fi
111fi
112
113SVN="svn://svn.linuxfromscratch.org"
114HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
115if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
116JHALFSDIR=$BUILDDIR/jhalfs
117LOG=build.log
118MKFILE=$JHALFSDIR/Makefile
119XSL=dump-commands.xsl
120if [ -z $TEST ] ; then TEST=0 ; fi
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.\"
125 exit 1"
126 cd $JHALFSDIR
127
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
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
145 else
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
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.\"
159 exit 1"
160 cd $JHALFSDIR
161
162 # Start clean
163 if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
164 echo -n "Extracting commands... "
165
166 # Dump the commands in shell script form from the LFS book.
167 xsltproc --nonet --xinclude --stringparam testsuite $TEST -o ./commands/ \
168 $XSL lfs-$LFSVRS/index.xml >>$JHALFSDIR/$LOG 2>&1
169
170 # Grab the patches and package names.
171 cd $JHALFSDIR
172 for i in patches packages ; do rm -f $i ; done
173 grep "\-version" lfs-$LFSVRS/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
174 -e '/generic/d' >> packages
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
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
204 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
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
216 fi
217 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
218 exit 1
219 fi
220}
221
222get_sources() {
223
224 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
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.
237 for i in `cat $JHALFSDIR/packages` ; do
238 PKG=`echo $i | sed 's/-version.*//'`
239
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
245 FILE="$PKG$VRS-src.tar.bz2"
246 else
247 FILE="$PKG-$VRS.tar.bz2"
248 fi
249 download $PKG $FILE
250 for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
251 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
252 download $PKG $PATCH
253 done
254 done
255}
256
257build_Makefile() {
258 echo -n "Creating Makefile... "
259 cd $JHALFSDIR/commands
260
261 # Start with a clean Makefile.tmp file
262 >$MKFILE.tmp
263
264 for file in chapter05/* ; do
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
269 # the names of the targets in the Makefile
270 chapter5="$chapter5 $i"
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
292 echo -e "\t\$(call unpack-lfs,$FILE) && \\" >> $MKFILE.tmp
293 echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
294 echo -e "\tchown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
295 echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
296 echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
297 fi
298
299 # Insert the script run
300 echo -e "\tsu - lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" && \\" >> $MKFILE.tmp
301
302 # Include a touch of the target name so make can check
303 # if it's already been made.
304 echo -e "\ttouch \$@" >> $MKFILE.tmp
305
306 # Remove the build directory(ies), including if the build has failed.
307 if [ "$vrs" != "" ] ; then
308 echo -e "\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
309 echo -e "\tif [ -e \$(LFS)\$(SRC)/*-build ]; then \\" >> $MKFILE.tmp
310 echo -e "\t\t rm -r \$(LFS)\$(SRC)/*-build; \\" >> $MKFILE.tmp
311 echo -e "\tfi;" >> $MKFILE.tmp
312 fi
313
314 done
315
316 # Stick a variable and some defines at the top of the real makefile
317 echo "export SRC := /sources" > $MKFILE
318 echo "export LFS := $BUILDDIR" >> $MKFILE
319 echo "define unpack-lfs" >> $MKFILE
320 echo -e "\t@cd \$(LFS)\$(SRC) ; tar -xvjf \$(1) > /tmp/unpacked" >> $MKFILE
321 echo -e "endef\n" >> $MKFILE
322 echo "define unpack" >> $MKFILE
323 echo -e "\t@cd \$(SRC) ; tar -xvf \$(1) > /tmp/unpacked" >> $MKFILE
324 echo -e "endef\n" >> $MKFILE
325
326 # Drop in the main target 'all:' and the chapter targets with each sub-target
327 # as a dependency.
328 echo -e "all: chapter4 chapter5\n" >> $MKFILE
329 echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
330 echo -e "chapter5: $chapter5\n" >> $MKFILE
331
332 # Clean targets
333 echo "clean: clean-chapter5 clean-chapter4" >> $MKFILE
334
335 echo "clean-chapter4:" >> $MKFILE
336 echo -e "\tuserdel lfs && \\" >> $MKFILE
337 echo -e "\trm -r /home/lfs && \\" >> $MKFILE
338 echo -e "\trm -r \$(LFS)/tools && \\" >> $MKFILE
339 echo -e "\trm /tools" >> $MKFILE
340 echo -e "\trm 02*\n" >> $MKFILE
341
342 echo "clean-chapter5:" >> $MKFILE
343 echo -e "\trm -r \$(LFS)/tools/* && \\" >> $MKFILE
344 echo -e "\trm -f $chapter5\n" >> $MKFILE
345
346 # The chapter4 sub-targets are hard-coded to can create the lfs user,
347 # to make the scripts executables, and to create a clean environment
348 # for the lfs user.
349 echo "020-creatingtoolsdir:" >> $MKFILE
350 echo -e "\tmkdir \$(LFS)/tools && \\" >> $MKFILE
351 echo -e "\tln -s \$(LFS)/tools / && \\" >> $MKFILE
352 echo -e "\ttouch \$@\n" >> $MKFILE
353
354 echo "021-addinguser:" >> $MKFILE
355 echo -e "\tgroupadd lfs && \\" >> $MKFILE
356 echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
357 echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
358 echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
359 # Make the scripts executables
360 echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
361 echo -e "\ttouch \$@\n" >> $MKFILE
362
363 echo "022-settingenvironment:" >> $MKFILE
364 echo -e "\techo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
365 echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
366 echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
367 echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
368 echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
369 echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
370 echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
371 # Source the file where we place changing variables.
372 echo -e "\techo \". $JHALFSDIR/envars\" >> /home/lfs/.bashrc && \\" >> $MKFILE
373 echo -e "\tchown lfs /home/lfs/.bash* && \\" >> $MKFILE
374 echo -e "\ttouch envars && \\" >> $MKFILE
375 echo -e "\ttouch \$@\n" >> $MKFILE
376
377
378 # Bring over the items from the Makefile.tmp
379 cat $MKFILE.tmp >> $MKFILE
380 rm $MKFILE.tmp
381 echo -ne "done\n"
382}
383
384
385if [ ! -d $JHALFSDIR ] ; then
386 mkdir -p $JHALFSDIR
387fi
388
389>$JHALFSDIR/$LOG
390
391if [ "$PWD" != "$JHALFSDIR" ] ; then
392 cp $0 $XSL $JHALFSDIR/
393fi
394
395get_book
396build_Makefile
Note: See TracBrowser for help on using the repository browser.