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 |
|
---|
19 | -V, --version print version number, then exit
|
---|
20 |
|
---|
21 | -d --directory=DIR use DIR directory for building LFS; all files
|
---|
22 | jhalfs produces will be in the directory
|
---|
23 | DIR/jhalfs
|
---|
24 |
|
---|
25 | -P, --get-packages download the packages and patches
|
---|
26 |
|
---|
27 | -D, --download-client=CLIENT use CLIENT as the program for retrieving
|
---|
28 | packages (for use in conjunction with -P)
|
---|
29 |
|
---|
30 | -W, --working-copy=DIR use the local working copy placed in DIR
|
---|
31 | as the LFS book
|
---|
32 |
|
---|
33 | -L, --LFS-version=VER ckeckout VER version of the LFS book
|
---|
34 |
|
---|
35 | -T, --testsuites add support to run the optional testsuites
|
---|
36 |
|
---|
37 | -M, --run-make run make on the generated Makefile
|
---|
38 | "
|
---|
39 |
|
---|
40 | help="\
|
---|
41 | Try '$0 --help' for more information."
|
---|
42 |
|
---|
43 | exit_missing_arg="\
|
---|
44 | echo \"Option '\$1' requires an argument\" >&2
|
---|
45 | echo \"\$help\" >&2
|
---|
46 | exit 1"
|
---|
47 |
|
---|
48 | no_dl_client="\
|
---|
49 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
50 | echo \"Attempting to continue.\" >&2"
|
---|
51 |
|
---|
52 | while test $# -gt 0 ; do
|
---|
53 | case $1 in
|
---|
54 | --version | -V )
|
---|
55 | echo "$version"
|
---|
56 | exit 0
|
---|
57 | ;;
|
---|
58 |
|
---|
59 | --help | -h )
|
---|
60 | echo "$usage"
|
---|
61 | exit 0
|
---|
62 | ;;
|
---|
63 |
|
---|
64 | --LFS-version | -L )
|
---|
65 | test $# = 1 && eval "$exit_missing_arg"
|
---|
66 | shift
|
---|
67 | case $1 in
|
---|
68 | dev* | SVN | trunk )
|
---|
69 | LFSVRS=development
|
---|
70 | ;;
|
---|
71 | * )
|
---|
72 | echo "$1 is an unsupported version at this time."
|
---|
73 | exit 1
|
---|
74 | ;;
|
---|
75 | esac
|
---|
76 | shift
|
---|
77 | ;;
|
---|
78 |
|
---|
79 | --directory | -d )
|
---|
80 | test $# = 1 && eval "$exit_missing_arg"
|
---|
81 | shift
|
---|
82 | BUILDDIR=$1
|
---|
83 | shift
|
---|
84 | ;;
|
---|
85 |
|
---|
86 | --download-client | -D )
|
---|
87 | test $# = 1 && eval "$exit_missing_arg"
|
---|
88 | shift
|
---|
89 | DL=$1
|
---|
90 | shift
|
---|
91 | ;;
|
---|
92 |
|
---|
93 | --working-copy | -W )
|
---|
94 | test $# = 1 && eval "$exit_missing_arg"
|
---|
95 | shift
|
---|
96 | WC=1
|
---|
97 | BOOK=$1
|
---|
98 | shift
|
---|
99 | ;;
|
---|
100 |
|
---|
101 | --testsuites | -T )
|
---|
102 | TEST=1
|
---|
103 | shift
|
---|
104 | ;;
|
---|
105 |
|
---|
106 | --get-packages | -P )
|
---|
107 | HPKG=1
|
---|
108 | shift
|
---|
109 | ;;
|
---|
110 |
|
---|
111 | --run-make | -M )
|
---|
112 | RUNMAKE=1
|
---|
113 | shift
|
---|
114 | ;;
|
---|
115 |
|
---|
116 | * )
|
---|
117 | echo "$usage"
|
---|
118 | exit 1
|
---|
119 | ;;
|
---|
120 | esac
|
---|
121 | done
|
---|
122 |
|
---|
123 | # Test to make sure we're running the build as root
|
---|
124 |
|
---|
125 | if [ "$UID" != "0" ] ; then
|
---|
126 | echo "You must be logged in as root to successfully build LFS."
|
---|
127 | exit 1
|
---|
128 | fi
|
---|
129 |
|
---|
130 | # Find the download client to use, if not already specified.
|
---|
131 |
|
---|
132 | if [ -z $DL ] ; then
|
---|
133 | if [ `type -p wget` ] ; then
|
---|
134 | DL=wget
|
---|
135 | elif [ `type -p curl` ] ; then
|
---|
136 | DL=curl
|
---|
137 | else
|
---|
138 | eval "$no_dl_client"
|
---|
139 | fi
|
---|
140 | fi
|
---|
141 |
|
---|
142 | SVN="svn://svn.linuxfromscratch.org"
|
---|
143 | HTTP=http://ftp.lfs-matrix.net/pub/lfs/lfs-packages/conglomeration
|
---|
144 | if [ -z $BUILDDIR ] ; then BUILDDIR=/mnt/lfs ; fi
|
---|
145 | JHALFSDIR=$BUILDDIR/jhalfs
|
---|
146 | LOGDIR=/jhalfs/logs
|
---|
147 | LOG=000-jhalfs.log
|
---|
148 | MKFILE=$JHALFSDIR/Makefile
|
---|
149 | XSL=dump-lfs-scripts.xsl
|
---|
150 | if [ -z $TEST ] ; then TEST=0 ; fi
|
---|
151 |
|
---|
152 | get_book() {
|
---|
153 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
154 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
155 | exit 1"
|
---|
156 | cd $JHALFSDIR
|
---|
157 |
|
---|
158 | # Test to make sure the LFS version is set
|
---|
159 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
160 |
|
---|
161 | # Set the book's sources directory
|
---|
162 | if [ -z $BOOK ] ; then BOOK=lfs-$LFSVRS ; fi
|
---|
163 |
|
---|
164 | if [ -z $WC ] ; then
|
---|
165 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
166 |
|
---|
167 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
168 | # repo. If we've already extracted the commands, move on to getting the
|
---|
169 | # sources.
|
---|
170 | if [ -d lfs-$LFSVRS ] ; then
|
---|
171 | cd lfs-$LFSVRS
|
---|
172 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
173 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
174 | echo -ne "done\n"
|
---|
175 | get_sources
|
---|
176 | else
|
---|
177 | echo -ne "done\n"
|
---|
178 | extract_commands
|
---|
179 | fi
|
---|
180 | else
|
---|
181 | if [ $LFSVRS = development ] ; then
|
---|
182 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$BUILDDIR$LOGDIR/$LOG 2>&1
|
---|
183 | else
|
---|
184 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$BUILDDIR$LOGDIR/$LOG 2>&1
|
---|
185 | fi
|
---|
186 | echo -ne "done\n"
|
---|
187 | extract_commands
|
---|
188 | fi
|
---|
189 | else
|
---|
190 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
191 | extract_commands
|
---|
192 | fi
|
---|
193 | }
|
---|
194 |
|
---|
195 | extract_commands() {
|
---|
196 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
197 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
198 | exit 1"
|
---|
199 | cd $JHALFSDIR
|
---|
200 |
|
---|
201 | # Start clean
|
---|
202 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
203 | echo -n "Extracting commands... "
|
---|
204 |
|
---|
205 | # Dump the commands in shell script form from the LFS book.
|
---|
206 | xsltproc --nonet --xinclude --stringparam testsuite $TEST -o ./commands/ \
|
---|
207 | $XSL $BOOK/index.xml >>$BUILDDIR$LOGDIR/$LOG 2>&1
|
---|
208 |
|
---|
209 | # Grab the patches and package names.
|
---|
210 | cd $JHALFSDIR
|
---|
211 | for i in patches packages ; do rm -f $i ; done
|
---|
212 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
213 | -e '/generic/d' >> packages
|
---|
214 | grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
215 |
|
---|
216 | # Done. Moving on...
|
---|
217 | echo -ne "done\n"
|
---|
218 | get_sources
|
---|
219 | }
|
---|
220 |
|
---|
221 | download() {
|
---|
222 | cd $BUILDDIR/sources
|
---|
223 |
|
---|
224 | # Hackish fix for the bash-doc package that doesn't conform
|
---|
225 | # to norms in the URL scheme.
|
---|
226 | DIR=`echo $1 | sed 's@-doc@@'`
|
---|
227 |
|
---|
228 | # Find the md5 sum for this package.
|
---|
229 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
230 |
|
---|
231 | if [ ! -f $2 ] ; then
|
---|
232 | case $DL in
|
---|
233 | wget )
|
---|
234 | wget $HTTP/$DIR/$2
|
---|
235 | ;;
|
---|
236 | curl )
|
---|
237 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
238 | ;;
|
---|
239 | * )
|
---|
240 | echo "$DL not supported at this time."
|
---|
241 | ;;
|
---|
242 | esac
|
---|
243 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
244 | case $DL in
|
---|
245 | wget )
|
---|
246 | wget -c $HTTP/$DIR/$2
|
---|
247 | ;;
|
---|
248 | curl )
|
---|
249 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
250 | ;;
|
---|
251 | * )
|
---|
252 | echo "$DL not supported at this time."
|
---|
253 | ;;
|
---|
254 | esac
|
---|
255 | fi
|
---|
256 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
257 | exit 1
|
---|
258 | fi
|
---|
259 | }
|
---|
260 |
|
---|
261 | get_sources() {
|
---|
262 |
|
---|
263 | # Test if the packages must be downloaded
|
---|
264 | if [ "$HPKG" = "1" ] ; then
|
---|
265 |
|
---|
266 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
267 | # separates each iteration by lines. It is necessary to have the second
|
---|
268 | # ' on the next line.
|
---|
269 | IFS='
|
---|
270 | '
|
---|
271 |
|
---|
272 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
273 | cd $BUILDDIR/sources
|
---|
274 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
275 |
|
---|
276 | download "" MD5SUMS
|
---|
277 |
|
---|
278 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
279 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
280 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
281 |
|
---|
282 | # Someone used some silly entities right next to the valid package entities.
|
---|
283 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" ] ; then continue ; fi
|
---|
284 |
|
---|
285 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
286 | if [ "$PKG" = "tcl" ] ; then
|
---|
287 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
288 | else
|
---|
289 | FILE="$PKG-$VRS.tar.bz2"
|
---|
290 | fi
|
---|
291 | download $PKG $FILE
|
---|
292 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
293 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
294 | download $PKG $PATCH
|
---|
295 | done
|
---|
296 | done
|
---|
297 | fi
|
---|
298 | }
|
---|
299 |
|
---|
300 | build_Makefile() {
|
---|
301 | echo -n "Creating Makefile... "
|
---|
302 | cd $JHALFSDIR/commands
|
---|
303 |
|
---|
304 | # Start with a clean Makefile.tmp file
|
---|
305 | >$MKFILE.tmp
|
---|
306 |
|
---|
307 | for file in chapter05/* ; do
|
---|
308 | # Keep the script file name
|
---|
309 | i=`basename $file`
|
---|
310 |
|
---|
311 | # First append each name of the script files to a list (this will become
|
---|
312 | # the names of the targets in the Makefile
|
---|
313 | chapter5="$chapter5 $i"
|
---|
314 |
|
---|
315 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
316 | # and binutils in chapter 5)
|
---|
317 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
318 |
|
---|
319 | # Set the dependency for the first target.
|
---|
320 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
321 |
|
---|
322 | # Drop in the name of the target on a new line, and the previous target
|
---|
323 | # as a dependency.
|
---|
324 | echo -e "\n$i: $PREV" >> $MKFILE.tmp
|
---|
325 |
|
---|
326 | # Find the version of the command files, if it corresponds with the building of
|
---|
327 | # a specific package
|
---|
328 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
329 |
|
---|
330 | # If $vrs isn't empty, we've got a package...
|
---|
331 | if [ "$vrs" != "" ] ; then
|
---|
332 | if [ "$name" = "tcl" ] ; then
|
---|
333 | FILE="$name$vrs-src.tar.bz2"
|
---|
334 | else
|
---|
335 | FILE="$name-$vrs.tar.bz2"
|
---|
336 | fi
|
---|
337 |
|
---|
338 | # Insert instructions for unpacking the package and to set
|
---|
339 | # the PKGDIR variable.
|
---|
340 | echo -e "\t\$(call unpack-lfs,$FILE)" >> $MKFILE.tmp
|
---|
341 | echo -e "\t-ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
342 | echo -e "\tchown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
343 | echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
|
---|
344 | echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
|
---|
345 | fi
|
---|
346 |
|
---|
347 | # Dump the path to the Binutils pass1 or TCL sources directory.
|
---|
348 | if [ "$i" = "027-binutils-pass1" -o "$i" = "032-tcl" ] ; then
|
---|
349 | echo -e "\techo \"\$(LFS)\$(SRC)/\$\$ROOT\" > sources-dir && \\" >> $MKFILE.tmp
|
---|
350 | fi
|
---|
351 |
|
---|
352 | # Dump the path to the Binutils pass2 sources directory.
|
---|
353 | if [ "$i" = "036-binutils-pass2" ] ; then
|
---|
354 | echo -e "\techo \"\$(SRC)/\$\$ROOT\" > sources-dir && \\" >> $MKFILE.tmp
|
---|
355 | fi
|
---|
356 |
|
---|
357 | # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
358 | if [ "$i" = "031-adjusting" ] ; then
|
---|
359 | echo -e "\techo \"PKGDIR=\$(LFS)\$(SRC)/binutils-build\" > envars && \\" >> $MKFILE.tmp
|
---|
360 | echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
|
---|
361 | fi
|
---|
362 |
|
---|
363 | # For the Expect build we need to set the TCLPATH envar.
|
---|
364 | if [ "$i" = "033-expect" ] ; then
|
---|
365 | echo -e "\techo \"TCLPATH=\`cat sources-dir\`\" >> envars && \\" >> $MKFILE.tmp
|
---|
366 | echo -e "\techo \"export TCLPATH\" >> envars && \\" >> $MKFILE.tmp
|
---|
367 | fi
|
---|
368 |
|
---|
369 | # Inser date and disk usage at the top of the log file.
|
---|
370 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >\$(LFS)\$(LOGDIR)/$i && \\" >> $MKFILE.tmp
|
---|
371 |
|
---|
372 | # Insert the script run
|
---|
373 | echo -e "\tsu - lfs -c \". /home/lfs/.bashrc && $JHALFSDIR/commands/$file\" >>\$(LFS)\$(LOGDIR)/$i 2>&1 && \\" >> $MKFILE.tmp
|
---|
374 |
|
---|
375 | # Inser date and disk usage at the bottom of the log file.
|
---|
376 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >>\$(LFS)\$(LOGDIR)/$i && \\" >> $MKFILE.tmp
|
---|
377 |
|
---|
378 | # Include a touch of the target name so make can check
|
---|
379 | # if it's already been made.
|
---|
380 | echo -e "\ttouch \$@" >> $MKFILE.tmp
|
---|
381 |
|
---|
382 | # Remove the build directory(ies) even if the package build fails, except for
|
---|
383 | # Binutils and TCL. In that cases the sources directories are removed
|
---|
384 | # only if the build fails.
|
---|
385 | if [ "$vrs" != "" ] ; then
|
---|
386 | if [ "$i" != "027-binutils-pass1" ] && [ "$i" != "032-tcl" ] && [ "$i" != "036-binutils-pass2" ] ; then
|
---|
387 | echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
388 | echo -e "\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
389 | echo -e "\tif [ -e \$(LFS)\$(SRC)/$name-build ]; then \\" >> $MKFILE.tmp
|
---|
390 | echo -e "\t\trm -r \$(LFS)\$(SRC)/$name-build; \\" >> $MKFILE.tmp
|
---|
391 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
392 | fi
|
---|
393 | fi
|
---|
394 | if [ "$i" = "027-binutils-pass1" -o "$i" = "036-binutils-pass2" ] ; then
|
---|
395 | echo -e "\tif [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
396 | echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
397 | echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
398 | echo -e "\t\trm -r \$(LFS)\$(SRC)/binutils-build; \\" >> $MKFILE.tmp
|
---|
399 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
400 | fi
|
---|
401 | if [ "$i" = "032-tcl" ] ; then
|
---|
402 | echo -e "\tif [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
403 | echo -e "\t\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
404 | echo -e "\t\trm -r \$(LFS)\$(SRC)/\$\$ROOT; \\" >> $MKFILE.tmp
|
---|
405 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
406 | fi
|
---|
407 |
|
---|
408 | # Remove the Binutils pass 1 sources after a sucessfull Adjusting phase.
|
---|
409 | if [ "$i" = "031-adjusting" ] ; then
|
---|
410 | echo -e "\tif [ -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
411 | echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
|
---|
412 | echo -e "\t\trm -r \$(LFS)\$(SRC)/binutils-build && \\" >> $MKFILE.tmp
|
---|
413 | echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
|
---|
414 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
415 | fi
|
---|
416 |
|
---|
417 | # Remove the TCL sources after a sucessfull Expect build.
|
---|
418 | if [ "$i" = "033-expect" ] ; then
|
---|
419 | echo -e "\tif [ -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
420 | echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
|
---|
421 | echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
|
---|
422 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
423 | fi
|
---|
424 |
|
---|
425 | # Check if the package has been sucessfully build.
|
---|
426 | echo -e "\tif [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
427 | echo -e "\t\techo \"The build of \$@ has failed\" && exit 1; \\" >> $MKFILE.tmp
|
---|
428 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
429 |
|
---|
430 | # Keep the script file name for Makefile dependencies.
|
---|
431 | PREV=$i
|
---|
432 | done
|
---|
433 |
|
---|
434 | for file in chapter06/* ; do
|
---|
435 | # Keep the script file name
|
---|
436 | i=`basename $file`
|
---|
437 |
|
---|
438 | # First append each name of the script files to a list (this will become
|
---|
439 | # the names of the targets in the Makefile
|
---|
440 | chapter6="$chapter6 $i"
|
---|
441 |
|
---|
442 | # Grab the name of the target
|
---|
443 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
|
---|
444 |
|
---|
445 | # Set the dependency for the first target.
|
---|
446 | if [ -z $PREV ] ; then PREV=055-stripping ; fi
|
---|
447 |
|
---|
448 | # Drop in the name of the target on a new line, and the previous target
|
---|
449 | # as a dependency.
|
---|
450 | echo -e "\n$i: $PREV" >> $MKFILE.tmp
|
---|
451 |
|
---|
452 | # Find the version of the command files, if it corresponds with the building of
|
---|
453 | # a specific package
|
---|
454 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
455 |
|
---|
456 | # If $vrs isn't empty, we've got a package...
|
---|
457 | if [ "$vrs" != "" ] ; then
|
---|
458 | FILE="$name-$vrs.tar.bz2"
|
---|
459 |
|
---|
460 | # Insert instructions for unpacking the package and changing directories
|
---|
461 | echo -e "\t\$(call unpack,$FILE)" >> $MKFILE.tmp
|
---|
462 | echo -e "\t-ROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
463 | echo -e "\techo \"PKGDIR=\$(SRC)/\$\$ROOT\" > envars && \\" >> $MKFILE.tmp
|
---|
464 | echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
|
---|
465 | fi
|
---|
466 |
|
---|
467 | # For the mount of kernel filesystems we need to set LFS.
|
---|
468 | if [ "$i" = "057-kernfs" ] ; then
|
---|
469 | echo -e "\techo \"LFS=\$(LFS)\" > envars && \\" >> $MKFILE.tmp
|
---|
470 | echo -e "\techo \"export LFS\" >> envars && \\" >> $MKFILE.tmp
|
---|
471 | fi
|
---|
472 |
|
---|
473 | # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
474 | if [ "$i" = "067-readjusting" ] ; then
|
---|
475 | echo -e "\techo \"PKGDIR=\$(SRC)/binutils-build\" > envars && \\" >> $MKFILE.tmp
|
---|
476 | echo -e "\techo \"export PKGDIR\" >> envars && \\" >> $MKFILE.tmp
|
---|
477 | fi
|
---|
478 |
|
---|
479 | # Inser date and disk usage at the top of the log file.
|
---|
480 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* /\`\\\n\" >\$(LOGDIR)/$i && \\" >> $MKFILE.tmp
|
---|
481 |
|
---|
482 | # Insert the script run
|
---|
483 | echo -e "\t. envars && commands/$file >>\$(LOGDIR)/$i 2>&1 && \\" >> $MKFILE.tmp
|
---|
484 |
|
---|
485 | # Inser date and disk usage at the bottom of the log file.
|
---|
486 | echo -e "\techo -e \"\\\n\`date\`\\\n\\\nKB: \`du -sk --exclude=0??-* \$(LFS)\`\\\n\" >>\$(LOGDIR)/$i && \\" >> $MKFILE.tmp
|
---|
487 |
|
---|
488 | # Include a touch of the target name so make can check
|
---|
489 | # if it's already been made.
|
---|
490 | echo -e "\ttouch \$@" >> $MKFILE.tmp
|
---|
491 |
|
---|
492 | # Remove the build directory(ies) even if the package build fails.
|
---|
493 | if [ "$vrs" != "" ] ; then
|
---|
494 | echo -e "\tROOT=\`head -n1 /tmp/unpacked | sed 's@/.*@@'\` && \\" >> $MKFILE.tmp
|
---|
495 | echo -e "\trm -r \$(SRC)/\$\$ROOT && \\" >> $MKFILE.tmp
|
---|
496 | echo -e "\tif [ -e \$(SRC)/$name-build ]; then \\" >> $MKFILE.tmp
|
---|
497 | echo -e "\t\trm -r \$(SRC)/$name-build; \\" >> $MKFILE.tmp
|
---|
498 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
499 | fi
|
---|
500 |
|
---|
501 | # Remove the Binutils pass 2 sources after a sucessfull Re-Adjusting phase.
|
---|
502 | if [ "$i" = "067-readjusting" ] ; then
|
---|
503 | echo -e "\tif [ -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
504 | echo -e "\t\trm -r \`cat sources-dir\` && \\" >> $MKFILE.tmp
|
---|
505 | echo -e "\t\trm -r \$(SRC)/binutils-build && \\" >> $MKFILE.tmp
|
---|
506 | echo -e "\t\trm sources-dir; \\" >> $MKFILE.tmp
|
---|
507 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
508 | fi
|
---|
509 |
|
---|
510 | # Check if the package has been sucessfully build.
|
---|
511 | echo -e "\tif [ ! -e \$@ ] ; then \\" >> $MKFILE.tmp
|
---|
512 | echo -e "\t\techo \"The build of \$@ has failed\" && exit 1; \\" >> $MKFILE.tmp
|
---|
513 | echo -e "\tfi;" >> $MKFILE.tmp
|
---|
514 |
|
---|
515 | # Keep the script file name for Makefile dependencies.
|
---|
516 | PREV=$i
|
---|
517 | done
|
---|
518 |
|
---|
519 | # Stick variables and some defines at the top of the real makefile
|
---|
520 | echo "export SRC := /sources" > $MKFILE
|
---|
521 | echo "export LFS := $BUILDDIR" >> $MKFILE
|
---|
522 | echo -e "export LOGDIR := $LOGDIR\n" >> $MKFILE
|
---|
523 | echo "define unpack-lfs" >> $MKFILE
|
---|
524 | echo -e "\t@cd \$(LFS)\$(SRC) ; tar -xvjf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
525 | echo -e "endef\n" >> $MKFILE
|
---|
526 | echo "define unpack" >> $MKFILE
|
---|
527 | echo -e "\t@cd \$(SRC) ; tar -xvf \$(1) > /tmp/unpacked" >> $MKFILE
|
---|
528 | echo -e "endef\n" >> $MKFILE
|
---|
529 |
|
---|
530 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
531 | # as a dependency.
|
---|
532 | echo "all: chapter4 chapter5" >> $MKFILE
|
---|
533 | echo -e "\techo -e \"\\\n\\\tYour new LFS system has been sucessfully build\"\n" >> $MKFILE
|
---|
534 | echo -e "chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment\n" >> $MKFILE
|
---|
535 | echo -e "chapter5: chapter4 $chapter5\n" >> $MKFILE >> $MKFILE
|
---|
536 | echo -e "chapter6: chapter5 $chapter6\n" >> $MKFILE
|
---|
537 |
|
---|
538 | # Clean targets
|
---|
539 | echo "clean-all: clean" >> $MKFILE
|
---|
540 | echo -e "\trm -rfv ./*\n" >> $MKFILE
|
---|
541 |
|
---|
542 | echo -e "clean: clean-chapter5 clean-chapter4\n" >> $MKFILE
|
---|
543 |
|
---|
544 | echo "clean-chapter4:" >> $MKFILE
|
---|
545 | echo -e "\t-userdel lfs" >> $MKFILE
|
---|
546 | echo -e "\trm -rfv /home/lfs" >> $MKFILE
|
---|
547 | echo -e "\trm -rfv \$(LFS)/tools" >> $MKFILE
|
---|
548 | echo -e "\trm -fv /tools" >> $MKFILE
|
---|
549 | echo -e "\trm -fv envars" >> $MKFILE
|
---|
550 | echo -e "\trm -fv 02* logs/02*.log\n" >> $MKFILE
|
---|
551 |
|
---|
552 | echo "clean-chapter5:" >> $MKFILE
|
---|
553 | echo -e "\trm -rfv \$(LFS)/tools/*" >> $MKFILE
|
---|
554 | echo -e "\trm -fv envars" >> $MKFILE
|
---|
555 | echo -e "\trm -fv $chapter5" >> $MKFILE
|
---|
556 | echo -e "\tcd logs && rm -fv $chapter5 && cd ..\n" >> $MKFILE
|
---|
557 |
|
---|
558 | # The chapter4 sub-targets are hard-coded to can create the lfs user,
|
---|
559 | # to make the scripts executables, and to create a clean environment
|
---|
560 | # for the lfs user.
|
---|
561 | echo "020-creatingtoolsdir:" >> $MKFILE
|
---|
562 | echo -e "\tmkdir -v \$(LFS)/tools && \\" >> $MKFILE
|
---|
563 | echo -e "\tln -sv \$(LFS)/tools / && \\" >> $MKFILE
|
---|
564 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
565 |
|
---|
566 | echo "021-addinguser: 020-creatingtoolsdir" >> $MKFILE
|
---|
567 | echo -e "\tgroupadd lfs && \\" >> $MKFILE
|
---|
568 | echo -e "\tuseradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\" >> $MKFILE
|
---|
569 | echo -e "\tchown lfs \$(LFS)/tools && \\" >> $MKFILE
|
---|
570 | echo -e "\tchown lfs \$(LFS)/sources && \\" >> $MKFILE
|
---|
571 | # Make the scripts executables
|
---|
572 | echo -e "\tchmod -R +x $JHALFSDIR/commands && \\" >> $MKFILE
|
---|
573 | echo -e "\ttouch \$@\n" >> $MKFILE
|
---|
574 |
|
---|
575 | echo "022-settingenvironment: 021-addinguser" >> $MKFILE
|
---|
576 | echo -e "\techo \"exec env -i HOME=\\\$\$HOME TERM=\\\$\$TERM PS1='\u:\w\$$ ' /bin/bash\" > /home/lfs/.bash_profile && \\" >> $MKFILE
|
---|
577 | echo -e "\techo \"set +h\" > /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
578 | echo -e "\techo \"umask 022\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
579 | echo -e "\techo \"LFS=/mnt/lfs\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
580 | echo -e "\techo \"LC_ALL=POSIX\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
581 | echo -e "\techo \"PATH=/tools/bin:/bin:/usr/bin\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
582 | echo -e "\techo \"export LFS LC_ALL PATH\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
583 | # Source the file where we place changing variables.
|
---|
584 | echo -e "\techo \". $JHALFSDIR/envars\" >> /home/lfs/.bashrc && \\" >> $MKFILE
|
---|
585 | echo -e "\tchown lfs:lfs /home/lfs/.bash* && \\" >> $MKFILE
|
---|
586 | echo -e "\ttouch envars && \\" >> $MKFILE
|
---|
587 | echo -e "\ttouch \$@" >> $MKFILE
|
---|
588 |
|
---|
589 | # Bring over the items from the Makefile.tmp
|
---|
590 | cat $MKFILE.tmp >> $MKFILE
|
---|
591 | rm $MKFILE.tmp
|
---|
592 | echo -ne "done\n"
|
---|
593 | }
|
---|
594 |
|
---|
595 | run_make() {
|
---|
596 | # Test if make must be run.
|
---|
597 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
598 | # Build the system
|
---|
599 | if [ -e $MKFILE ] ; then
|
---|
600 | echo -ne "Building the LFS system\n"
|
---|
601 | cd $JHALFSDIR && make
|
---|
602 | echo -ne "done\n"
|
---|
603 | fi
|
---|
604 | fi
|
---|
605 | }
|
---|
606 |
|
---|
607 | if [ ! -d $JHALFSDIR ] ; then
|
---|
608 | mkdir -p $JHALFSDIR
|
---|
609 | fi
|
---|
610 |
|
---|
611 | if [ ! -d $BUILDDIR$LOGDIR ] ; then
|
---|
612 | mkdir $BUILDDIR$LOGDIR
|
---|
613 | fi
|
---|
614 |
|
---|
615 | >$BUILDDIR$LOGDIR/$LOG
|
---|
616 |
|
---|
617 | if [ "$PWD" != "$JHALFSDIR" ] ; then
|
---|
618 | cp $0 $XSL $JHALFSDIR/
|
---|
619 | fi
|
---|
620 |
|
---|
621 | get_book
|
---|
622 | build_Makefile
|
---|
623 | run_make
|
---|