1 | #!/bin/sh
|
---|
2 |
|
---|
3 | version="
|
---|
4 | jhalfs development
|
---|
5 |
|
---|
6 | Originally written by Jeremy Huntwork.
|
---|
7 | Maintained by Manuel Canales Esparcia.
|
---|
8 |
|
---|
9 | This program is published under the \
|
---|
10 | Gnu General Public License, Version 2.
|
---|
11 | "
|
---|
12 |
|
---|
13 | usage="\
|
---|
14 | Usage: $0 [OPTION]
|
---|
15 |
|
---|
16 | Options:
|
---|
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 | -T, --no-testsuites don't run the package's testsuites.
|
---|
26 | "
|
---|
27 |
|
---|
28 | help="\
|
---|
29 | Try '$0 --help' for more information."
|
---|
30 |
|
---|
31 | exit_missing_arg="\
|
---|
32 | echo \"Option '\$1' requires an argument\" >&2
|
---|
33 | echo \"\$help\" >&2
|
---|
34 | exit 1"
|
---|
35 |
|
---|
36 | no_dl_client="\
|
---|
37 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
38 | echo \"Attempting to continue.\" >&2"
|
---|
39 |
|
---|
40 | while test $# -gt 0 ; do
|
---|
41 | case $1 in
|
---|
42 | --version | -V )
|
---|
43 | echo "$version"
|
---|
44 | exit 0
|
---|
45 | ;;
|
---|
46 |
|
---|
47 | --help | -h )
|
---|
48 | echo "$usage"
|
---|
49 | exit 0
|
---|
50 | ;;
|
---|
51 |
|
---|
52 | --LFS-version | -L )
|
---|
53 | test $# = 1 && eval "$exit_missing_arg"
|
---|
54 | shift
|
---|
55 | case $1 in
|
---|
56 | dev* | SVN | trunk )
|
---|
57 | LFSVRS=development
|
---|
58 | ;;
|
---|
59 | * )
|
---|
60 | echo "$1 is an unsupported version at this time."
|
---|
61 | exit 1
|
---|
62 | ;;
|
---|
63 | esac
|
---|
64 | shift
|
---|
65 | ;;
|
---|
66 |
|
---|
67 | --directory | -d )
|
---|
68 | test $# = 1 && eval "$exit_missing_arg"
|
---|
69 | shift
|
---|
70 | BUILDDIR=$1
|
---|
71 | shift
|
---|
72 | ;;
|
---|
73 |
|
---|
74 | --download-client | -D )
|
---|
75 | test $# = 1 && eval "$exit_missing_arg"
|
---|
76 | shift
|
---|
77 | DL=$1
|
---|
78 | shift
|
---|
79 | ;;
|
---|
80 |
|
---|
81 | --no-testsuites | -T )
|
---|
82 | shift
|
---|
83 | TEST=1
|
---|
84 | shift
|
---|
85 | ;;
|
---|
86 |
|
---|
87 | * )
|
---|
88 | echo "$usage"
|
---|
89 | exit 1
|
---|
90 | ;;
|
---|
91 | esac
|
---|
92 | done
|
---|
93 |
|
---|
94 | # Test to make sure we're running the build as root
|
---|
95 |
|
---|
96 | if [ "$UID" != "0" ] ; then
|
---|
97 | echo "You must be logged in as root to successfully build LFS."
|
---|
98 | exit 1
|
---|
99 | fi
|
---|
100 |
|
---|
101 | # Find the download client to use, if not already specified.
|
---|
102 |
|
---|
103 | if [ -z $DL ] ; then
|
---|
104 | if [ `type -p wget` ] ; then
|
---|
105 | DL=wget
|
---|
106 | elif [ `type -p curl` ] ; then
|
---|
107 | DL=curl
|
---|
108 | else
|
---|
109 | eval "$no_dl_client"
|
---|
110 | fi
|
---|
111 | fi
|
---|
112 |
|
---|
113 | SVN="svn://svn.linuxfromscratch.org"
|
---|
114 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
115 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
116 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
117 | LOG=build.log
|
---|
118 | MKFILE=$JHALFSDIR/Makefile
|
---|
119 | XSL=dump-commands.xsl
|
---|
120 | if [ -z $TEST ] ; then TEST=0 ; fi
|
---|
121 |
|
---|
122 | get_book() {
|
---|
123 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
124 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
125 | exit 1"
|
---|
126 | cd $JHALFSDIR
|
---|
127 |
|
---|
128 | # Test to make sure the LFS version is set
|
---|
129 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
130 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
131 |
|
---|
132 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
133 | # repo. If we've already extracted the commands, move on to getting the
|
---|
134 | # sources.
|
---|
135 | if [ -d lfs-$LFSVRS ] ; then
|
---|
136 | cd lfs-$LFSVRS
|
---|
137 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
138 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
139 | echo -ne "done\n"
|
---|
140 | get_sources
|
---|
141 | else
|
---|
142 | echo -ne "done\n"
|
---|
143 | extract_commands
|
---|
144 | fi
|
---|
145 | else
|
---|
146 | if [ $LFSVRS = development ] ; then
|
---|
147 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
148 | else
|
---|
149 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
150 | fi
|
---|
151 | echo -ne "done\n"
|
---|
152 | extract_commands
|
---|
153 | fi
|
---|
154 | }
|
---|
155 |
|
---|
156 | extract_commands() {
|
---|
157 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
158 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
159 | exit 1"
|
---|
160 | cd $JHALFSDIR
|
---|
161 |
|
---|
162 | # Start clean
|
---|
163 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
164 | echo -n "Extracting commands... "
|
---|
165 |
|
---|
166 | # Dump the commands in shell script form from the LFS book.
|
---|
167 | xsltproc --nonet --xinclude --stringparam testsuite $TEST -o ./commands/ \
|
---|
168 | $XSL lfs-$LFSVRS/index.xml >>$JHALFSDIR/$LOG 2>&1
|
---|
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 | echo -n "Creating Makefile... "
|
---|
259 | cd $JHALFSDIR/commands
|
---|
260 |
|
---|
261 | # Start with a clean Makefile.tmp file
|
---|
262 | >$MKFILE.tmp
|
---|
263 |
|
---|
264 | for file in chapter05/* ; do
|
---|
265 | # Keep the script file name
|
---|
266 | i=`basename $file`
|
---|
267 |
|
---|
268 | # First append each name of the script files to a list (this will become
|
---|
269 | # the names of the targets in the Makefile
|
---|
270 | chapter5="$chapter5 $i"
|
---|
271 |
|
---|
272 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
273 | # and binutils in chapter 5)
|
---|
274 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
275 |
|
---|
276 | # Drop in the name of the target on a new line.
|
---|
277 | echo -e "\n$i:" >> $MKFILE.tmp
|
---|
278 |
|
---|
279 | # Find the version of the command files, if it corresponds with the building of
|
---|
280 | # a specific package
|
---|
281 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
282 |
|
---|
283 | # If $vrs isn't empty, we've got a package...
|
---|
284 | if [ "$vrs" != "" ] ; then
|
---|
285 | if [ "$name" = "tcl" ] ; then
|
---|
286 | FILE="$name$vrs-src.tar.bz2"
|
---|
287 | else
|
---|
288 | FILE="$name-$vrs.tar.bz2"
|
---|
289 | fi
|
---|
290 |
|
---|
291 | # Insert instructions for unpacking the package and changing directories
|
---|
292 | echo -e "\t\$(call unpack-lfs,$FILE) && \\" >> $MKFILE.tmp
|
---|
293 | echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
294 | echo -e "\tchown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
295 | echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
|
---|
296 | echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
|
---|
297 | fi
|
---|
298 |
|
---|
299 | # Insert the script run
|
---|
300 | echo -e "\tsu - lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" && \\" >> $MKFILE.tmp
|
---|
301 |
|
---|
302 | # Include a touch of the target name so make can check
|
---|
303 | # if it's already been made.
|
---|
304 | echo -e "\ttouch \$@" >> $MKFILE.tmp
|
---|
305 |
|
---|
306 | # Remove the build directory(ies), including if the build has failed.
|
---|
307 | if [ "$vrs" != "" ] ; then
|
---|
308 | echo -e "\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
309 | echo -e "\tif [ -e \$(LFS)\$(SRC)/*-build ]; then \\" >> $MKFILE.tmp
|
---|
310 | echo -e "\t\t rm -r \$(LFS)\$(SRC)/*-build; \\" >> $MKFILE.tmp
|
---|
311 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
312 | fi
|
---|
313 |
|
---|
314 | done
|
---|
315 |
|
---|
316 | # Stick a variable and some defines at the top of the real makefile
|
---|
317 | echo "export SRC := /sources" > $MKFILE
|
---|
318 | echo "export LFS := $BUILDDIR" >> $MKFILE
|
---|
319 | echo "define unpack-lfs" >> $MKFILE
|
---|
320 | echo -e "\t@cd \$(LFS)\$(SRC) ; tar -xvjf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
321 | echo -e "endef\n" >> $MKFILE
|
---|
322 | echo "define unpack" >> $MKFILE
|
---|
323 | echo -e "\t@cd \$(SRC) ; tar -xvf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
324 | echo -e "endef\n" >> $MKFILE
|
---|
325 |
|
---|
326 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
327 | # as a dependency.
|
---|
328 | echo -e "all: chapter4 chapter5\n" >> $MKFILE
|
---|
329 | echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
|
---|
330 | echo -e "chapter5: $chapter5\n" >> $MKFILE
|
---|
331 |
|
---|
332 | # Clean targets
|
---|
333 | echo "clean: clean-chapter5 clean-chapter4" >> $MKFILE
|
---|
334 |
|
---|
335 | echo "clean-chapter4:" >> $MKFILE
|
---|
336 | echo -e "\tuserdel lfs && \\" >> $MKFILE
|
---|
337 | echo -e "\trm -r /home/lfs && \\" >> $MKFILE
|
---|
338 | echo -e "\trm -r \$(LFS)/tools && \\" >> $MKFILE
|
---|
339 | echo -e "\trm /tools" >> $MKFILE
|
---|
340 | echo -e "\trm 02*\n" >> $MKFILE
|
---|
341 |
|
---|
342 | echo "clean-chapter5:" >> $MKFILE
|
---|
343 | echo -e "\trm -r \$(LFS)/tools/* && \\" >> $MKFILE
|
---|
344 | echo -e "\trm -f $chapter5\n" >> $MKFILE
|
---|
345 |
|
---|
346 | # The chapter4 sub-targets are hard-coded to can create the lfs user,
|
---|
347 | # to make the scripts executables, and to create a clean environment
|
---|
348 | # for the lfs user.
|
---|
349 | echo "020-creatingtoolsdir:" >> $MKFILE
|
---|
350 | echo -e "\tmkdir \$(LFS)/tools && \\" >> $MKFILE
|
---|
351 | echo -e "\tln -s \$(LFS)/tools / && \\" >> $MKFILE
|
---|
352 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
353 |
|
---|
354 | echo "021-addinguser:" >> $MKFILE
|
---|
355 | echo -e "\tgroupadd lfs && \\" >> $MKFILE
|
---|
356 | echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
|
---|
357 | echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
|
---|
358 | echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
|
---|
359 | # Make the scripts executables
|
---|
360 | echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
|
---|
361 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
362 |
|
---|
363 | echo "022-settingenvironment:" >> $MKFILE
|
---|
364 | echo -e "\techo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
|
---|
365 | echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
366 | echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
367 | echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
368 | echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
369 | echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
370 | echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
371 | # Source the file where we place changing variables.
|
---|
372 | echo -e "\techo \". $JHALFSDIR/envars\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
373 | echo -e "\tchown lfs /home/lfs/.bash* && \\" >> $MKFILE
|
---|
374 | echo -e "\ttouch envars && \\" >> $MKFILE
|
---|
375 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
376 |
|
---|
377 |
|
---|
378 | # Bring over the items from the Makefile.tmp
|
---|
379 | cat $MKFILE.tmp >> $MKFILE
|
---|
380 | rm $MKFILE.tmp
|
---|
381 | echo -ne "done\n"
|
---|
382 | }
|
---|
383 |
|
---|
384 |
|
---|
385 | if [ ! -d $JHALFSDIR ] ; then
|
---|
386 | mkdir -p $JHALFSDIR
|
---|
387 | fi
|
---|
388 |
|
---|
389 | >$JHALFSDIR/$LOG
|
---|
390 |
|
---|
391 | if [ "$PWD" != "$JHALFSDIR" ] ; then
|
---|
392 | cp $0 $XSL $JHALFSDIR/
|
---|
393 | fi
|
---|
394 |
|
---|
395 | get_book
|
---|
396 | build_Makefile
|
---|