source: jhalfs@ 4e5e9b4

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

Indentation clean-up.
Removed vervosity in xsltproc run.
Added dump-commands.xsl.

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