source: jhalfs@ 48d7968

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

Make LFS a variable make understands and add a switch to allow user to specify

  • Property mode set to 100755
File size: 8.0 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
[48d7968]17 -d --directory=DIR use DIR directory for building LFS; all files
18 jhalfs produces will be in the directory
19 DIR/jhalfs
[1236262]20 -D, --download-client=CLIENT use CLIENT as the program for retrieving
21 packages
22"
23
24help="\
25Try '$0 --help' for more information."
26
27exit_missing_arg="\
28echo \"Option '\$1' requires an argument\" >&2
29echo \"\$help\" >&2
30exit 1"
31
32no_dl_client="\
33echo \"Could not find a way to download the LFS sources.\" >&2
34echo \"Attempting to continue.\" >&2"
35
36while test $# -gt 0 ; do
37 case $1 in
38 --version | -V )
39 echo "$version"
40 exit 0
41 ;;
42
43 --help | -h )
44 echo "$usage"
45 exit 0
46 ;;
47
48 --LFS-version | -L )
49 test $# = 1 && eval "$exit_missing_arg"
50 shift
51 case $1 in
52 dev* | SVN | trunk )
53 LFSVRS=development
54 ;;
55 * )
56 echo "$1 is an unsupported version at this time."
57 exit 1
58 ;;
59 esac
60 shift
61 ;;
62
[48d7968]63 --directory | -d )
64 test $# = 1 && eval "$exit_missing_arg"
65 shift
66 BUILDDIR=$1
67 shift
68 ;;
69
[1236262]70 --download-client | -D )
71 test $# = 1 && eval "$exit_missing_arg"
72 shift
73 DL=$1
74 shift
75 ;;
76
77 * )
78 echo "$usage"
79 exit 1
80 ;;
81 esac
82done
83
84# Test to make sure we're running the build as root
85
86if [ "$UID" != "0" ] ; then
87 echo "You must be logged in as root to successfully build LFS."
88 exit 1
89fi
90
91# Find the download client to use, if not already specified.
92
93if [ -z $DL ] ; then
94 if [ `type -p wget` ] ; then
95 DL=wget
96 elif [ `type -p curl` ] ; then
97 DL=curl
98 else
99 eval "$no_dl_client"
100 fi
101fi
102
103SVN="svn://svn.linuxfromscratch.org"
104HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
[48d7968]105if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
[4dafc45]106JHALFSDIR=$BUILDDIR/jhalfs
[1236262]107LOG=build.log
[f8de156]108MKFILE=$JHALFSDIR/Makefile
[1236262]109
110get_book() {
111 # Check for Subversion instead of just letting the script hit 'svn' and fail.
112 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
113 exit 1"
[4dafc45]114 cd $JHALFSDIR
[1236262]115
116 # Test to make sure the LFS version is set
117 if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
118 echo -n "Downloading the LFS Book, version $LFSVRS... "
119
120 # Grab the LFS book fresh if it's missing, otherwise, update it from the
121 # repo. If we've already extracted the commands, move on to getting the
122 # sources.
123 if [ -d lfs-$LFSVRS ] ; then
124 cd lfs-$LFSVRS
[4dafc45]125 if svn up | grep -q At && test -d $JHALFSDIR/commands && \
126 test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
[1236262]127 echo -ne "done\n"
128 get_sources
129 else
130 echo -ne "done\n"
131 extract_commands
132 fi
133 else
134 if [ $LFSVRS = development ] ; then
[4dafc45]135 svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
[1236262]136 else
[4dafc45]137 svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
[1236262]138 fi
139 echo -ne "done\n"
140 extract_commands
141 fi
142}
143
144extract_commands() {
145 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
146 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
147 exit 1"
[4dafc45]148 cd $JHALFSDIR
[1236262]149
150 # Start clean
151 if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
152 echo -n "Extracting commands... "
153
154 # Use Maneul's stylesheet to dump the commands in text form from the LFS book.
155 xsltproc -v --nonet --xinclude -o ./commands/ \
156 lfs-$LFSVRS/stylesheets/dump-commands.xsl lfs-$LFSVRS/index.xml \
[4dafc45]157 >>$JHALFSDIR/$LOG 2>&1
[1236262]158
159 # Move the text files out from the chapter directories, and dump them
160 # all into the 'commands' directory.
161 cd commands
162 find ./* -xtype f -exec mv '{}' . \;
163 find ./* -maxdepth 0 -xtype d -exec rm -rf '{}' \;
164
[f8de156]165 # Remove all the blank lines from the commands
166 for i in $JHALFSDIR/commands/* ; do
167 sed -i '/^$/d' $i
168 done
169
[1236262]170 # Grab the patches and package names.
[4dafc45]171 cd $JHALFSDIR
[1236262]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
[f8de156]224 # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
[1236262]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.
[4dafc45]237 for i in `cat $JHALFSDIR/packages` ; do
[1236262]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
[4dafc45]250 for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
[1236262]251 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
252 download $PKG $PATCH
253 done
254 done
255}
256
[f8de156]257build_Makefile() {
258 cd $JHALFSDIR/commands
259
260 # Start with a clean Makefile.tmp file
261 >$MKFILE.tmp
262
263 for i in * ; do
264 # First append each name of the command files to a list (this will become the names
265 # of the targets in the Makefile
266 list="$list $i"
267
268 # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
269 # and binutils in chapter 5)
270 name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
271
272 # Drop in the name of the target on a new line.
273 echo -e "\n$i:" >> $MKFILE.tmp
274
275 # Find the version of the command files, if it corresponds with the building of
276 # a specific package
277 vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
278
279 # If $vrs isn't empty, we've got a package...
280 if [ "$vrs" != "" ] ; then
281 if [ "$name" = "tcl" ] ; then
282 FILE="$name$vrs-src.tar.bz2"
283 else
284 FILE="$name-$vrs.tar.bz2"
285 fi
286
287 # Insert instructions for unpacking the package and changing directories
288 echo -e "\t\$(call unpack,$FILE)" >> $MKFILE.tmp
289 echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
290 echo -e "\tcd \$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
291 fi
292
293 # Drop in the actual commands that were parsed from the book
[e2caf6f]294 cat $i | sed -e 's:\$:&&:g' -e 's:^:\t:' -e 's:[^\\]$:& \&\& \\:' >> $MKFILE.tmp
[48d7968]295 sed -i -e '$s: \&\& \\::' $MKFILE.tmp -e 's|\$\$LFS|\$(LFS)|' $MKFILE.tmp
[f8de156]296
297 # Include a touch of the target name so make can check if it's already been made.
298 echo -e "\ttouch \$@" >> $MKFILE.tmp
299 done
300
301 # Stick a variable and some defines at the top of the real makefile
302 echo "export SRC := /sources" > $MKFILE
[48d7968]303 echo "export LFS := $BUILDDIR" >> $MKFILE
[f8de156]304 echo "define unpack" >> $MKFILE
305 echo -e "\t@cd \$(SRC) ; tar -xvf \$(1) > /tmp/unpacked" >> $MKFILE
306 echo -e "endef\n" >> $MKFILE
307
308 # Drop in the list as the main target 'all:' with each sub-target as a dependency.
309 echo "all: $list" >> $MKFILE
310
311 # Bring over the items from the Makefile.tmp
312 cat $MKFILE.tmp >> $MKFILE
313 rm $MKFILE.tmp
314}
315
[1236262]316
[4dafc45]317if [ ! -d $JHALFSDIR ] ; then
318 mkdir -p $JHALFSDIR
[1236262]319fi
320
[4dafc45]321>$JHALFSDIR/$LOG
322cp $0 $JHALFSDIR/
[1236262]323get_book
[f8de156]324build_Makefile
Note: See TracBrowser for help on using the repository browser.