1 | #!/bin/sh
|
---|
2 |
|
---|
3 | #
|
---|
4 | # Load the configuration file
|
---|
5 | #
|
---|
6 | source 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 | _IS_() # Function to test build scripts names
|
---|
282 | #-----------------------------------------------#
|
---|
283 | {
|
---|
284 | # Returns substr $2 or null str
|
---|
285 | # Must use string testing
|
---|
286 | case $1 in
|
---|
287 | *$2*) echo "$2" ;;
|
---|
288 | *) echo "" ;;
|
---|
289 | esac
|
---|
290 | }
|
---|
291 |
|
---|
292 | #----------------------------#
|
---|
293 | chapter4_Makefiles() {
|
---|
294 | #----------------------------#
|
---|
295 | (
|
---|
296 | cat << EOF
|
---|
297 | 020-creatingtoolsdir:
|
---|
298 | @\$(call echo_message, Building)
|
---|
299 | @mkdir -v \$(LFS)/tools && \\
|
---|
300 | ln -sv \$(LFS)/tools / && \\
|
---|
301 | touch \$@
|
---|
302 |
|
---|
303 | 021-addinguser: 020-creatingtoolsdir
|
---|
304 | @\$(call echo_message, Building)
|
---|
305 | @groupadd lfs && \\
|
---|
306 | useradd -s /bin/bash -g lfs -m -k /dev/null lfs && \\
|
---|
307 | chown lfs \$(LFS)/tools && \\
|
---|
308 | chown lfs \$(LFS)/sources && \\
|
---|
309 | touch \$@
|
---|
310 |
|
---|
311 | 022-settingenvironment: 021-addinguser
|
---|
312 | @\$(call echo_message, Building)
|
---|
313 | @echo "set +h" > /home/lfs/.bashrc && \\
|
---|
314 | echo "umask 022" >> /home/lfs/.bashrc && \\
|
---|
315 | echo "LFS=/mnt/lfs" >> /home/lfs/.bashrc && \\
|
---|
316 | echo "LC_ALL=POSIX" >> /home/lfs/.bashrc && \\
|
---|
317 | echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/lfs/.bashrc && \\
|
---|
318 | echo "export LFS LC_ALL PATH" >> /home/lfs/.bashrc && \\
|
---|
319 | echo "source $JHALFSDIR/envars" >> /home/lfs/.bashrc && \\
|
---|
320 | chown lfs:lfs /home/lfs/.bashrc && \\
|
---|
321 | touch envars && \\
|
---|
322 | touch \$@
|
---|
323 | EOF
|
---|
324 | ) >> $MKFILE.tmp
|
---|
325 | }
|
---|
326 |
|
---|
327 | #----------------------------#
|
---|
328 | chapter5_Makefiles() {
|
---|
329 | #----------------------------#
|
---|
330 | for file in chapter05/* ; do
|
---|
331 | # Keep the script file name
|
---|
332 | i=`basename $file`
|
---|
333 |
|
---|
334 | # If no testsuites will be run, then TCL, Expect and DejaGNU isn't needed
|
---|
335 | if [ "$TOOLCHAINTEST" = "0" ]; then
|
---|
336 | if [[ `_IS_ $i tcl` ]] || [[ `_IS_ $i expect` ]] || [[ `_IS_ $i dejagnu` ]] ; then
|
---|
337 | continue
|
---|
338 | fi
|
---|
339 | fi
|
---|
340 |
|
---|
341 | # First append each name of the script files to a list (this will become
|
---|
342 | # the names of the targets in the Makefile
|
---|
343 | chapter5="$chapter5 $i"
|
---|
344 |
|
---|
345 | # Grab the name of the target (minus the -pass1 or -pass2 in the case of gcc
|
---|
346 | # and binutils in chapter 5)
|
---|
347 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@' -e 's@-pass[0-9]\{1\}@@'`
|
---|
348 |
|
---|
349 | # Set the dependency for the first target.
|
---|
350 | if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
|
---|
351 |
|
---|
352 | # Drop in the name of the target on a new line, and the previous target
|
---|
353 | # as a dependency. Also call the echo_message function.
|
---|
354 | (
|
---|
355 | cat << EOF
|
---|
356 |
|
---|
357 | $i: $PREV
|
---|
358 | @\$(call echo_message, Building)
|
---|
359 | EOF
|
---|
360 | ) >> $MKFILE.tmp
|
---|
361 |
|
---|
362 | # Find the version of the command files, if it corresponds with the building of
|
---|
363 | # a specific package
|
---|
364 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
365 |
|
---|
366 | # If $vrs isn't empty, we've got a package...
|
---|
367 | if [ "$vrs" != "" ] ; then
|
---|
368 | if [ "$name" = "tcl" ] ; then
|
---|
369 | FILE="$name$vrs-src.tar.bz2"
|
---|
370 | else
|
---|
371 | FILE="$name-$vrs.tar.bz2"
|
---|
372 | fi
|
---|
373 |
|
---|
374 | # Insert instructions for unpacking the package and to set
|
---|
375 | # the PKGDIR variable.
|
---|
376 | (
|
---|
377 | cat << EOF
|
---|
378 | @\$(call unpack,$FILE)
|
---|
379 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
380 | chown -R lfs \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
381 | echo "PKGDIR=\$(LFS)\$(SRC)/\$\$ROOT" > envars && \\
|
---|
382 | echo "export PKGDIR" >> envars && \\
|
---|
383 | EOF
|
---|
384 | ) >> $MKFILE.tmp
|
---|
385 |
|
---|
386 | fi
|
---|
387 |
|
---|
388 | # Dump the path to the Binutils or TCL sources directory.
|
---|
389 | if [[ `_IS_ $i binutils` ]] || [[ `_IS_ $i tcl` ]] ; then
|
---|
390 | (
|
---|
391 | cat << EOF
|
---|
392 | echo "\$(LFS)\$(SRC)/\$\$ROOT" > sources-dir
|
---|
393 | EOF
|
---|
394 | ) >> $MKFILE.tmp
|
---|
395 |
|
---|
396 | # For the Adjusting phase we must to cd to the binutils-build directory.
|
---|
397 | elif [[ `_IS_ $i adjusting` ]] ; then
|
---|
398 | (
|
---|
399 | cat << EOF
|
---|
400 | @echo "PKGDIR=\$(LFS)\$(SRC)/binutils-build" > envars && \\
|
---|
401 | echo "export PKGDIR" >> envars
|
---|
402 | EOF
|
---|
403 | ) >> $MKFILE.tmp
|
---|
404 |
|
---|
405 | # For the Expect build we need to set the TCLPATH envar.
|
---|
406 | elif [[ `_IS_ $i expect` ]] ; then
|
---|
407 | (
|
---|
408 | cat << EOF
|
---|
409 | echo "TCLPATH=\`cat sources-dir\`" >> envars && \\
|
---|
410 | echo "export TCLPATH" >> envars
|
---|
411 | EOF
|
---|
412 | ) >> $MKFILE.tmp
|
---|
413 |
|
---|
414 | # Everything else, add a true statment so we don't confuse make
|
---|
415 | else
|
---|
416 | (
|
---|
417 | cat << EOF
|
---|
418 | true
|
---|
419 | EOF
|
---|
420 | ) >> $MKFILE.tmp
|
---|
421 | fi
|
---|
422 |
|
---|
423 | # Insert date and disk usage at the top of the log file, the script run
|
---|
424 | # and date and disk usage again at the bottom of the log file.
|
---|
425 | (
|
---|
426 | cat << EOF
|
---|
427 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
428 | su - lfs -c "source /home/lfs/.bashrc && $JHALFSDIR/commands/$file" >>logs/$i 2>&1 && \\
|
---|
429 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
430 | EOF
|
---|
431 | ) >> $MKFILE.tmp
|
---|
432 |
|
---|
433 | # Remove the build directory(ies) except if the package build fails
|
---|
434 | # (to can review config.cache, config.log, and like.)
|
---|
435 | # For Binutils and TCL the sources must be retained some time.
|
---|
436 | if [ "$vrs" != "" ] ; then
|
---|
437 | if [[ ! `_IS_ $i binutils` ]] && [[ ! `_IS_ $i tcl` ]] ; then
|
---|
438 | (
|
---|
439 | cat << EOF
|
---|
440 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
441 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
442 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
443 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
444 | fi;
|
---|
445 | EOF
|
---|
446 | ) >> $MKFILE.tmp
|
---|
447 | fi
|
---|
448 | fi
|
---|
449 |
|
---|
450 | # Remove the Binutils pass 1 sources after a successful Adjusting phase.
|
---|
451 | if [[ `_IS_ $i adjusting` ]] ; then
|
---|
452 | (
|
---|
453 | cat << EOF
|
---|
454 | @rm -r \`cat sources-dir\` && \\
|
---|
455 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
456 | rm sources-dir
|
---|
457 | EOF
|
---|
458 | ) >> $MKFILE.tmp
|
---|
459 | fi
|
---|
460 |
|
---|
461 | # Remove the TCL sources after a successful Expect build.
|
---|
462 | if [[ `_IS_ $i expect` ]] ; then
|
---|
463 | (
|
---|
464 | cat << EOF
|
---|
465 | @rm -r \`cat sources-dir\` && \\
|
---|
466 | rm sources-dir
|
---|
467 | EOF
|
---|
468 | ) >> $MKFILE.tmp
|
---|
469 | fi
|
---|
470 |
|
---|
471 | # Include a touch of the target name so make can check
|
---|
472 | # if it's already been made.
|
---|
473 | (
|
---|
474 | cat << EOF
|
---|
475 | @touch \$@
|
---|
476 | EOF
|
---|
477 | ) >> $MKFILE.tmp
|
---|
478 |
|
---|
479 | # Keep the script file name for Makefile dependencies.
|
---|
480 | PREV=$i
|
---|
481 | done # end for file in chapter05/*
|
---|
482 | }
|
---|
483 |
|
---|
484 | #----------------------------#
|
---|
485 | chapter6_Makefiles() {
|
---|
486 | #----------------------------#
|
---|
487 | for file in chapter06/* ; do
|
---|
488 | # Keep the script file name
|
---|
489 | i=`basename $file`
|
---|
490 |
|
---|
491 | # We'll run the chroot commands differently than the others, so skip them in the
|
---|
492 | # dependencies and target creation.
|
---|
493 | if [[ `_IS_ $i chroot` ]] ; then
|
---|
494 | continue
|
---|
495 | fi
|
---|
496 |
|
---|
497 | # First append each name of the script files to a list (this will become
|
---|
498 | # the names of the targets in the Makefile
|
---|
499 | chapter6="$chapter6 $i"
|
---|
500 |
|
---|
501 | # Grab the name of the target
|
---|
502 | name=`echo $i | sed -e 's@[0-9]\{3\}-@@'`
|
---|
503 |
|
---|
504 | # Drop in the name of the target on a new line, and the previous target
|
---|
505 | # as a dependency. Also call the echo_message function.
|
---|
506 | (
|
---|
507 | cat << EOF
|
---|
508 |
|
---|
509 | $i: $PREV
|
---|
510 | @\$(call echo_message, Building)
|
---|
511 | EOF
|
---|
512 | ) >> $MKFILE.tmp
|
---|
513 |
|
---|
514 | # Find the version of the command files, if it corresponds with the building of
|
---|
515 | # a specific package
|
---|
516 | vrs=`grep "^$name-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
517 |
|
---|
518 | # If $vrs isn't empty, we've got a package...
|
---|
519 | # Insert instructions for unpacking the package and changing directories
|
---|
520 | if [ "$vrs" != "" ] ; then
|
---|
521 | FILE="$name-$vrs.tar.bz2"
|
---|
522 | (
|
---|
523 | cat << EOF
|
---|
524 | @\$(call unpack,$FILE)
|
---|
525 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
526 | echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
|
---|
527 | echo "export PKGDIR" >> envars
|
---|
528 | EOF
|
---|
529 | ) >> $MKFILE.tmp
|
---|
530 | fi
|
---|
531 |
|
---|
532 | # For the Re-Adjusting phase we must to cd to the binutils-build directory.
|
---|
533 | if [[ `_IS_ $i readjusting` ]] ; then
|
---|
534 | (
|
---|
535 | cat << EOF
|
---|
536 | @echo "PKGDIR=\$(SRC)/binutils-build" > envars && \\
|
---|
537 | echo "export PKGDIR" >> envars
|
---|
538 | EOF
|
---|
539 | ) >> $MKFILE.tmp
|
---|
540 |
|
---|
541 | # For Glibc we need to set TIMEZONE envar.
|
---|
542 | elif [[ `_IS_ $i glibc` ]] ; then
|
---|
543 | (
|
---|
544 | cat << EOF
|
---|
545 | @echo "TIMEZONE=\$(TIMEZONE)" >> envars && \\
|
---|
546 | echo "export TIMEZONE" >> envars
|
---|
547 | EOF
|
---|
548 | ) >> $MKFILE.tmp
|
---|
549 |
|
---|
550 | # For Groff we need to set PAGE envar.
|
---|
551 | elif [[ `_IS_ $i groff` ]] ; then
|
---|
552 | (
|
---|
553 | cat << EOF
|
---|
554 | @echo "PAGE=\$(PAGE)" >> envars && \\
|
---|
555 | echo "export PAGE" >> envars
|
---|
556 | EOF
|
---|
557 | ) >> $MKFILE.tmp
|
---|
558 | fi
|
---|
559 |
|
---|
560 | # In the mount of kernel filesystems we need to set LFS
|
---|
561 | # and not to use chroot.
|
---|
562 | if [[ `_IS_ $i kernfs` ]] ; then
|
---|
563 | (
|
---|
564 | cat << EOF
|
---|
565 | @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
566 | export LFS=\$(LFS) && commands/$file >>logs/$i 2>&1 && \\
|
---|
567 | echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
568 | EOF
|
---|
569 | ) >> $MKFILE.tmp
|
---|
570 |
|
---|
571 | # The rest of Chapter06
|
---|
572 | else
|
---|
573 | (
|
---|
574 | cat << EOF
|
---|
575 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
576 | \$(CHROOT1) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
|
---|
577 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
578 | EOF
|
---|
579 | ) >> $MKFILE.tmp
|
---|
580 | fi
|
---|
581 |
|
---|
582 | # Remove the build directory(ies) except if the package build fails.
|
---|
583 | if [ "$vrs" != "" ] ; then
|
---|
584 | (
|
---|
585 | cat << EOF
|
---|
586 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
587 | rm -r \$(LFS)\$(SRC)/\$\$ROOT && \\
|
---|
588 | if [ -e \$(LFS)\$(SRC)/$name-build ]; then \\
|
---|
589 | rm -r \$(LFS)\$(SRC)/$name-build; \\
|
---|
590 | fi;
|
---|
591 | EOF
|
---|
592 | ) >> $MKFILE.tmp
|
---|
593 | fi
|
---|
594 |
|
---|
595 | # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
|
---|
596 | if [[ `_IS_ $i readjusting` ]] ; then
|
---|
597 | (
|
---|
598 | cat << EOF
|
---|
599 | @rm -r \`cat sources-dir\` && \\
|
---|
600 | rm -r \$(LFS)\$(SRC)/binutils-build && \\
|
---|
601 | rm sources-dir
|
---|
602 | EOF
|
---|
603 | ) >> $MKFILE.tmp
|
---|
604 | fi
|
---|
605 |
|
---|
606 | # Include a touch of the target name so make can check
|
---|
607 | # if it's already been made.
|
---|
608 | (
|
---|
609 | cat << EOF
|
---|
610 | @touch \$@
|
---|
611 | EOF
|
---|
612 | ) >> $MKFILE.tmp
|
---|
613 |
|
---|
614 | # Keep the script file name for Makefile dependencies.
|
---|
615 | PREV=$i
|
---|
616 | done # end for file in chapter06/*
|
---|
617 | }
|
---|
618 |
|
---|
619 | #----------------------------#
|
---|
620 | chapter789_Makefiles() {
|
---|
621 | #----------------------------#
|
---|
622 | for file in chapter0{7,8,9}/* ; do
|
---|
623 | # Keep the script file name
|
---|
624 | i=`basename $file`
|
---|
625 |
|
---|
626 | # Grub must be configured manually.
|
---|
627 | # The filesystems can't be unmounted via Makefile and the user
|
---|
628 | # should to enter to the chroot environment to create the root
|
---|
629 | # password, edit several files and setup Grub,
|
---|
630 | if [[ `_IS_ $i grub` ]] || [[ `_IS_ $i reboot` ]] ; then
|
---|
631 | continue
|
---|
632 | fi
|
---|
633 |
|
---|
634 | # If no .config file is supplied, the kernel build is skipped
|
---|
635 | if [ -z $CONFIG ] && [[ `_IS_ $i kernel` ]] ; then
|
---|
636 | continue
|
---|
637 | fi
|
---|
638 |
|
---|
639 | # First append each name of the script files to a list (this will become
|
---|
640 | # the names of the targets in the Makefile
|
---|
641 | chapter789="$chapter789 $i"
|
---|
642 |
|
---|
643 | # Drop in the name of the target on a new line, and the previous target
|
---|
644 | # as a dependency. Also call the echo_message function.
|
---|
645 | (
|
---|
646 | cat << EOF
|
---|
647 |
|
---|
648 | $i: $PREV
|
---|
649 | @\$(call echo_message, Building)
|
---|
650 | EOF
|
---|
651 | ) >> $MKFILE.tmp
|
---|
652 |
|
---|
653 | # Find the the bootscripts and kernel package names
|
---|
654 | if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
|
---|
655 | if [[ `_IS_ $i bootscripts` ]] ; then
|
---|
656 | vrs=`grep "^lfs-bootscripts-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
657 | FILE="lfs-bootscripts-$vrs.tar.bz2"
|
---|
658 | elif [[ `_IS_ $i kernel` ]] ; then
|
---|
659 | vrs=`grep "^linux-version" $JHALFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
|
---|
660 | FILE="linux-$vrs.tar.bz2"
|
---|
661 | fi
|
---|
662 | (
|
---|
663 | cat << EOF
|
---|
664 | @\$(call unpack,$FILE)
|
---|
665 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
666 | echo "PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
|
---|
667 | echo "export PKGDIR" >> envars
|
---|
668 | EOF
|
---|
669 | ) >> $MKFILE.tmp
|
---|
670 | fi
|
---|
671 |
|
---|
672 | # Put in place the kernel .config file
|
---|
673 | if [[ `_IS_ $i kernel` ]] ; then
|
---|
674 | (
|
---|
675 | cat << EOF
|
---|
676 | @cp $CONFIG \$(LFS)/sources/kernel-config
|
---|
677 | EOF
|
---|
678 | ) >> $MKFILE.tmp
|
---|
679 | fi
|
---|
680 |
|
---|
681 | # Check if we have a real /etc/fstab file
|
---|
682 | if [[ `_IS_ $i fstab` ]] && [[ -n "$FSTAB" ]] ; then
|
---|
683 | (
|
---|
684 | cat << EOF
|
---|
685 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
686 | cp -v $FSTAB \$(LFS)/etc/fstab >>logs/$i 2>&1 && \\
|
---|
687 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
688 | EOF
|
---|
689 | ) >> $MKFILE.tmp
|
---|
690 | else
|
---|
691 | # Initialize the log an run the script
|
---|
692 | (
|
---|
693 | cat << EOF
|
---|
694 | @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >logs/$i && \\
|
---|
695 | \$(CHROOT2) 'cd /jhalfs && source envars && /jhalfs/commands/$file >>/jhalfs/logs/$i 2>&1' && \\
|
---|
696 | echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(LFS)\`\n" >>logs/$i
|
---|
697 | EOF
|
---|
698 | ) >> $MKFILE.tmp
|
---|
699 | fi
|
---|
700 |
|
---|
701 | # Remove the build directory except if the package build fails.
|
---|
702 | if [[ `_IS_ $i bootscripts` ]] || [[ `_IS_ $i kernel` ]] ; then
|
---|
703 | (
|
---|
704 | cat << EOF
|
---|
705 | @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
|
---|
706 | rm -r \$(LFS)\$(SRC)/\$\$ROOT
|
---|
707 | EOF
|
---|
708 | ) >> $MKFILE.tmp
|
---|
709 | fi
|
---|
710 |
|
---|
711 | # Include a touch of the target name so make can check
|
---|
712 | # if it's already been made.
|
---|
713 | (
|
---|
714 | cat << EOF
|
---|
715 | @touch \$@
|
---|
716 | EOF
|
---|
717 | ) >> $MKFILE.tmp
|
---|
718 |
|
---|
719 | # Keep the script file name for Makefile dependencies.
|
---|
720 | PREV=$i
|
---|
721 | done # for file in chapter0{7,8,9}/*
|
---|
722 | }
|
---|
723 |
|
---|
724 |
|
---|
725 | #----------------------------#
|
---|
726 | build_Makefile() {
|
---|
727 | #----------------------------#
|
---|
728 | echo -n "Creating Makefile... "
|
---|
729 | cd $JHALFSDIR/commands
|
---|
730 |
|
---|
731 | # Start with a clean Makefile.tmp file
|
---|
732 | >$MKFILE.tmp
|
---|
733 |
|
---|
734 | chapter4_Makefiles
|
---|
735 | chapter5_Makefiles
|
---|
736 | chapter6_Makefiles
|
---|
737 | chapter789_Makefiles
|
---|
738 |
|
---|
739 |
|
---|
740 | # Add a header, some variables and include the function file
|
---|
741 | # to the top of the real Makefile.
|
---|
742 | (
|
---|
743 | cat << EOF
|
---|
744 | $HEADER
|
---|
745 |
|
---|
746 | SRC= /sources
|
---|
747 | LFS= $BUILDDIR
|
---|
748 | PAGE= $PAGE
|
---|
749 | TIMEZONE= $TIMEZONE
|
---|
750 |
|
---|
751 | include functions
|
---|
752 |
|
---|
753 | EOF
|
---|
754 | ) > $MKFILE
|
---|
755 |
|
---|
756 |
|
---|
757 | # Add chroot commands
|
---|
758 | i=1
|
---|
759 | for file in chapter06/*chroot* ; do
|
---|
760 | chroot=`cat $file | sed -e '/#!\/bin\/sh/d' -e 's@ \\\@ @g' | tr -d '\n' | sed \
|
---|
761 | -e 's/ */ /g' -e 's|\\$|&&|g' -e 's|exit||g' -e 's|$| -c|' \
|
---|
762 | -e 's|"$$LFS"|$(LFS)|' -e 's|set -e||'`
|
---|
763 | echo -e "CHROOT$i= $chroot\n" >> $MKFILE
|
---|
764 | i=`expr $i + 1`
|
---|
765 | done
|
---|
766 |
|
---|
767 | # Drop in the main target 'all:' and the chapter targets with each sub-target
|
---|
768 | # as a dependency.
|
---|
769 | (
|
---|
770 | cat << EOF
|
---|
771 | all: chapter4 chapter5 chapter6 chapter789
|
---|
772 | @\$(call echo_finished,$VERSION)
|
---|
773 |
|
---|
774 | chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
|
---|
775 |
|
---|
776 | chapter5: chapter4 $chapter5
|
---|
777 |
|
---|
778 | chapter6: chapter5 $chapter6
|
---|
779 |
|
---|
780 | chapter789: chapter6 $chapter789
|
---|
781 |
|
---|
782 | clean-all: clean
|
---|
783 | rm -rf ./*
|
---|
784 |
|
---|
785 | clean: clean-chapter5 clean-chapter4
|
---|
786 |
|
---|
787 | clean-chapter4:
|
---|
788 | -userdel lfs
|
---|
789 | rm -rf /home/lfs
|
---|
790 | rm -rf \$(LFS)/tools
|
---|
791 | rm -f /tools
|
---|
792 | rm -f envars
|
---|
793 | rm -f 02* logs/02*.log
|
---|
794 |
|
---|
795 | clean-chapter5:
|
---|
796 | rm -rf \$(LFS)/tools/*
|
---|
797 | rm -f $chapter5
|
---|
798 | cd logs && rm -f $chapter5 && cd ..
|
---|
799 |
|
---|
800 | EOF
|
---|
801 | ) >> $MKFILE
|
---|
802 |
|
---|
803 | # Bring over the items from the Makefile.tmp
|
---|
804 | cat $MKFILE.tmp >> $MKFILE
|
---|
805 | rm $MKFILE.tmp
|
---|
806 | echo -ne "done\n"
|
---|
807 | }
|
---|
808 |
|
---|
809 | #----------------------------#
|
---|
810 | run_make() {
|
---|
811 | #----------------------------#
|
---|
812 | # Test if make must be run.
|
---|
813 | if [ "$RUNMAKE" = "1" ] ; then
|
---|
814 | # Build the system
|
---|
815 | if [ -e $MKFILE ] ; then
|
---|
816 | echo -ne "Building the LFS system...\n"
|
---|
817 | cd $JHALFSDIR && make
|
---|
818 | echo -ne "done\n"
|
---|
819 | fi
|
---|
820 | fi
|
---|
821 | }
|
---|
822 |
|
---|
823 |
|
---|
824 |
|
---|
825 | ###################################
|
---|
826 | ### MAIN ###
|
---|
827 | ###################################
|
---|
828 |
|
---|
829 | # Test to make sure we're running the build as root
|
---|
830 |
|
---|
831 | if [ "$UID" != "0" ] ; then
|
---|
832 | echo "You must be logged in as root to successfully build LFS."
|
---|
833 | exit 1
|
---|
834 | fi
|
---|
835 |
|
---|
836 | # Evaluate any command line switches
|
---|
837 |
|
---|
838 | while test $# -gt 0 ; do
|
---|
839 | case $1 in
|
---|
840 | --version | -V )
|
---|
841 | echo "$version"
|
---|
842 | exit 0
|
---|
843 | ;;
|
---|
844 |
|
---|
845 | --help | -h )
|
---|
846 | echo "$usage"
|
---|
847 | exit 0
|
---|
848 | ;;
|
---|
849 |
|
---|
850 | --LFS-version | -L )
|
---|
851 | test $# = 1 && eval "$exit_missing_arg"
|
---|
852 | shift
|
---|
853 | case $1 in
|
---|
854 | dev* | SVN | trunk )
|
---|
855 | LFSVRS=development
|
---|
856 | ;;
|
---|
857 | testing | 6.1.1 )
|
---|
858 | LFSVRS=6.1.1
|
---|
859 | ;;
|
---|
860 | * )
|
---|
861 | echo "$1 is an unsupported version at this time."
|
---|
862 | exit 1
|
---|
863 | ;;
|
---|
864 | esac
|
---|
865 | ;;
|
---|
866 |
|
---|
867 | --directory | -d )
|
---|
868 | test $# = 1 && eval "$exit_missing_arg"
|
---|
869 | shift
|
---|
870 | BUILDDIR=$1
|
---|
871 | ;;
|
---|
872 |
|
---|
873 | --download-client | -D )
|
---|
874 | test $# = 1 && eval "$exit_missing_arg"
|
---|
875 | shift
|
---|
876 | DL=$1
|
---|
877 | ;;
|
---|
878 |
|
---|
879 | --working-copy | -W )
|
---|
880 | test $# = 1 && eval "$exit_missing_arg"
|
---|
881 | shift
|
---|
882 | if [ -f $1/patches.ent ] ; then
|
---|
883 | WC=1
|
---|
884 | BOOK=$1
|
---|
885 | else
|
---|
886 | echo -e "\nLook like $1 isn't a supported working copy."
|
---|
887 | echo -e "Verify your selection and the command line.\n"
|
---|
888 | exit 1
|
---|
889 | fi
|
---|
890 | ;;
|
---|
891 |
|
---|
892 | --testsuites | -T ) TEST=1 ;;
|
---|
893 |
|
---|
894 | --get-packages | -P ) HPKG=1 ;;
|
---|
895 |
|
---|
896 | --run-make | -M ) RUNMAKE=1 ;;
|
---|
897 |
|
---|
898 | --no-toolchain-test ) TOOLCHAINTEST=0 ;;
|
---|
899 |
|
---|
900 | --page_size )
|
---|
901 | test $# = 1 && eval "$exit_missing_arg"
|
---|
902 | shift
|
---|
903 | case $1 in
|
---|
904 | letter | A4 )
|
---|
905 | PAGE=$1
|
---|
906 | ;;
|
---|
907 | * )
|
---|
908 | echo "$1 isn't a supported page size."
|
---|
909 | exit 1
|
---|
910 | ;;
|
---|
911 | esac
|
---|
912 | ;;
|
---|
913 |
|
---|
914 |
|
---|
915 | --timezone )
|
---|
916 | test $# = 1 && eval "$exit_missing_arg"
|
---|
917 | shift
|
---|
918 | if [ -f /usr/share/zoneinfo/$1 ] ; then
|
---|
919 | TIMEZONE=$1
|
---|
920 | else
|
---|
921 | echo -e "\nLook like $1 isn't a valid timezone description."
|
---|
922 | echo -e "Verify your selection and the command line.\n"
|
---|
923 | exit 1
|
---|
924 | fi
|
---|
925 | ;;
|
---|
926 |
|
---|
927 | --fstab )
|
---|
928 | test $# = 1 && eval "$exit_missing_arg"
|
---|
929 | shift
|
---|
930 | if [ -f $1 ] ; then
|
---|
931 | FSTAB=$1
|
---|
932 | else
|
---|
933 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
934 | exit 1
|
---|
935 | fi
|
---|
936 | ;;
|
---|
937 |
|
---|
938 | --kernel-config | -C )
|
---|
939 | test $# = 1 && eval "$exit_missing_arg"
|
---|
940 | shift
|
---|
941 | if [ -f $1 ] ; then
|
---|
942 | CONFIG=$1
|
---|
943 | else
|
---|
944 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
945 | exit 1
|
---|
946 | fi
|
---|
947 | ;;
|
---|
948 |
|
---|
949 | * )
|
---|
950 | echo "$usage"
|
---|
951 | exit 1
|
---|
952 | ;;
|
---|
953 | esac
|
---|
954 | shift
|
---|
955 | done
|
---|
956 |
|
---|
957 | # Find the download client to use, if not already specified.
|
---|
958 |
|
---|
959 | if [ -z $DL ] ; then
|
---|
960 | if [ `type -p wget` ] ; then
|
---|
961 | DL=wget
|
---|
962 | elif [ `type -p curl` ] ; then
|
---|
963 | DL=curl
|
---|
964 | else
|
---|
965 | eval "$no_dl_client"
|
---|
966 | fi
|
---|
967 | fi
|
---|
968 |
|
---|
969 | [[ ! -d $JHALFSDIR ]] && mkdir -pv $JHALFSDIR
|
---|
970 | [[ "$PWD" != "$JHALFSDIR" ]] && cp -v $0 $XSL $FILES $JHALFSDIR/
|
---|
971 | [[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
|
---|
972 | >$LOGDIR/$LOG
|
---|
973 |
|
---|
974 | get_book
|
---|
975 | build_Makefile
|
---|
976 | run_make
|
---|
977 |
|
---|