1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Load the configuration file
|
---|
5 | #
|
---|
6 | . jhalfs.conf
|
---|
7 |
|
---|
8 |
|
---|
9 | version="
|
---|
10 | jhalfs development \$Date$
|
---|
11 |
|
---|
12 | Originally written by Jeremy Huntwork.
|
---|
13 | Maintained by Manuel Canales Esparcia.
|
---|
14 |
|
---|
15 | This program is published under the \
|
---|
16 | Gnu General Public License, Version 2.
|
---|
17 | "
|
---|
18 |
|
---|
19 | usage="\
|
---|
20 | Usage: $0 [OPTION]
|
---|
21 |
|
---|
22 | Options:
|
---|
23 | -h, --help print this help, then exit
|
---|
24 |
|
---|
25 | -V, --version print version number, then exit
|
---|
26 |
|
---|
27 | -d --directory DIR use DIR directory for building LFS; all files
|
---|
28 | jhalfs produces will be in the directory
|
---|
29 | DIR/jhalfs. Default is \"/mnt/lfs\".
|
---|
30 |
|
---|
31 | -P, --get-packages download the packages and patches
|
---|
32 |
|
---|
33 | -D, --download-client CLIENT use CLIENT as the program for retrieving
|
---|
34 | packages (for use in conjunction with -P)
|
---|
35 |
|
---|
36 | -W, --working-copy DIR use the local working copy placed in DIR
|
---|
37 | as the LFS book
|
---|
38 |
|
---|
39 | -L, --LFS-version VER ckeckout VER version of the LFS book.
|
---|
40 | Supported versions at this time are:
|
---|
41 |
|
---|
42 | dev* | trunk | SVN alias for Development LFS
|
---|
43 | testing | 6.1.1 alias for the testing 6.1.1 branch
|
---|
44 |
|
---|
45 | -T, --testsuites add support to run the optional testsuites
|
---|
46 |
|
---|
47 | --no-toolchain-test don't run the toolchain testsuites. This
|
---|
48 | disables also the build of TCL, Expect
|
---|
49 | and DejaGNU
|
---|
50 |
|
---|
51 | --timezone TIMEZONE set TIMEZONE as the local timezone. If not
|
---|
52 | specified, Europe/London will be used.
|
---|
53 |
|
---|
54 | --page_size PAGE set PAGE as the default page size (letter
|
---|
55 | or A4). This setting is required to
|
---|
56 | build Groff. If not specified, \"letter\"
|
---|
57 | will be used.
|
---|
58 |
|
---|
59 | --fstab FILE use FILE as the /etc/fstab file for the
|
---|
60 | LFS system. If not specified, a default
|
---|
61 | /etc/fstab file with dummy values is
|
---|
62 | created.
|
---|
63 |
|
---|
64 | -C, --kernel-config FILE use the kernel configuration file specified
|
---|
65 | in FILE to build the kernel. If not found,
|
---|
66 | the kernel build is skipped.
|
---|
67 |
|
---|
68 | -M, --run-make run make on the generated Makefile
|
---|
69 |
|
---|
70 | "
|
---|
71 |
|
---|
72 | help="\
|
---|
73 | Try '$0 --help' for more information."
|
---|
74 |
|
---|
75 | exit_missing_arg="\
|
---|
76 | echo \"Option '\$1' requires an argument\" >&2
|
---|
77 | echo \"\$help\" >&2
|
---|
78 | exit 1"
|
---|
79 |
|
---|
80 | no_dl_client="\
|
---|
81 | echo \"Could not find a way to download the LFS sources.\" >&2
|
---|
82 | echo \"Attempting to continue.\" >&2"
|
---|
83 |
|
---|
84 |
|
---|
85 | HEADER="# This file is automatically generated by jhalfs
|
---|
86 | # DO NOT EDIT THIS FILE MANUALLY
|
---|
87 | #
|
---|
88 | # Generated on `date \"+%F %X %Z\"`"
|
---|
89 |
|
---|
90 |
|
---|
91 | ###################################
|
---|
92 | ### FUNCTIONS ###
|
---|
93 | ###################################
|
---|
94 |
|
---|
95 |
|
---|
96 | #----------------------------#
|
---|
97 | get_book() {
|
---|
98 | #----------------------------#
|
---|
99 | # Check for Subversion instead of just letting the script hit 'svn' and fail.
|
---|
100 | test `type -p svn` || eval "echo \"This feature requires Subversion.\"
|
---|
101 | exit 1"
|
---|
102 | cd $JHALFSDIR
|
---|
103 |
|
---|
104 | # Test to make sure the LFS version is set
|
---|
105 | if [ -z $LFSVRS ] ; then LFSVRS=development ; fi
|
---|
106 |
|
---|
107 | # Set the book's sources directory
|
---|
108 | if [ -z $BOOK ] ; then BOOK=lfs-$LFSVRS ; fi
|
---|
109 |
|
---|
110 | if [ -z $WC ] ; then
|
---|
111 | echo -n "Downloading the LFS Book, version $LFSVRS... "
|
---|
112 |
|
---|
113 | # Grab the LFS book fresh if it's missing, otherwise, update it from the
|
---|
114 | # repo. If we've already extracted the commands, move on to getting the
|
---|
115 | # sources.
|
---|
116 | if [ -d lfs-$LFSVRS ] ; then
|
---|
117 | cd lfs-$LFSVRS
|
---|
118 | if svn up | grep -q At && test -d $JHALFSDIR/commands && \
|
---|
119 | test -f $JHALFSDIR/packages && test -f $JHALFSDIR/patches ; then
|
---|
120 | echo -ne "done\n"
|
---|
121 | get_sources
|
---|
122 | else
|
---|
123 | echo -ne "done\n"
|
---|
124 | extract_commands
|
---|
125 | fi
|
---|
126 | else
|
---|
127 | if [ $LFSVRS = development ] ; then
|
---|
128 | svn co $SVN/LFS/trunk/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
129 | else
|
---|
130 | svn co $SVN/LFS/branches/$LFSVRS/BOOK lfs-$LFSVRS >>$LOGDIR/$LOG 2>&1
|
---|
131 | fi
|
---|
132 | echo -ne "done\n"
|
---|
133 | extract_commands
|
---|
134 | fi
|
---|
135 | else
|
---|
136 | echo -ne "Using $BOOK as book's sources ...\n"
|
---|
137 | extract_commands
|
---|
138 | fi
|
---|
139 | # Set the canonical book version
|
---|
140 | cd $JHALFSDIR
|
---|
141 | VERSION=`grep "ENTITY version " $BOOK/general.ent | sed -e 's@<!ENTITY version "@@' -e 's@">@@'`
|
---|
142 | }
|
---|
143 |
|
---|
144 | #----------------------------#
|
---|
145 | extract_commands() {
|
---|
146 | #----------------------------#
|
---|
147 | # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
|
---|
148 | test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
|
---|
149 | exit 1"
|
---|
150 | cd $JHALFSDIR
|
---|
151 |
|
---|
152 | # Start clean
|
---|
153 | if [ -d commands ] ; then rm -rf commands ; fi && mkdir commands
|
---|
154 | echo -n "Extracting commands... "
|
---|
155 |
|
---|
156 | # Dump the commands in shell script form from the LFS book.
|
---|
157 | xsltproc --nonet --xinclude --stringparam testsuite $TEST \
|
---|
158 | --stringparam toolchaintest $TOOLCHAINTEST -o ./commands/ \
|
---|
159 | $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
|
---|
160 |
|
---|
161 | # Make the scripts executable.
|
---|
162 | chmod -R +x $JHALFSDIR/commands
|
---|
163 |
|
---|
164 | # Grab the patches and package names.
|
---|
165 | cd $JHALFSDIR
|
---|
166 | for i in patches packages ; do rm -f $i ; done
|
---|
167 | grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
|
---|
168 | -e '/generic/d' >> packages
|
---|
169 | echo `grep "glibc" packages | sed 's@glibc@glibc-linuxthreads@'` >> packages
|
---|
170 | # If we are buildind the UTF-8 branch, the glibc-libidn package is required
|
---|
171 | if grep -q "man-db-version" $BOOK/general.ent ; then
|
---|
172 | echo `grep "glibc" packages | sed 's@glibc@glibc-libidn@'` >> packages
|
---|
173 | fi
|
---|
174 | grep "ENTITY" $BOOK/patches.ent | sed -e 's/.* "//' -e 's/">//' >> patches
|
---|
175 |
|
---|
176 | # Done. Moving on...
|
---|
177 | echo -ne "done\n"
|
---|
178 | get_sources
|
---|
179 | }
|
---|
180 |
|
---|
181 | #----------------------------#
|
---|
182 | download() {
|
---|
183 | #----------------------------#
|
---|
184 | cd $BUILDDIR/sources
|
---|
185 |
|
---|
186 | # Hackish fix for the bash-doc and glibc-{linuxthreads,libidn} packages that
|
---|
187 | # doesn't conform to norms in the URL scheme.
|
---|
188 | DIR=`echo $1 | sed -e 's@-doc@@' -e 's@-linuxthreads@@' -e 's@-libidn@@'`
|
---|
189 |
|
---|
190 | # Find the md5 sum for this package.
|
---|
191 | if [ $2 != MD5SUMS ] ; then MD5=`grep " $2" MD5SUMS` ; fi
|
---|
192 |
|
---|
193 | if [ ! -f $2 ] ; then
|
---|
194 | case $DL in
|
---|
195 | wget )
|
---|
196 | wget $HTTP/$DIR/$2
|
---|
197 | ;;
|
---|
198 | curl )
|
---|
199 | `curl -# $HTTP/$DIR/$2 -o $2`
|
---|
200 | ;;
|
---|
201 | * )
|
---|
202 | echo "$DL not supported at this time."
|
---|
203 | ;;
|
---|
204 | esac
|
---|
205 | elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
|
---|
206 | case $DL in
|
---|
207 | wget )
|
---|
208 | wget -c $HTTP/$DIR/$2
|
---|
209 | ;;
|
---|
210 | curl )
|
---|
211 | `curl -# -C - $HTTP/$DIR/$2 -o $2`
|
---|
212 | ;;
|
---|
213 | * )
|
---|
214 | echo "$DL not supported at this time."
|
---|
215 | ;;
|
---|
216 | esac
|
---|
217 | fi
|
---|
218 | if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
|
---|
219 | exit 1
|
---|
220 | fi
|
---|
221 | }
|
---|
222 |
|
---|
223 | #----------------------------#
|
---|
224 | get_sources() {
|
---|
225 | #----------------------------#
|
---|
226 |
|
---|
227 | # Test if the packages must be downloaded
|
---|
228 | if [ "$HPKG" = "1" ] ; then
|
---|
229 |
|
---|
230 | # This variable is necessary to make sure the `cat $JHALFSDIR/packages`
|
---|
231 | # separates each iteration by lines. It is necessary to have the second
|
---|
232 | # ' on the next line.
|
---|
233 | IFS='
|
---|
234 | '
|
---|
235 |
|
---|
236 | if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
|
---|
237 | cd $BUILDDIR/sources
|
---|
238 | if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
|
---|
239 |
|
---|
240 | download "" MD5SUMS
|
---|
241 |
|
---|
242 | # Iterate through each package and grab it, along with any patches it needs.
|
---|
243 | for i in `cat $JHALFSDIR/packages` ; do
|
---|
244 | PKG=`echo $i | sed 's/-version.*//'`
|
---|
245 | # Needed for Groff patchlevel patch on UTF-8 branch
|
---|
246 | GROFFLEVEL=`grep "groff-patchlevel" $JHALFSDIR/packages | sed -e 's/groff-patchlevel //' -e 's/"//g'`
|
---|
247 | # Needed for IPRoute2 patch on 6.1.1 book
|
---|
248 | IPROUTE2PATCH=`grep "iproute2-patch" $JHALFSDIR/packages | sed -e 's/iproute2-patch-version //' -e 's/"//g'`
|
---|
249 |
|
---|
250 | # There is some entities that aren't valid package entities.
|
---|
251 | if [ "$PKG" = "expect-lib" -o "$PKG" = "linux-dl" -o "$PKG" = "groff-patchlevel" -o "$PKG" = "iproute2-patch" ] ; then continue ; fi
|
---|
252 |
|
---|
253 | VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
|
---|
254 | if [ "$PKG" = "tcl" ] ; then
|
---|
255 | FILE="$PKG$VRS-src.tar.bz2"
|
---|
256 | else
|
---|
257 | FILE="$PKG-$VRS.tar.bz2"
|
---|
258 | fi
|
---|
259 | download $PKG $FILE
|
---|
260 | for patch in `grep "$PKG-&$PKG" $JHALFSDIR/patches` ; do
|
---|
261 | if [ "$patch" = "iproute2-&iproute2-patch-version;-remove_db-1.patch" ] ; then
|
---|
262 | PATCH=`echo $patch | sed 's@&iproute2-patch-version;@'$IPROUTE2PATCH'@'`
|
---|
263 | download $PKG $PATCH
|
---|
264 | else
|
---|
265 | PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
|
---|
266 | download $PKG $PATCH
|
---|
267 | fi
|
---|
268 | done
|
---|
269 | # Needed for Groff patchlevel patch on UTF-8 branch
|
---|
270 | for patch in `grep "patchlevel" $JHALFSDIR/patches` ; do
|
---|
271 | PATCH=`echo $patch | sed 's@&'$PKG'-version;-&'$PKG'-patchlevel;@'$VRS'-'$GROFFLEVEL'@'`
|
---|
272 | download $PKG $PATCH
|
---|
273 | done
|
---|
274 | done
|
---|
275 | # Hardcoded Udev configuration file until find a better way
|
---|
276 | download udev udev-config-4.rules
|
---|
277 | fi
|
---|
278 | }
|
---|
279 |
|
---|
280 | #----------------------------#
|
---|
281 | chapter4_Makefiles() {
|
---|
282 | #----------------------------#
|
---|
283 | (
|
---|
284 | cat << EOF
|
---|
285 | 020-creatingtoolsdir:
|
---|
286 | @\$(call echo_message, Building)
|
---|
287 | @mkdir -v \$(LFS)/tools && \\
|
---|
288 | ln -sv \$(LFS)/tools / && \\
|
---|
289 | touch \$@
|
---|
290 |
|
---|
291 | 021-addinguser: 020-creatingtoolsdir
|
---|
292 | @\$(call echo_message, Building)
|
---|
293 | @groupadd lfs && \\
|
---|
294 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
|
---|
295 | chown lfs \$(LFS)/tools && \\
|
---|
296 | chown lfs \$(LFS)/sources && \\
|
---|
297 | touch \$@
|
---|
298 |
|
---|
299 | 022-settingenvironment: 021-addinguser
|
---|
300 | @\$(call echo_message, Building)
|
---|
301 | @echo "set +h" > /home/lfs/.bashrc && \\
|
---|
302 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
303 | echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
|
---|
304 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
305 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
306 | echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
307 | echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
308 | chown lfs:lfs /home/lfs/.bashrc && \\
|
---|
309 | touch envars && \\
|
---|
310 | touch \$@
|
---|
311 | EOF
|
---|
312 | ) >> $MKFILE.tmp
|
---|
313 | }
|
---|
314 |
|
---|
315 | #----------------------------#
|
---|
316 | chapter5_Makefiles() {
|
---|
317 | #----------------------------#
|
---|
318 | for file in chapter05/* ; do
|
---|
319 | # Keep the script file name
|
---|
320 | i=`basename $file`
|
---|
321 |
|
---|
322 | # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
|
---|
323 | if [ "$TOOLCHAINTEST" = "0" ]; then
|
---|
324 | if echo $i | grep -q "tcl" ; then
|
---|
325 | continue
|
---|
326 | elif echo $i | grep -q "expect" ; then
|
---|
327 | continue
|
---|
328 | elif echo $i | grep -q "dejagnu" ; then
|
---|
329 | continue
|
---|
330 | fi
|
---|
331 | fi
|
---|
332 |
|
---|
333 | # First append each name of the script files to a list (this will become
|
---|
334 | # the names of the targets in the Makefile
|
---|
335 | chapter5="$chapter5 $i"
|
---|
336 |
|
---|
337 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
338 | # and binutils in chapter 5)
|
---|
339 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
340 |
|
---|
341 | # Set the dependency for the first target.
|
---|
342 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
343 |
|
---|
344 | # Drop in the name of the target on a new line, and the previous target
|
---|
345 | # as a dependency. Also call the echo_message function.
|
---|
346 | (
|
---|
347 | cat << EOF
|
---|
348 |
|
---|
349 | $i: $PREV
|
---|
350 | @\$(call echo_message, Building)
|
---|
351 | EOF
|
---|
352 | ) >> $MKFILE.tmp
|
---|
353 |
|
---|
354 | # Find the version of the command files, if it corresponds with the building of
|
---|
355 | # a specific package
|
---|
356 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
357 |
|
---|
358 | # If $vrs isn't empty, we've got a package...
|
---|
359 | if [ "$vrs" != "" ] ; then
|
---|
360 | if [ "$name" = "tcl" ] ; then
|
---|
361 | FILE="$name$vrs-src.tar.bz2"
|
---|
362 | else
|
---|
363 | FILE="$name-$vrs.tar.bz2"
|
---|
364 | fi
|
---|
365 |
|
---|
366 | # Insert instructions for unpacking the package and to set
|
---|
367 | # the PKGDIR variable.
|
---|
368 | (
|
---|
369 | cat << EOF
|
---|
370 | @\$(call unpack,$FILE)
|
---|
371 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
372 | chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
373 | echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
|
---|
374 | echo "export PKGDIR" >> envars && \\
|
---|
375 | EOF
|
---|
376 | ) >> $MKFILE.tmp
|
---|
377 |
|
---|
378 | fi
|
---|
379 |
|
---|
380 | # Dump the path to the Binutils or TCL sources directory.
|
---|
381 | if [ ${i:4:8} = "binutils" -o ${i:4:3} = "tcl" ] ; then
|
---|
382 | (
|
---|
383 | cat << EOF
|
---|
384 | echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
|
---|
385 | EOF
|
---|
386 | ) >> $MKFILE.tmp
|
---|
387 |
|
---|
388 | # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
389 | elif [ ${i:4:9} = "adjusting" ] ; then
|
---|
390 | (
|
---|
391 | cat << EOF
|
---|
392 | @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
|
---|
393 | echo "export PKGDIR" >> envars
|
---|
394 | EOF
|
---|
395 | ) >> $MKFILE.tmp
|
---|
396 |
|
---|
397 | # For the Expect build we need to set the TCLPATH envar.
|
---|
398 | elif [ ${i:4:6} = "expect" ] ; then
|
---|
399 | (
|
---|
400 | cat << EOF
|
---|
401 | echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
|
---|
402 | echo "export TCLPATH" >> envars
|
---|
403 | EOF
|
---|
404 | ) >> $MKFILE.tmp
|
---|
405 |
|
---|
406 | # Everything else, add a true statment so we don't confuse make
|
---|
407 | else
|
---|
408 | (
|
---|
409 | cat << EOF
|
---|
410 | true
|
---|
411 | EOF
|
---|
412 | ) >> $MKFILE.tmp
|
---|
413 | fi
|
---|
414 |
|
---|
415 | # Insert date and disk usage at the top of the log file, the script run
|
---|
416 | # and date and disk usage again at the bottom of the log file.
|
---|
417 | (
|
---|
418 | cat << EOF
|
---|
419 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
420 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
|
---|
421 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
422 | EOF
|
---|
423 | ) >> $MKFILE.tmp
|
---|
424 |
|
---|
425 | # Remove the build directory(ies) except if the package build fails
|
---|
426 | # (to can review config.cache, config.log, and like.)
|
---|
427 | # For Binutils and TCL the sources must be retained some time.
|
---|
428 | if [ "$vrs" != "" ] ; then
|
---|
429 | if [ ${i:4:8} != "binutils" ] && [ ${i:4:3} != "tcl" ] ; then
|
---|
430 | (
|
---|
431 | cat << EOF
|
---|
432 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
433 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
434 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
435 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
436 | fi;
|
---|
437 | EOF
|
---|
438 | ) >> $MKFILE.tmp
|
---|
439 | fi
|
---|
440 | fi
|
---|
441 |
|
---|
442 | # Remove the Binutils pass 1 sources after a successful Adjusting phase.
|
---|
443 | if [ ${i:4:9} = "adjusting" ] ; then
|
---|
444 | (
|
---|
445 | cat << EOF
|
---|
446 | @rm -r \`cat sources-dir\` && \\
|
---|
447 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
448 | rm sources-dir
|
---|
449 | EOF
|
---|
450 | ) >> $MKFILE.tmp
|
---|
451 | fi
|
---|
452 |
|
---|
453 | # Remove the TCL sources after a successful Expect build.
|
---|
454 | if [ ${i:4:6} = "expect" ] ; then
|
---|
455 | (
|
---|
456 | cat << EOF
|
---|
457 | @rm -r \`cat sources-dir\` && \\
|
---|
458 | rm sources-dir
|
---|
459 | EOF
|
---|
460 | ) >> $MKFILE.tmp
|
---|
461 | fi
|
---|
462 |
|
---|
463 | # Include a touch of the target name so make can check
|
---|
464 | # if it's already been made.
|
---|
465 | (
|
---|
466 | cat << EOF
|
---|
467 | @touch \$@
|
---|
468 | EOF
|
---|
469 | ) >> $MKFILE.tmp
|
---|
470 |
|
---|
471 | # Keep the script file name for Makefile dependencies.
|
---|
472 | PREV=$i
|
---|
473 | done # end for file in chapter05/*
|
---|
474 | }
|
---|
475 |
|
---|
476 | #----------------------------#
|
---|
477 | chapter6_Makefiles() {
|
---|
478 | #----------------------------#
|
---|
479 | for file in chapter06/* ; do
|
---|
480 | # Keep the script file name
|
---|
481 | i=`basename $file`
|
---|
482 |
|
---|
483 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
484 | # dependencies and target creation.
|
---|
485 | if echo $i | grep -q "chroot" ; then
|
---|
486 | continue
|
---|
487 | fi
|
---|
488 |
|
---|
489 | # First append each name of the script files to a list (this will become
|
---|
490 | # the names of the targets in the Makefile
|
---|
491 | chapter6="$chapter6 $i"
|
---|
492 |
|
---|
493 | # Grab the name of the target
|
---|
494 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
|
---|
495 |
|
---|
496 | # Drop in the name of the target on a new line, and the previous target
|
---|
497 | # as a dependency. Also call the echo_message function.
|
---|
498 | (
|
---|
499 | cat << EOF
|
---|
500 |
|
---|
501 | $i: $PREV
|
---|
502 | @\$(call echo_message, Building)
|
---|
503 | EOF
|
---|
504 | ) >> $MKFILE.tmp
|
---|
505 |
|
---|
506 | # Find the version of the command files, if it corresponds with the building of
|
---|
507 | # a specific package
|
---|
508 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
509 |
|
---|
510 | # If $vrs isn't empty, we've got a package...
|
---|
511 | # Insert instructions for unpacking the package and changing directories
|
---|
512 | if [ "$vrs" != "" ] ; then
|
---|
513 | FILE="$name-$vrs.tar.bz2"
|
---|
514 | (
|
---|
515 | cat << EOF
|
---|
516 | @\$(call unpack,$FILE)
|
---|
517 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
518 | echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
|
---|
519 | echo "export PKGDIR" >> envars
|
---|
520 | EOF
|
---|
521 | ) >> $MKFILE.tmp
|
---|
522 | fi
|
---|
523 |
|
---|
524 | # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
525 | if [ ${i:4:11} = "readjusting" ] ; then
|
---|
526 | (
|
---|
527 | cat << EOF
|
---|
528 | @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
|
---|
529 | echo "export PKGDIR" >> envars
|
---|
530 | EOF
|
---|
531 | ) >> $MKFILE.tmp
|
---|
532 | fi
|
---|
533 |
|
---|
534 | # For Glibc we need to set TIMEZONE envar.
|
---|
535 | if [ ${i:4:5} = "glibc" ] ; then
|
---|
536 | (
|
---|
537 | cat << EOF
|
---|
538 | @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
|
---|
539 | echo "export TIMEZONE" >> envars
|
---|
540 | EOF
|
---|
541 | ) >> $MKFILE.tmp
|
---|
542 | fi
|
---|
543 |
|
---|
544 | # For Groff we need to set PAGE envar.
|
---|
545 | if [ ${i:4:5} = "groff" ] ; then
|
---|
546 | (
|
---|
547 | cat << EOF
|
---|
548 | @echo "PAGE=\$(PAGE)" >> envars && \\
|
---|
549 | echo "export PAGE" >> envars
|
---|
550 | EOF
|
---|
551 | ) >> $MKFILE.tmp
|
---|
552 | fi
|
---|
553 |
|
---|
554 | # In the mount of kernel filesystems we need to set LFS
|
---|
555 | # and not to use chroot.
|
---|
556 | if [ ${i:4:6} = "kernfs" ] ; then
|
---|
557 | (
|
---|
558 | cat << EOF
|
---|
559 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
560 | export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
|
---|
561 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
562 | EOF
|
---|
563 | ) >> $MKFILE.tmp
|
---|
564 |
|
---|
565 | # The rest of Chapter06
|
---|
566 | else
|
---|
567 | (
|
---|
568 | cat << EOF
|
---|
569 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
570 | \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
|
---|
571 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
572 | EOF
|
---|
573 | ) >> $MKFILE.tmp
|
---|
574 |
|
---|
575 | fi
|
---|
576 |
|
---|
577 | # Remove the build directory(ies) except if the package build fails.
|
---|
578 | if [ "$vrs" != "" ] ; then
|
---|
579 | (
|
---|
580 | cat << EOF
|
---|
581 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
582 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
583 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
584 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
585 | fi;
|
---|
586 | EOF
|
---|
587 | ) >> $MKFILE.tmp
|
---|
588 | fi
|
---|
589 |
|
---|
590 | # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
|
---|
591 | if [ ${i:4:11} = "readjusting" ] ; then
|
---|
592 | (
|
---|
593 | cat << EOF
|
---|
594 | @rm -r \`cat sources-dir\` && \\
|
---|
595 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
596 | rm sources-dir
|
---|
597 | EOF
|
---|
598 | ) >> $MKFILE.tmp
|
---|
599 | fi
|
---|
600 |
|
---|
601 | # Include a touch of the target name so make can check
|
---|
602 | # if it's already been made.
|
---|
603 | (
|
---|
604 | cat << EOF
|
---|
605 | @touch \$@
|
---|
606 | EOF
|
---|
607 | ) >> $MKFILE.tmp
|
---|
608 |
|
---|
609 | # Keep the script file name for Makefile dependencies.
|
---|
610 | PREV=$i
|
---|
611 | done # end for file in chapter06/*
|
---|
612 | }
|
---|
613 |
|
---|
614 | #----------------------------#
|
---|
615 | chapter789_Makefiles() {
|
---|
616 | #----------------------------#
|
---|
617 | for file in chapter0{7,8,9}/* ; do
|
---|
618 | # Keep the script file name
|
---|
619 | i=`basename $file`
|
---|
620 |
|
---|
621 | # Grub must be configured manually
|
---|
622 | if echo $i | grep -q "grub" ; then
|
---|
623 | continue
|
---|
624 | # The filesystems can't be unmounted yet due that the user must
|
---|
625 | # to enter to the chroot environment to create the root password,
|
---|
626 | # edit several files and setup Grub,
|
---|
627 | elif echo $i | grep -q "reboot" ; then
|
---|
628 | continue
|
---|
629 | fi
|
---|
630 |
|
---|
631 | # If no .config file is supplied, the kernel build is skipped
|
---|
632 | if [ -z $CONFIG ] ; then
|
---|
633 | if echo $i | grep -q "kernel" ; then
|
---|
634 | continue
|
---|
635 | fi
|
---|
636 | fi
|
---|
637 |
|
---|
638 | # First append each name of the script files to a list (this will become
|
---|
639 | # the names of the targets in the Makefile
|
---|
640 | chapter789="$chapter789 $i"
|
---|
641 |
|
---|
642 | # Drop in the name of the target on a new line, and the previous target
|
---|
643 | # as a dependency. Also call the echo_message function.
|
---|
644 | (
|
---|
645 | cat << EOF
|
---|
646 |
|
---|
647 | $i: $PREV
|
---|
648 | @\$(call echo_message, Building)
|
---|
649 | EOF
|
---|
650 | ) >> $MKFILE.tmp
|
---|
651 |
|
---|
652 | # Find the the bootscripts and kernel package names
|
---|
653 | if [ ${i:4:11} = "bootscripts" -o ${i:4:6} = "kernel" ] ; then
|
---|
654 | if [ ${i:4:11} = "bootscripts" ] ; then
|
---|
655 | vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
656 | FILE="lfs-bootscripts-$vrs.tar.bz2"
|
---|
657 | elif [ ${i:4:6} = "kernel" ] ; then
|
---|
658 | vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
659 | FILE="linux-$vrs.tar.bz2"
|
---|
660 | fi
|
---|
661 | (
|
---|
662 | cat << EOF
|
---|
663 | @\$(call unpack,$FILE)
|
---|
664 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
665 | echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
|
---|
666 | echo "export PKGDIR" >> envars
|
---|
667 | EOF
|
---|
668 | ) >> $MKFILE.tmp
|
---|
669 | fi
|
---|
670 |
|
---|
671 | # Put in place the kernel .config file
|
---|
672 | if [ ${i:4:6} = "kernel" ] ; then
|
---|
673 | (
|
---|
674 | cat << EOF
|
---|
675 | @cp $CONFIG \$(LFS)/sources/kernel-config
|
---|
676 | EOF
|
---|
677 | ) >> $MKFILE.tmp
|
---|
678 | fi
|
---|
679 |
|
---|
680 | # Check if we have a real /etc/fstab file
|
---|
681 | if [ ${i:4:5} = "fstab" ] && [ -n "$FSTAB" ] ; then
|
---|
682 | (
|
---|
683 | cat << EOF
|
---|
684 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
685 | cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
|
---|
686 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
687 | EOF
|
---|
688 | ) >> $MKFILE.tmp
|
---|
689 | else
|
---|
690 | # Initialize the log an run the script
|
---|
691 | (
|
---|
692 | cat << EOF
|
---|
693 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
694 | \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
|
---|
695 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
696 | EOF
|
---|
697 | ) >> $MKFILE.tmp
|
---|
698 | fi
|
---|
699 |
|
---|
700 | # Remove the build directory except if the package build fails.
|
---|
701 | if [ ${i:4:11} = "bootscripts" -o ${i:4:6} = "kernel" ] ; then
|
---|
702 | (
|
---|
703 | cat << EOF
|
---|
704 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
705 | rm -r \$(LFS)\$(SRC)/\$\$ROOT
|
---|
706 | EOF
|
---|
707 | ) >> $MKFILE.tmp
|
---|
708 | fi
|
---|
709 |
|
---|
710 | # Include a touch of the target name so make can check
|
---|
711 | # if it's already been made.
|
---|
712 | (
|
---|
713 | cat << EOF
|
---|
714 | @touch \$@
|
---|
715 | EOF
|
---|
716 | ) >> $MKFILE.tmp
|
---|
717 |
|
---|
718 | # Keep the script file name for Makefile dependencies.
|
---|
719 | PREV=$i
|
---|
720 | done # for file in chapter0{7,8,9}/*
|
---|
721 | }
|
---|
722 |
|
---|
723 |
|
---|
724 | #----------------------------#
|
---|
725 | build_Makefile() {
|
---|
726 | #----------------------------#
|
---|
727 | echo -n "Creating Makefile... "
|
---|
728 | cd $JHALFSDIR/commands
|
---|
729 |
|
---|
730 | # Start with a clean Makefile.tmp file
|
---|
731 | >$MKFILE.tmp
|
---|
732 |
|
---|
733 | chapter4_Makefiles
|
---|
734 | chapter5_Makefiles
|
---|
735 | chapter6_Makefiles
|
---|
736 | chapter789_Makefiles
|
---|
737 |
|
---|
738 |
|
---|
739 | # Add a header, some variables and include the function file
|
---|
740 | # to the top of the real Makefile.
|
---|
741 | (
|
---|
742 | cat << EOF
|
---|
743 | $HEADER
|
---|
744 |
|
---|
745 | SRC= /sources
|
---|
746 | LFS= $BUILDDIR
|
---|
747 | PAGE= $PAGE
|
---|
748 | TIMEZONE= $TIMEZONE
|
---|
749 |
|
---|
750 | include functions
|
---|
751 |
|
---|
752 | EOF
|
---|
753 | ) > $MKFILE
|
---|
754 |
|
---|
755 |
|
---|
756 | # Add chroot commands
|
---|
757 | i=1
|
---|
758 | for file in chapter06/*chroot* ; do
|
---|
759 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
|
---|
760 | -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
|
---|
761 | -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
|
---|
762 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
763 | i=`expr $i + 1`
|
---|
764 | done
|
---|
765 |
|
---|
766 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
767 | # as a dependency.
|
---|
768 | (
|
---|
769 | cat << EOF
|
---|
770 | all: chapter4 chapter5 chapter6 chapter789
|
---|
771 | @\$(call echo_finished,$VERSION)
|
---|
772 |
|
---|
773 | chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
774 |
|
---|
775 | chapter5: chapter4 $chapter5
|
---|
776 |
|
---|
777 | chapter6: chapter5 $chapter6
|
---|
778 |
|
---|
779 | chapter789: chapter6 $chapter789
|
---|
780 |
|
---|
781 | clean-all: clean
|
---|
782 | rm -rf ./*
|
---|
783 |
|
---|
784 | clean: clean-chapter5 clean-chapter4
|
---|
785 |
|
---|
786 | clean-chapter4:
|
---|
787 | -userdel lfs
|
---|
788 | rm -rf /home/lfs
|
---|
789 | rm -rf \$(LFS)/tools
|
---|
790 | rm -f /tools
|
---|
791 | rm -f envars
|
---|
792 | rm -f 02* logs/02*.log
|
---|
793 |
|
---|
794 | clean-chapter5:
|
---|
795 | rm -rf \$(LFS)/tools/*
|
---|
796 | rm -f $chapter5
|
---|
797 | cd logs && rm -f $chapter5 && cd ..
|
---|
798 |
|
---|
799 | EOF
|
---|
800 | ) >> $MKFILE
|
---|
801 |
|
---|
802 | # Bring over the items from the Makefile.tmp
|
---|
803 | cat $MKFILE.tmp >> $MKFILE
|
---|
804 | rm $MKFILE.tmp
|
---|
805 | echo -ne "done\n"
|
---|
806 | }
|
---|
807 |
|
---|
808 | #----------------------------#
|
---|
809 | run_make() {
|
---|
810 | #----------------------------#
|
---|
811 | # Test if make must be run.
|
---|
812 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
813 | # Build the system
|
---|
814 | if [ -e $MKFILE ] ; then
|
---|
815 | echo -ne "Building the LFS system...\n"
|
---|
816 | cd $JHALFSDIR && make
|
---|
817 | echo -ne "done\n"
|
---|
818 | fi
|
---|
819 | fi
|
---|
820 | }
|
---|
821 |
|
---|
822 |
|
---|
823 |
|
---|
824 | ###################################
|
---|
825 | ### MAIN ###
|
---|
826 | ###################################
|
---|
827 |
|
---|
828 | # Test to make sure we're running the build as root
|
---|
829 |
|
---|
830 | if [ "$UID" != "0" ] ; then
|
---|
831 | echo "You must be logged in as root to successfully build LFS."
|
---|
832 | exit 1
|
---|
833 | fi
|
---|
834 |
|
---|
835 | # Find the download client to use, if not already specified.
|
---|
836 |
|
---|
837 | if [ -z $DL ] ; then
|
---|
838 | if [ `type -p wget` ] ; then
|
---|
839 | DL=wget
|
---|
840 | elif [ `type -p curl` ] ; then
|
---|
841 | DL=curl
|
---|
842 | else
|
---|
843 | eval "$no_dl_client"
|
---|
844 | fi
|
---|
845 | fi
|
---|
846 |
|
---|
847 | # Evaluate any command line switches
|
---|
848 |
|
---|
849 | while test $# -gt 0 ; do
|
---|
850 | case $1 in
|
---|
851 | --version | -V )
|
---|
852 | echo "$version"
|
---|
853 | exit 0
|
---|
854 | ;;
|
---|
855 |
|
---|
856 | --help | -h )
|
---|
857 | echo "$usage"
|
---|
858 | exit 0
|
---|
859 | ;;
|
---|
860 |
|
---|
861 | --LFS-version | -L )
|
---|
862 | test $# = 1 && eval "$exit_missing_arg"
|
---|
863 | shift
|
---|
864 | case $1 in
|
---|
865 | dev* | SVN | trunk )
|
---|
866 | LFSVRS=development
|
---|
867 | ;;
|
---|
868 | testing | 6.1.1 )
|
---|
869 | LFSVRS=6.1.1
|
---|
870 | ;;
|
---|
871 | * )
|
---|
872 | echo "$1 is an unsupported version at this time."
|
---|
873 | exit 1
|
---|
874 | ;;
|
---|
875 | esac
|
---|
876 | ;;
|
---|
877 |
|
---|
878 | --directory | -d )
|
---|
879 | test $# = 1 && eval "$exit_missing_arg"
|
---|
880 | shift
|
---|
881 | BUILDDIR=$1
|
---|
882 | ;;
|
---|
883 |
|
---|
884 | --download-client | -D )
|
---|
885 | test $# = 1 && eval "$exit_missing_arg"
|
---|
886 | shift
|
---|
887 | DL=$1
|
---|
888 | ;;
|
---|
889 |
|
---|
890 | --working-copy | -W )
|
---|
891 | test $# = 1 && eval "$exit_missing_arg"
|
---|
892 | shift
|
---|
893 | if [ -f $1/patches.ent ] ; then
|
---|
894 | WC=1
|
---|
895 | BOOK=$1
|
---|
896 | else
|
---|
897 | echo -e "\nLook like $1 isn't a supported working copy."
|
---|
898 | echo -e "Verify your selection and the command line.\n"
|
---|
899 | exit 1
|
---|
900 | fi
|
---|
901 | ;;
|
---|
902 |
|
---|
903 | --testsuites | -T ) TEST=1 ;;
|
---|
904 |
|
---|
905 | --get-packages | -P ) HPKG=1 ;;
|
---|
906 |
|
---|
907 | --run-make | -M ) RUNMAKE=1 ;;
|
---|
908 |
|
---|
909 | --no-toolchain-test ) TOOLCHAINTEST=0 ;;
|
---|
910 |
|
---|
911 | --page_size )
|
---|
912 | test $# = 1 && eval "$exit_missing_arg"
|
---|
913 | shift
|
---|
914 | case $1 in
|
---|
915 | letter | A4 )
|
---|
916 | PAGE=$1
|
---|
917 | ;;
|
---|
918 | * )
|
---|
919 | echo "$1 isn't a supported page size."
|
---|
920 | exit 1
|
---|
921 | ;;
|
---|
922 | esac
|
---|
923 | ;;
|
---|
924 |
|
---|
925 |
|
---|
926 | --timezone )
|
---|
927 | test $# = 1 && eval "$exit_missing_arg"
|
---|
928 | shift
|
---|
929 | if [ -f /usr/share/zoneinfo/$1 ] ; then
|
---|
930 | TIMEZONE=$1
|
---|
931 | else
|
---|
932 | echo -e "\nLook like $1 isn't a valid timezone description."
|
---|
933 | echo -e "Verify your selection and the command line.\n"
|
---|
934 | exit 1
|
---|
935 | fi
|
---|
936 | ;;
|
---|
937 |
|
---|
938 | --fstab )
|
---|
939 | test $# = 1 && eval "$exit_missing_arg"
|
---|
940 | shift
|
---|
941 | if [ -f $1 ] ; then
|
---|
942 | FSTAB=$1
|
---|
943 | else
|
---|
944 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
945 | exit 1
|
---|
946 | fi
|
---|
947 | ;;
|
---|
948 |
|
---|
949 | --kernel-config | -C )
|
---|
950 | test $# = 1 && eval "$exit_missing_arg"
|
---|
951 | shift
|
---|
952 | if [ -f $1 ] ; then
|
---|
953 | CONFIG=$1
|
---|
954 | else
|
---|
955 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
956 | exit 1
|
---|
957 | fi
|
---|
958 | ;;
|
---|
959 |
|
---|
960 | * )
|
---|
961 | echo "$usage"
|
---|
962 | exit 1
|
---|
963 | ;;
|
---|
964 | esac
|
---|
965 | shift
|
---|
966 | done
|
---|
967 |
|
---|
968 | [[ ! -d $JHALFSDIR ]] && mkdir -pv $JHALFSDIR
|
---|
969 | [[ "$PWD" != "$JHALFSDIR" ]] && cp -v $0 $XSL $FILES $JHALFSDIR/
|
---|
970 | [[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
|
---|
971 | >$LOGDIR/$LOG
|
---|
972 |
|
---|
973 | get_book
|
---|
974 | build_Makefile
|
---|
975 | run_make
|
---|
976 |
|
---|