1 | #!/bin/sh
|
---|
2 |
|
---|
3 | version="
|
---|
4 | jhalfs 0.1
|
---|
5 | Written by Jeremy Huntwork.
|
---|
6 |
|
---|
7 | This program is published under the \
|
---|
8 | Gnu General Public License, Version 2."
|
---|
9 |
|
---|
10 | usage="\
|
---|
11 | Usage: $0 [OPTION]
|
---|
12 |
|
---|
13 | Options:
|
---|
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 --directory=DIR use DIR directory for building LFS; all files
|
---|
18 | jhalfs produces will be in the directory
|
---|
19 | DIR/jhalfs
|
---|
20 | -D, --download-client=CLIENT use CLIENT as the program for retrieving
|
---|
21 | packages
|
---|
22 | "
|
---|
23 |
|
---|
24 | help="\
|
---|
25 | Try '$0 --help' for more information."
|
---|
26 |
|
---|
27 | exit_missing_arg="\
|
---|
28 | echo \"Option '\$1' requires an argument\" >&2
|
---|
29 | echo \"\$help\" >&2
|
---|
30 | exit 1"
|
---|
31 |
|
---|
32 | no_dl_client="\
|
---|
33 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
34 | echo \"Attempting to continue.\" >&2"
|
---|
35 |
|
---|
36 | while 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 |
|
---|
63 | --directory | -d )
|
---|
64 | test $# = 1 && eval "$exit_missing_arg"
|
---|
65 | shift
|
---|
66 | BUILDDIR=$1
|
---|
67 | shift
|
---|
68 | ;;
|
---|
69 |
|
---|
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
|
---|
82 | done
|
---|
83 |
|
---|
84 | # Test to make sure we're running the build as root
|
---|
85 |
|
---|
86 | if [ "$UID" != "0" ] ; then
|
---|
87 | echo "You must be logged in as root to successfully build LFS."
|
---|
88 | exit 1
|
---|
89 | fi
|
---|
90 |
|
---|
91 | # Find the download client to use, if not already specified.
|
---|
92 |
|
---|
93 | if [ -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
|
---|
101 | fi
|
---|
102 |
|
---|
103 | SVN="svn://svn.linuxfromscratch.org"
|
---|
104 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
105 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
106 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
107 | LOG=build.log
|
---|
108 | MKFILE=$JHALFSDIR/Makefile
|
---|
109 |
|
---|
110 | get_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"
|
---|
114 | cd $JHALFSDIR
|
---|
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
|
---|
125 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
126 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
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
|
---|
135 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
136 | else
|
---|
137 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
138 | fi
|
---|
139 | echo -ne "done\n"
|
---|
140 | extract_commands
|
---|
141 | fi
|
---|
142 | }
|
---|
143 |
|
---|
144 | extract_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"
|
---|
148 | cd $JHALFSDIR
|
---|
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 \
|
---|
157 | >>$JHALFSDIR/$LOG 2>&1
|
---|
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 |
|
---|
165 | # Remove all the blank lines from the commands
|
---|
166 | for i in $JHALFSDIR/commands/* ; do
|
---|
167 | sed -i '/^$/d' $i
|
---|
168 | done
|
---|
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 |
|
---|
182 | download() {
|
---|
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 |
|
---|
222 | get_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 |
|
---|
257 | build_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
|
---|
294 | cat $i | sed -e 's:\$:&&:g' -e 's:^:\t:' -e 's:[^\\]$:& \&\& \\:' >> $MKFILE.tmp
|
---|
295 | sed -i -e '$s: \&\& \\::' $MKFILE.tmp -e 's|\$\$LFS|\$(LFS)|' $MKFILE.tmp
|
---|
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
|
---|
303 | echo "export LFS := $BUILDDIR" >> $MKFILE
|
---|
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 |
|
---|
316 |
|
---|
317 | if [ ! -d $JHALFSDIR ] ; then
|
---|
318 | mkdir -p $JHALFSDIR
|
---|
319 | fi
|
---|
320 |
|
---|
321 | >$JHALFSDIR/$LOG
|
---|
322 | cp $0 $JHALFSDIR/
|
---|
323 | get_book
|
---|
324 | build_Makefile
|
---|