source: jhalfs@ f8de156

0.2 1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since f8de156 was f8de156, checked in by Jeremy Huntwork <jhuntwork@…>, 19 years ago

Added a function to build a Makefile out of the extracted commands

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