source: jhalfs@ 63b2859

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

Starting the move of some features to the XSL code.
First try to manage chapter05.

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