1 | #!/bin/sh
|
---|
2 |
|
---|
3 | version="
|
---|
4 | jhalfs development
|
---|
5 |
|
---|
6 | 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 | "
|
---|
26 |
|
---|
27 | help="\
|
---|
28 | Try '$0 --help' for more information."
|
---|
29 |
|
---|
30 | exit_missing_arg="\
|
---|
31 | echo \"Option '\$1' requires an argument\" >&2
|
---|
32 | echo \"\$help\" >&2
|
---|
33 | exit 1"
|
---|
34 |
|
---|
35 | no_dl_client="\
|
---|
36 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
37 | echo \"Attempting to continue.\" >&2"
|
---|
38 |
|
---|
39 | while test $# -gt 0 ; do
|
---|
40 | case $1 in
|
---|
41 | --version | -V )
|
---|
42 | echo "$version"
|
---|
43 | exit 0
|
---|
44 | ;;
|
---|
45 |
|
---|
46 | --help | -h )
|
---|
47 | echo "$usage"
|
---|
48 | exit 0
|
---|
49 | ;;
|
---|
50 |
|
---|
51 | --LFS-version | -L )
|
---|
52 | test $# = 1 && eval "$exit_missing_arg"
|
---|
53 | shift
|
---|
54 | case $1 in
|
---|
55 | dev* | SVN | trunk )
|
---|
56 | LFSVRS=development
|
---|
57 | ;;
|
---|
58 | * )
|
---|
59 | echo "$1 is an unsupported version at this time."
|
---|
60 | exit 1
|
---|
61 | ;;
|
---|
62 | esac
|
---|
63 | shift
|
---|
64 | ;;
|
---|
65 |
|
---|
66 | --directory | -d )
|
---|
67 | test $# = 1 && eval "$exit_missing_arg"
|
---|
68 | shift
|
---|
69 | BUILDDIR=$1
|
---|
70 | shift
|
---|
71 | ;;
|
---|
72 |
|
---|
73 | --download-client | -D )
|
---|
74 | test $# = 1 && eval "$exit_missing_arg"
|
---|
75 | shift
|
---|
76 | DL=$1
|
---|
77 | shift
|
---|
78 | ;;
|
---|
79 |
|
---|
80 | * )
|
---|
81 | echo "$usage"
|
---|
82 | exit 1
|
---|
83 | ;;
|
---|
84 | esac
|
---|
85 | done
|
---|
86 |
|
---|
87 | # Test to make sure we're running the build as root
|
---|
88 |
|
---|
89 | if [ "$UID" != "0" ] ; then
|
---|
90 | echo "You must be logged in as root to successfully build LFS."
|
---|
91 | exit 1
|
---|
92 | fi
|
---|
93 |
|
---|
94 | # Find the download client to use, if not already specified.
|
---|
95 |
|
---|
96 | if [ -z $DL ] ; then
|
---|
97 | if [ `type -p wget` ] ; then
|
---|
98 | DL=wget
|
---|
99 | elif [ `type -p curl` ] ; then
|
---|
100 | DL=curl
|
---|
101 | else
|
---|
102 | eval "$no_dl_client"
|
---|
103 | fi
|
---|
104 | fi
|
---|
105 |
|
---|
106 | SVN="svn://svn.linuxfromscratch.org"
|
---|
107 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
108 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
109 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
110 | LOG=build.log
|
---|
111 | MKFILE=$JHALFSDIR/Makefile
|
---|
112 | XSL=dump-commands.xsl
|
---|
113 |
|
---|
114 | get_book() {
|
---|
115 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
116 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
117 | exit 1"
|
---|
118 | cd $JHALFSDIR
|
---|
119 |
|
---|
120 | # Test to make sure the LFS version is set
|
---|
121 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
122 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
123 |
|
---|
124 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
125 | # repo. If we've already extracted the commands, move on to getting the
|
---|
126 | # sources.
|
---|
127 | if [ -d lfs-$LFSVRS ] ; then
|
---|
128 | cd lfs-$LFSVRS
|
---|
129 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
130 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
131 | echo -ne "done\n"
|
---|
132 | get_sources
|
---|
133 | else
|
---|
134 | echo -ne "done\n"
|
---|
135 | extract_commands
|
---|
136 | fi
|
---|
137 | else
|
---|
138 | if [ $LFSVRS = development ] ; then
|
---|
139 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
140 | else
|
---|
141 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$JHALFSDIR/$LOG 2>&1
|
---|
142 | fi
|
---|
143 | echo -ne "done\n"
|
---|
144 | extract_commands
|
---|
145 | fi
|
---|
146 | }
|
---|
147 |
|
---|
148 | extract_commands() {
|
---|
149 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
150 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
151 | exit 1"
|
---|
152 | cd $JHALFSDIR
|
---|
153 |
|
---|
154 | # Start clean
|
---|
155 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
156 | echo -n "Extracting commands... "
|
---|
157 |
|
---|
158 | # Dump the commands in shell script form from the LFS book.
|
---|
159 | xsltproc --nonet --xinclude -o ./commands/ $XSL \
|
---|
160 | lfs-$LFSVRS/index.xml >>$JHALFSDIR/$LOG 2>&1
|
---|
161 |
|
---|
162 | # Grab the patches and package names.
|
---|
163 | cd $JHALFSDIR
|
---|
164 | for i in patches packages ; do rm -f $i ; done
|
---|
165 | grep "\-version" lfs-$LFSVRS/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
166 | -e '/generic/d' >> packages
|
---|
167 | grep "ENTITY" lfs-$LFSVRS/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
168 |
|
---|
169 | # Done. Moving on...
|
---|
170 | echo -ne "done\n"
|
---|
171 | get_sources
|
---|
172 | }
|
---|
173 |
|
---|
174 | download() {
|
---|
175 | cd $BUILDDIR/sources
|
---|
176 |
|
---|
177 | # Hackish fix for the bash-doc package that doesn't conform
|
---|
178 | # to norms in the URL scheme.
|
---|
179 | DIR=`echo $1 | sed 's@-doc@@'`
|
---|
180 |
|
---|
181 | # Find the md5 sum for this package.
|
---|
182 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
183 |
|
---|
184 | if [ ! -f $2 ] ; then
|
---|
185 | case $DL in
|
---|
186 | wget )
|
---|
187 | wget $HTTP/$DIR/$2
|
---|
188 | ;;
|
---|
189 | curl )
|
---|
190 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
191 | ;;
|
---|
192 | * )
|
---|
193 | echo "$DL not supported at this time."
|
---|
194 | ;;
|
---|
195 | esac
|
---|
196 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
197 | case $DL in
|
---|
198 | wget )
|
---|
199 | wget -c $HTTP/$DIR/$2
|
---|
200 | ;;
|
---|
201 | curl )
|
---|
202 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
203 | ;;
|
---|
204 | * )
|
---|
205 | echo "$DL not supported at this time."
|
---|
206 | ;;
|
---|
207 | esac
|
---|
208 | fi
|
---|
209 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
210 | exit 1
|
---|
211 | fi
|
---|
212 | }
|
---|
213 |
|
---|
214 | get_sources() {
|
---|
215 |
|
---|
216 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
217 | # separates each iteration by lines. It is necessary to have the second
|
---|
218 | # ' on the next line.
|
---|
219 | IFS='
|
---|
220 | '
|
---|
221 |
|
---|
222 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
223 | cd $BUILDDIR/sources
|
---|
224 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
225 |
|
---|
226 | download "" MD5SUMS
|
---|
227 |
|
---|
228 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
229 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
230 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
231 |
|
---|
232 | # Someone used some silly entities right next to the valid package entities.
|
---|
233 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
234 |
|
---|
235 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
236 | if [ "$PKG" = "tcl" ] ; then
|
---|
237 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
238 | else
|
---|
239 | FILE="$PKG-$VRS.tar.bz2"
|
---|
240 | fi
|
---|
241 | download $PKG $FILE
|
---|
242 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
243 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
244 | download $PKG $PATCH
|
---|
245 | done
|
---|
246 | done
|
---|
247 | }
|
---|
248 |
|
---|
249 | build_Makefile() {
|
---|
250 | echo -n "Creating Makefile... "
|
---|
251 | cd $JHALFSDIR/commands
|
---|
252 |
|
---|
253 | # Start with a clean Makefile.tmp file
|
---|
254 | >$MKFILE.tmp
|
---|
255 |
|
---|
256 | for file in chapter05/* ; do
|
---|
257 | # Keep the script file name
|
---|
258 | i=`basename $file`
|
---|
259 |
|
---|
260 | # First append each name of the script files to a list (this will become
|
---|
261 | # the names of the targets in the Makefile
|
---|
262 | chapter5="$chapter5 $i"
|
---|
263 |
|
---|
264 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
265 | # and binutils in chapter 5)
|
---|
266 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
267 |
|
---|
268 | # Drop in the name of the target on a new line.
|
---|
269 | echo -e "\n$i:" >> $MKFILE.tmp
|
---|
270 |
|
---|
271 | # Find the version of the command files, if it corresponds with the building of
|
---|
272 | # a specific package
|
---|
273 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
274 |
|
---|
275 | # If $vrs isn't empty, we've got a package...
|
---|
276 | if [ "$vrs" != "" ] ; then
|
---|
277 | if [ "$name" = "tcl" ] ; then
|
---|
278 | FILE="$name$vrs-src.tar.bz2"
|
---|
279 | else
|
---|
280 | FILE="$name-$vrs.tar.bz2"
|
---|
281 | fi
|
---|
282 |
|
---|
283 | # Insert instructions for unpacking the package and changing directories
|
---|
284 | echo -e "\t\$(call unpack-lfs,$FILE) && \\" >> $MKFILE.tmp
|
---|
285 | echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
286 | echo -e "\tcd \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
287 | fi
|
---|
288 |
|
---|
289 | # Insert the script run
|
---|
290 | echo -e "\tsu lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" && \\" >> $MKFILE.tmp
|
---|
291 |
|
---|
292 | # Include a touch of the target name so make can check if it's already been made.
|
---|
293 | echo -e "\ttouch \$@" >> $MKFILE.tmp
|
---|
294 | done
|
---|
295 |
|
---|
296 | # Stick a variable and some defines at the top of the real makefile
|
---|
297 | echo "export SRC := /sources" > $MKFILE
|
---|
298 | echo "export LFS := $BUILDDIR" >> $MKFILE
|
---|
299 | echo "define unpack-lfs" >> $MKFILE
|
---|
300 | echo -e "\t@cd \$(LFS)\$(SRC) ; tar -xvjf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
301 | echo -e "endef\n" >> $MKFILE
|
---|
302 | echo "define unpack" >> $MKFILE
|
---|
303 | echo -e "\t@cd \$(SRC) ; tar -xvf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
304 | echo -e "endef\n" >> $MKFILE
|
---|
305 |
|
---|
306 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
307 | # as a dependency.
|
---|
308 | echo -e "all: chapter4 chapter5\n" >> $MKFILE
|
---|
309 | echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
|
---|
310 | echo -e "chapter5: $chapter5\n" >> $MKFILE
|
---|
311 |
|
---|
312 | # Clean targets
|
---|
313 | echo "clean-chapter4:" >> $MKFILE
|
---|
314 | echo -e "\tuserdel lfs && \\" >> $MKFILE
|
---|
315 | echo -e "\trm -r /home/lfs && \\" >> $MKFILE
|
---|
316 | echo -e "\trm -r \$(LFS)/tools && \\" >> $MKFILE
|
---|
317 | echo -e "\trm /tools" >> $MKFILE
|
---|
318 | echo -e "\trm $JHALFSDIR/02*\n" >> $MKFILE
|
---|
319 |
|
---|
320 | # The chapter4 sub-targets are hard-coded to can create the lfs user and
|
---|
321 | # environment, and to make the scripts executables (as part of 021-addinguser).
|
---|
322 | echo "020-creatingtoolsdir:" >> $MKFILE
|
---|
323 | echo -e "\tmkdir \$(LFS)/tools && \\" >> $MKFILE
|
---|
324 | echo -e "\tln -s \$(LFS)/tools / && \\" >> $MKFILE
|
---|
325 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
326 |
|
---|
327 | echo "021-addinguser:" >> $MKFILE
|
---|
328 | echo -e "\tgroupadd lfs && \\" >> $MKFILE
|
---|
329 | echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
|
---|
330 | echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
|
---|
331 | echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
|
---|
332 | # Make the scripts executables
|
---|
333 | echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
|
---|
334 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
335 |
|
---|
336 | echo "022-settingenvironment:" >> $MKFILE
|
---|
337 | echo -e "\techo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
|
---|
338 | echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
339 | echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
340 | echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
341 | echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
342 | echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
343 | echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
344 | echo -e "\tchown lfs /home/lfs/.bash* && \\" >> $MKFILE
|
---|
345 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
346 |
|
---|
347 |
|
---|
348 | # Bring over the items from the Makefile.tmp
|
---|
349 | cat $MKFILE.tmp >> $MKFILE
|
---|
350 | rm $MKFILE.tmp
|
---|
351 | echo -ne "done\n"
|
---|
352 | }
|
---|
353 |
|
---|
354 |
|
---|
355 | if [ ! -d $JHALFSDIR ] ; then
|
---|
356 | mkdir -p $JHALFSDIR
|
---|
357 | fi
|
---|
358 |
|
---|
359 | >$JHALFSDIR/$LOG
|
---|
360 |
|
---|
361 | if [ "$PWD" != "$JHALFSDIR" ] ; then
|
---|
362 | cp $0 $XSL $JHALFSDIR/
|
---|
363 | fi
|
---|
364 |
|
---|
365 | get_book
|
---|
366 | build_Makefile
|
---|