source: HLFS/jhahlfs@ 1327ccc

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 1327ccc was 1690d1e, checked in by George Boudreau <georgeb@…>, 19 years ago

Adjust script coding style

  • Property mode set to 100755
File size: 44.9 KB
Line 
1#!/bin/sh
2set -e # Enable error trapping
3set -u # Trap undefined variables.. Forces the programmer
4 # to define a variable before using it
5
6#
7# Load the configuration file
8#
9source jhahlfs.conf
10
11# VT100 colors
12declare -r BLACK=$'\e[1;30m'
13declare -r DK_GRAY=$'\e[0;30m'
14
15declare -r RED=$'\e[31m'
16declare -r GREEN=$'\e[32m'
17declare -r YELLOW=$'\e[33m'
18declare -r BLUE=$'\e[34m'
19declare -r MAGENTA=$'\e[35m'
20declare -r CYAN=$'\e[36m'
21declare -r WHITE=$'\e[37m'
22
23declare -r OFF=$'\e[0m'
24declare -r BOLD=$'\e[1m'
25declare -r REVERSE=$'\e[7m'
26declare -r HIDDEN=$'\e[8m'
27
28declare -r tab_=$'\t'
29declare -r nl_=$'\n'
30
31declare -r DD_BORDER="${BOLD}${WHITE}==============================================================================${OFF}"
32declare -r SD_BORDER="${BOLD}${WHITE}------------------------------------------------------------------------------${OFF}"
33declare -r STAR_BORDER="${BOLD}${WHITE}******************************************************************************${OFF}"
34
35# bold yellow > < pair
36declare -r R_arrow=$'\e[1;33m>\e[0m'
37declare -r L_arrow=$'\e[1;33m<\e[0m'
38
39
40# START predefine some internal vars.. proper programming style
41
42 # If the var BOOK contains something then, maybe, it points
43 # to a working doc.. set WC=1, else 'null'
44WC=${BOOK:+1}
45
46CLEAN=0 # Clean out build dir?
47DL= # The download app to use
48PREV= # name of previous script processed
49chapter5=
50chapter6=
51chapter7=
52
53# END predefined vars section
54
55_inline_doc="
56${GREEN}
57 This script, jhahlfs, strives to create an accurate makefile
58 directly from the xml files used to generate the Hardened Linux From
59 Scratch document.
60 The usage of this script assumes you have read and are familiar with
61 the book and therefore the configuration variables found in jhahlfs.conf
62 will have meaning to you. There are a limited number of command line
63 switches which, if used, will override the config file settings.
64
65 NOTES::
66 *. The resulting Makefile takes considerable time to run to completion,
67 lay in a supply of caffeine beverages.
68
69 *. The document, Hardened Linux From Scratch, specifies a Linux kernel
70 >=2.6.2 and GCC >=3.0 for proper compilation.
71
72 *. It is recommended that you temporarily unpack your linux kernel and
73 run <make menuconfig> and configure the kernal as per the book and save
74 the resulting .config file.
75
76 *. Chapter07 contains numerous command files which require customizing
77 before you start 129-console, 131-profile, 133-hosts, 134-network,
78 135-fstab, 136-kernel.
79${OFF}"
80
81version="
82jhahlfs development \$Date$
83
84Written by George Boudreau
85
86Based on the jhalfs code written by Jeremy Huntwork and Manuel Canales Esparcia.
87
88This program is published under the ${WHITE}Gnu General Public License, Version 2.${OFF}
89"
90
91usage() {
92 'clear'
93cat <<- -EOF-
94${DD_BORDER}
95${BOLD}
96${WHITE} Usage: $0 ${YELLOW}[OPTION]
97${CYAN}
98Options:
99${YELLOW} -h, --help
100${CYAN} print this help, then exit
101${YELLOW} --readme
102${CYAN} print a small readme file, then exit
103${YELLOW} -V, --version
104${CYAN} print version number, then exit
105${YELLOW} -d --directory DIR
106${CYAN} use DIR directory for building HLFS; all files jhahlfs produces will be
107 in the directory DIR/jhahlfs. Default is \"/mnt/lfs\".
108${YELLOW} --rebuild
109${CYAN} clean the build directory before to perfom any other task. The directory
110 is cleaned only if it was populated by a previous jhahlfs run.
111${YELLOW} -P, --get-packages
112${CYAN} download the packages and patches. This assumes that the server declared in the
113 jhahlfs.conf file has the proper packages and patches for the book version being
114 processed.
115${YELLOW} -W, --working-copy DIR
116${CYAN} use the local working copy placed in DIR as the HLFS book
117${YELLOW} -L, --HLFS-version VER
118${CYAN} checkout VER version of the HLFS book. Supported versions at this time are:
119 dev* | trunk | SVN aliases for Development HLFS
120${YELLOW} --fstab FILE
121${CYAN} use FILE as the /etc/fstab file for the HLFS system. If not specified,
122 a default /etc/fstab file with dummy values is created.
123${YELLOW} -C, --kernel-config FILE
124${CYAN} use the kernel configuration file specified in FILE to build the kernel.
125 if the file is not found, or if not specified, the kernel build is skipped.
126${YELLOW} -M, --run-make
127${CYAN} run make on the generated Makefile
128${DD_BORDER}
129-EOF-
130 exit
131}
132
133
134help="\
135Try '$0 --help' for more information."
136
137no_empty_builddir() {
138 'clear'
139cat <<- -EOF-
140${DD_BORDER}
141
142${tab_}${tab_}${RED}W A R N I N G${OFF}
143${GREEN}
144 Looks like the \$BUILDDIR directory contains subdirectories
145 from a previous HLFS build.
146
147 Please format the partition mounted on \$BUILDDIR or set
148 a different build directory before running jhahlfs.
149${OFF}
150${DD_BORDER}
151-EOF-
152 exit
153}
154
155exit_missing_arg="\
156echo \"Option '\$1' requires an argument\" >&2
157echo \"\$help\" >&2
158exit 1"
159
160no_dl_client="\
161echo \"Could not find a way to download the HLFS sources.\" >&2
162echo \"Attempting to continue.\" >&2"
163
164HEADER="# This file is automatically generated by jhahlfs
165# DO NOT EDIT THIS FILE MANUALLY
166#
167# Generated on `date \"+%F %X %Z\"`"
168
169#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
170#-----------------------#
171simple_error() { # Basic error trap.... JUST DIE
172#-----------------------#
173 # If +e then disable text output
174 if [[ "$-" =~ "e" ]]; then
175 echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
176 fi
177}
178
179see_ya() {
180 echo -e "\n\t${BOLD}${WHITE}Goodbye and thank you for choosing ${YELLOW}JHAHLFS\n${OFF}"
181}
182##### Simple error TRAPS
183# ctrl-c SIGINT
184# ctrl-y
185# ctrl-z SIGTSTP
186# SIGHUP 1 HANGUP
187# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
188# SIGQUIT 3
189# SIGKILL 9 KILL
190# SIGTERM 15 TERMINATION
191# SIGSTOP 17,18,23 STOP THE PROCESS
192#####
193set -e
194trap see_ya 0
195trap simple_error ERR
196trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
197#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
198
199
200###################################
201### FUNCTIONS ###
202###################################
203
204#----------------------------#
205check_requirements() { # Simple routine to validate gcc and kernel versions against requirements
206#----------------------------#
207 # Minimum values acceptable
208 # bash 3.0>
209 # gcc 3.0>
210 # kernel 2.6.2>
211
212 [[ $1 = "1" ]] && echo "${nl_}BASH: ${L_arrow}${GREEN}${BASH_VERSION}${R_arrow}"
213 case $BASH_VERSION in
214 [3-9].*) ;;
215 *) 'clear'
216 echo -e "
217$DD_BORDER
218\t\t${OFF}${RED}BASH version ${BOLD}${YELLOW}-->${WHITE} $BASH_VERSION ${YELLOW}<--${OFF}${RED} is too old.
219\t\t This script requires 3.0${OFF}${RED} or greater
220$DD_BORDER"
221 exit 1
222 ;;
223 esac
224
225 [[ $1 = "1" ]] && echo "GCC: ${L_arrow}${GREEN}`gcc -dumpversion`${R_arrow}"
226 case `gcc -dumpversion` in
227 [3-9].[0-9].* ) ;;
228 *) 'clear'
229 echo -e "
230$DD_BORDER
231\t\t${OFF}${RED}GCC version ${BOLD}${YELLOW}-->${WHITE} $(gcc -dumpversion) ${YELLOW}<--${OFF}${RED} is too old.
232\t\t This script requires ${BOLD}${WHITE}3.0${OFF}${RED} or greater
233$DD_BORDER"
234 exit 1
235 ;;
236 esac
237
238 #
239 # >>>> Check kernel version against the minimum acceptable level <<<<
240 #
241 [[ $1 = "1" ]] && echo "LINUX: ${L_arrow}${GREEN}`uname -r`${R_arrow}"
242
243 local IFS
244 declare -i major minor revision change
245 min_kernel_vers=2.6.2
246
247 IFS=".-" # Split up w.x.y.z as well as w.x.y-rc (catch release candidates)
248 set -- $min_kernel_vers # set postional parameters to minimum ver values
249 major=$1; minor=$2; revision=$3
250 #
251 set -- `uname -r` # Set postional parameters to user kernel version
252 #Compare against minimum acceptable kernel version..
253 (( $1 > major )) && return
254 (( $1 == major )) && ((( $2 > minor )) ||
255 ((( $2 == minor )) && (( $3 >= revision )))) && return
256
257 # oops.. write error msg and die
258 echo -e "
259$DD_BORDER
260\t\t${OFF}${RED}The kernel version ${BOLD}${YELLOW}-->${WHITE} $(uname -r) ${YELLOW}<--${OFF}${RED} is too old.
261\t\tThis script requires version ${BOLD}${WHITE}$min_kernel_vers${OFF}${RED} or greater
262$DD_BORDER"
263 exit 1
264}
265
266
267#----------------------------#
268validate_config() { # Are the config values sane (within reason)
269#----------------------------#
270 local -r PARAM_LIST="BUILDDIR HPKG MODEL TEST TOOLCHAINTEST STRIP VIMLANG PAGE GRSECURITY_HOST RUNMAKE"
271 local -r ERROR_MSG='${OFF}${RED}The variable \"${GREEN}${config_param}${RED}\" value ${BOLD}${YELLOW}--\>${WHITE}${!config_param}${YELLOW}\<--${OFF}${RED} is invalid, check the config file ${GREEN}\<jhahlfs.conf\>${OFF}'
272 local -r PARAM_VALS='${WHITE}${config_param}: ${L_arrow}${GREEN}${!config_param}${R_arrow}'
273 local config_param
274 local validation_str
275
276 write_error_and_die() {
277 echo -e "\n${DD_BORDER}"
278 echo "`eval echo ${ERROR_MSG}`" >&2
279 echo -e "${DD_BORDER}\n"
280 exit 1
281 }
282
283 set +e
284
285 for config_param in $PARAM_LIST; do
286 [[ $1 = "1" ]] && echo -e "`eval echo $PARAM_VALS`"
287 case $config_param in
288 BUILDDIR) # We cannot have an <empty> or </> root mount point
289 if [[ "xx x/x" =~ "x${!config_param}x" ]]; then
290 write_error_and_die
291 fi
292 continue ;;
293 HPKG) validation_str="x0x x1x" ;;
294 RUNMAKE) validation_str="x0x x1x" ;;
295 TEST) validation_str="x0x x1x" ;;
296 STRIP) validation_str="x0x x1x" ;;
297 VIMLANG) validation_str="x0x x1x" ;;
298 TOOLCHAINTEST) validation_str="x0x x1x" ;;
299 GRSECURITY_HOST) validation_str="x0x x1x" ;;
300
301 MODEL) validation_str="xglibcx xuclibcx" ;;
302 PAGE) validation_str="xletterx xA4x" ;;
303 *)
304 echo "WHAT PARAMETER IS THIS.. <<${config_param}>>"
305 exit
306 ;;
307 esac
308 # This is the 'regexp' test available in bash-3.0..
309 # using it as a poor man's test for substring
310 if [[ ! "${validation_str}" =~ "x${!config_param}x" ]] ; then
311 # parameter value entered is no good
312 write_error_and_die
313 fi
314 done # for loop
315
316 for config_param in LC_ALL LANG; do
317 [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
318 [[ -z "${!config_param}" ]] && continue
319 # See it the locale values exist on this machine
320 [[ "`locale -a | grep -c ${!config_param}`" > 0 ]] && continue
321
322 # If you make it this far then there is a problem
323 write_error_and_die
324 done
325
326 for config_param in FSTAB CONFIG KEYMAP BOOK; do
327 [[ $1 = "1" ]] && echo "`eval echo $PARAM_VALS`"
328 # If this is not a working copy, ie the default book, then skip
329 [[ -z $WC ]] && continue
330 [[ -z "${!config_param}" ]] && continue
331 [[ -e "${!config_param}" ]] && [[ -s "${!config_param}" ]] && continue
332
333 # If you make it this far then there is a problem
334 write_error_and_die
335 done
336
337 set -e
338 echo "$tab_${BOLD}${YELLOW} Config parameters look good${OFF}${nl_}"
339}
340
341
342#----------------------------#
343build_patches_file() { # Supply a suitably formated list of patches.
344#----------------------------#
345 local saveIFS=$IFS
346
347 LOC_add_patches_entry() {
348 for f in `grep "/$1-" patcheslist_.wget`; do
349 basename $f | sed "s|${2}|\&${1}-version;|" >> patches
350 done
351 }
352
353 xsltproc --nonet \
354 --xinclude \
355 -o patcheslist_.wget \
356 hlfs-patcheslist_.xsl \
357 $BOOK/index.xml > /dev/null 2>&1
358
359 rm -f patches
360
361 IFS=$'\x0A' # Modify the 'internal field separator' to break on 'LF' only
362 for f in `cat packages`; do
363 IFS=$saveIFS
364 LOC_add_patches_entry \
365 `echo $f | sed -e 's/-version//' \
366 -e 's/-file.*//' \
367 -e 's/"//g' \
368 -e 's/uclibc/uClibc/'`
369 done
370
371 # .... U G L Y .... what to do with the grsecurity patch to the kernel..
372 for f in `grep "/grsecurity-" patcheslist_.wget`; do
373 basename $f >> patches
374 done
375
376 IFS=$saveIFS
377 rm -f patcheslist_.wget
378}
379
380
381#----------------------------#
382clean_builddir() { #
383#----------------------------#
384 # Test if the clean must be done.
385 if [ "$CLEAN" = "1" ] ; then
386 # Test to make sure we're running the clean as root
387 if [ "$UID" != "0" ] ; then
388 echo "You must be logged in as root to clean the build directory."
389 exit 1
390 fi
391 # Test to make sure that the build directory was populated by jhahlfs
392 if [ ! -d $JHAHLFSDIR ] || [ ! -d $BUILDDIR/sources ] ; then
393 echo "Looks like $BUILDDIR was not populated by a previous jhahlfs run."
394 exit 1
395 else
396 # Clean the build directory
397 echo -ne "Cleaning $BUILDDIR...\n"
398 rm -rf $BUILDDIR/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,tools,usr,var}
399 echo -ne "Cleaning $JHAHLFSDIR...\n"
400 rm -rf $JHAHLFSDIR/{0*,1*,envars,sources-dir,commands,logs,Makefile,dump-hlfs-scripts.xsl,hlfs-functions,packages,patches}
401 echo -ne "Cleaning remainig extracted sources in $BUILDDIR/sources...\n"
402 rm -rf `find $BUILDDIR/sources/* -maxdepth 0 -type d`
403 echo -ne "done\n"
404 fi
405 fi
406}
407
408#----------------------------#
409get_book() { #
410#----------------------------#
411 cd $JHAHLFSDIR
412
413 if [ -z $WC ] ; then
414 # Check for Subversion instead of just letting the script hit 'svn' and fail.
415 test `type -p svn` || eval "echo \"This feature requires Subversion.\"
416 exit 1"
417
418 echo -n "Downloading the HLFS Book, version $HLFSVRS... "
419 # Grab a fresh HLFS book if it's missing, otherwise, update it from the
420 # repo. If we've already extracted the commands, move on to getting the
421 # sources.
422 if [ -d hlfs-$HLFSVRS ] ; then
423 cd hlfs-$HLFSVRS
424 if LC_ALL=C svn up | grep -q At && \
425 test -d $JHAHLFSDIR/commands && \
426 test -f $JHAHLFSDIR/packages && \
427 test -f $JHAHLFSDIR/patches ; then
428 echo -ne "done\n"
429 # Set the canonical book version
430 cd $JHAHLFSDIR
431 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
432 get_sources
433 else
434 echo -ne "done\n"
435 extract_commands
436 fi
437 else
438 case $HLFSVRS in
439 development)
440 svn co $SVN/HLFS/trunk/BOOK hlfs-$HLFSVRS >>$LOGDIR/$LOG 2>&1
441 ;;
442 *) echo -e "${RED}Invalid document version selected${OFF}"
443 ;;
444 esac
445 echo -ne "done\n"
446 extract_commands
447 fi
448 else
449 echo -ne "Using $BOOK as book's sources ...\n"
450 extract_commands
451 fi
452}
453
454#----------------------------#
455extract_commands() { #
456#----------------------------#
457 # Check for libxslt instead of just letting the script hit 'xsltproc' and fail.
458 test `type -p xsltproc` || eval "echo \"This feature requires libxslt.\"
459 exit 1"
460
461 cd $JHAHLFSDIR
462 VERSION=`grep "ENTITY version " $BOOK/general.ent | sed 's@<!ENTITY version "@@;s@">@@'`
463
464 # Start clean
465 if [ -d commands ]; then
466 rm -rf commands
467 mkdir -v commands
468 fi
469 echo -n "Extracting commands..."
470
471 # Dump the commands in shell script form from the HLFS book.
472 xsltproc --nonet \
473 --xinclude \
474 --stringparam model $MODEL \
475 --stringparam testsuite $TEST \
476 --stringparam toolchaintest $TOOLCHAINTEST \
477 --stringparam vim-lang $VIMLANG \
478 -o ./commands/ $XSL $BOOK/index.xml >>$LOGDIR/$LOG 2>&1
479
480 # Make the scripts executable.
481 chmod -R +x $JHAHLFSDIR/commands
482
483 # Grab the patches and package names.
484 cd $JHAHLFSDIR
485 for i in patches packages ; do rm -f $i ; done
486 grep "\-version" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@' \
487 -e '/generic/d' >> packages
488
489 # Download the vim-lang package if it must be installed
490 if [ "$VIMLANG" = "1" ] ; then
491 echo `grep "vim" packages | sed 's@vim@&-lang@'` >> packages
492 fi
493 echo `grep "udev-config-file" $BOOK/general.ent | sed -e 's@<!ENTITY @@' -e 's@">@"@'` >> packages
494
495 # There is no HLFS patches.ent file so we will create one.
496 build_patches_file
497
498 # Done. Moving on...
499 echo -ne "done\n"
500 get_sources
501}
502
503#----------------------------#
504download() { # Download file, write name to MISSING_FILES.DMP if an error
505#----------------------------#
506 cd $BUILDDIR/sources
507
508 # Hackish fix for the bash-doc, glibc-{linuxthreads,libidn} and
509 # module-init-tools-testsuite packages that don't conform to
510 # norms in the URL scheme.
511 DIR=`echo $1 | sed 's@-doc@@;s@-linuxthreads@@;s@-libidn@@;s@-testsuite@@'`
512
513 # Find the md5 sum for this package.
514 if [ $2 != MD5SUMS ] ; then
515 set +e
516 MD5=`grep " $2" MD5SUMS`
517 if [ $? -ne 0 ]; then
518 set -e
519 echo "${RED}$2 not found in MD5SUMS${OFF}"
520 echo "$2 not found in MD5SUMS" >> MISSING_FILES.DMP
521 return
522 fi
523 set -e
524 fi
525
526 if [ ! -f $2 ] ; then
527 case $DL in
528 wget ) wget $HTTP/$DIR/$2 ;;
529 curl ) `curl -# $HTTP/$DIR/$2 -o $2` ;;
530 * ) echo "$DL not supported at this time." ;;
531 esac
532 elif ! echo "$MD5" | md5sum -c - >/dev/null 2>/dev/null ; then
533 case $DL in
534 wget ) wget -c $HTTP/$DIR/$2 ;;
535 curl ) `curl -# -C - $HTTP/$DIR/$2 -o $2` ;;
536 * ) echo "$DL not supported at this time." ;;
537 esac
538 fi
539
540 if [ $2 != MD5SUMS ] && ! echo "$MD5" | md5sum -c - ; then
541 exit 1
542 fi
543 if [ $2 != MD5SUMS ] ; then
544 echo `grep "$MD5" MD5SUMS` >> MD5SUMS-$VERSION
545 fi
546}
547
548
549#----------------------------#
550get_sources() { #
551#----------------------------#
552 local IFS
553
554 # Test if the packages must be downloaded
555 if [ ! "$HPKG" = "1" ] ; then
556 return
557 fi
558
559 # Modify the 'internal field separator' to break on 'LF' only
560 IFS=$'\x0A'
561
562 if [ ! -d $BUILDDIR/sources ] ; then mkdir $BUILDDIR/sources ; fi
563 cd $BUILDDIR/sources
564
565 > MISSING_FILES.DMP # Files not in md5sum end up here
566
567 if [ -f MD5SUMS ] ; then rm MD5SUMS ; fi
568 if [ -f MD5SUMS-$VERSION ] ; then rm MD5SUMS-$VERSION ; fi
569
570 # Retrieve the master md5sum file
571 download "" MD5SUMS
572
573 # Iterate through each package and grab it, along with any patches it needs.
574 for i in `cat $JHAHLFSDIR/packages` ; do
575 PKG=`echo $i | sed -e 's/-version.*//' \
576 -e 's/-file.*//' \
577 -e 's/uclibc/uClibc/' `
578
579 # Needed for Groff patchlevel patch on UTF-8 branch
580 GROFFLEVEL=`grep "groff-patchlevel" $JHAHLFSDIR/packages | sed -e 's/groff-patchlevel //' -e 's/"//g'`
581
582 #
583 # How to deal with orphan packages..??
584 #
585 VRS=`echo $i | sed -e 's/.* //' -e 's/"//g'`
586 case "$PKG" in
587 "expect-lib" ) continue ;; # not valid packages
588 "linux-dl" ) continue ;;
589 "groff-patchlevel" ) continue ;;
590 "uClibc-patch" ) continue ;;
591
592 "tcl" ) FILE="$PKG$VRS-src.tar.bz2" ; download $PKG $FILE ;;
593 "vim-lang" ) FILE="vim-$VRS-lang.tar.bz2"; PKG="vim" ; download $PKG $FILE ;;
594 "udev-config" ) FILE="$VRS" ; PKG="udev" ; download $PKG $FILE ;;
595
596 "uClibc-locale" ) FILE="$PKG-$VRS.tar.bz2" ; PKG="uClibc"
597 download $PKG $FILE
598 # There can be no patches for this file
599 continue ;;
600
601 "gcc" ) download $PKG "gcc-core-$VRS.tar.bz2"
602 download $PKG "gcc-g++-$VRS.tar.bz2"
603 ;;
604 "glibc") download $PKG "$PKG-$VRS.tar.bz2"
605 download $PKG "$PKG-libidn-$VRS.tar.bz2"
606 ;;
607 * ) FILE="$PKG-$VRS.tar.bz2"
608 download $PKG $FILE
609 ;;
610 esac
611
612 for patch in `grep "$PKG-&$PKG" $JHAHLFSDIR/patches` ; do
613 PATCH=`echo $patch | sed 's@&'$PKG'-version;@'$VRS'@'`
614 download $PKG $PATCH
615 done
616
617 done
618
619 # .... U G L Y .... what to do with the grsecurity patch to the kernel..
620 download grsecurity `grep grsecurity $JHAHLFSDIR/patches`
621
622 # .... U G L Y .... deal with uClibc-locale-xxxxx.tar.bz2 format issue.
623 bzcat uClibc-locale-030818.tar.bz2 | gzip > uClibc-locale-030818.tgz
624
625 if [[ -s $BUILDDIR/sources/MISSING_FILES.DMP ]]; then
626 echo -e "\n\n${tab_}${RED} One or more files were not retrieved.\n${tab_} Check <MISSING_FILES.DMP> for names ${OFF}\n\n"
627 fi
628}
629
630
631#----------------------------#
632_IS_() { # Function to test build scripts names
633#----------------------------#
634 # Returns substr $2 or null str
635 # Must use string testing
636 case $1 in
637 *$2*) echo "$2" ;;
638 *) echo "" ;;
639 esac
640}
641
642#----------------------------#
643chapter4_Makefiles() { # Initialization of the system
644#----------------------------#
645 local TARGET LOADER
646
647 echo "${YELLOW} Processing Chapter-4 scripts ${OFF}"
648
649 # Define a few model dependant variables
650 if [[ ${MODEL} = "uclibc" ]]; then
651 TARGET="tools-linux-uclibc"; LOADER="ld-uClibc.so.0"
652 else
653 TARGET="tools-linux-gnu"; LOADER="ld-linux.so.2"
654 fi
655
656 # 022-
657 # If /home/hlfs is already present in the host, we asume that the
658 # hlfs user and group are also presents in the host, and a backup
659 # of their bash init files is made.
660(
661cat << EOF
662020-creatingtoolsdir:
663 @\$(call echo_message, Building)
664 @mkdir -v \$(HLFS)/tools && \\
665 rm -fv /tools && \\
666 ln -sv \$(HLFS)/tools /
667 @if [ ! -d \$(HLFS)/sources ]; then \\
668 mkdir \$(HLFS)/sources; \\
669 fi;
670 @chmod a+wt \$(HLFS)/sources && \\
671 touch \$@
672
673021-addinguser: 020-creatingtoolsdir
674 @\$(call echo_message, Building)
675 @if [ ! -d /home/hlfs ]; then \\
676 groupadd hlfs; \\
677 useradd -s /bin/bash -g hlfs -m -k /dev/null hlfs; \\
678 else \\
679 touch user-hlfs-exist; \\
680 fi;
681 @chown hlfs \$(HLFS)/tools && \\
682 chown hlfs \$(HLFS)/sources && \\
683 touch \$@
684
685022-settingenvironment: 021-addinguser
686 @\$(call echo_message, Building)
687 @if [ -f /home/hlfs/.bashrc -a ! -f /home/hlfs/.bashrc.XXX ]; then \\
688 mv -v /home/hlfs/.bashrc /home/hlfs/.bashrc.XXX; \\
689 fi;
690 @if [ -f /home/hlfs/.bash_profile -a ! -f /home/hlfs/.bash_profile.XXX ]; then \\
691 mv -v /home/hlfs/.bash_profile /home/hlfs/.bash_profile.XXX; \\
692 fi;
693 @echo "set +h" > /home/hlfs/.bashrc && \\
694 echo "umask 022" >> /home/hlfs/.bashrc && \\
695 echo "HLFS=\$(HLFS)" >> /home/hlfs/.bashrc && \\
696 echo "LC_ALL=POSIX" >> /home/hlfs/.bashrc && \\
697 echo "PATH=/tools/bin:/bin:/usr/bin" >> /home/hlfs/.bashrc && \\
698 echo "export HLFS LC_ALL PATH" >> /home/hlfs/.bashrc && \\
699 echo "" >> /home/hlfs/.bashrc && \\
700 echo "target=$(uname -m)-${TARGET}" >> /home/hlfs/.bashrc && \\
701 echo "ldso=/tools/lib/${LOADER}" >> /home/hlfs/.bashrc && \\
702 echo "export target ldso" >> /home/hlfs/.bashrc && \\
703 echo "source $JHAHLFSDIR/envars" >> /home/hlfs/.bashrc && \\
704 chown hlfs:hlfs /home/hlfs/.bashrc && \\
705 touch envars && \\
706 touch \$@
707EOF
708) >> $MKFILE.tmp
709
710}
711
712#----------------------------#
713chapter5_Makefiles() { # Bootstrap or temptools phase
714#----------------------------#
715
716 echo "${YELLOW} Processing Chapter-5 scripts${OFF}"
717
718 for file in chapter05/* ; do
719 # Keep the script file name
720 this_script=`basename $file`
721
722 # Skip this script depending on jhahlfs.conf flags set.
723 case $this_script in
724 # If no testsuites will be run, then TCL, Expect and DejaGNU aren't needed
725 *tcl* ) [[ "$TOOLCHAINTEST" = "0" ]] && continue; ;;
726 *expect* ) [[ "$TOOLCHAINTEST" = "0" ]] && continue; ;;
727 *dejagnu* ) [[ "$TOOLCHAINTEST" = "0" ]] && continue; ;;
728 # Test if the stripping phase must be skipped
729 *stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
730 # Select the appropriate library
731 *glibc*) [[ ${MODEL} = "uclibc" ]] && continue ;;
732 *uclibc*) [[ ${MODEL} = "glibc" ]] && continue ;;
733 *) ;;
734 esac
735
736 # First append each name of the script files to a list (this will become
737 # the names of the targets in the Makefile
738 chapter5="$chapter5 $this_script"
739
740 # Grab the name of the target (minus the -headers or -cross in the case of gcc
741 # and binutils in chapter 5)
742 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@' -e 's@-cross@@' -e 's@-headers@@'`
743
744 # >>>>>>>>>> U G L Y <<<<<<<<<
745 # Adjust 'name' and patch a few scripts on the fly..
746 case $name in
747 linux-libc) name=linux-libc-headers
748 ;;
749 uclibc) # this sucks as method to deal with gettext/libint inside uClibc
750 sed 's@^cd gettext-runtime@cd ../gettext-*/gettext-runtime@' -i chapter05/$this_script
751 ;;
752 gcc) # to compensate for the compiler test inside gcc (which fails), disable error trap
753 sed 's@^gcc -o test test.c@set +e; gcc -o test test.c@' -i chapter05/$this_script
754 ;;
755 esac
756
757 # Set the dependency for the first target.
758 if [ -z $PREV ] ; then PREV=022-settingenvironment ; fi
759
760
761 #--------------------------------------------------------------------#
762 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
763 #--------------------------------------------------------------------#
764 #
765 # Drop in the name of the target on a new line, and the previous target
766 # as a dependency. Also call the echo_message function.
767 echo -e "\n$this_script: $PREV
768 @\$(call echo_message, Building)" >> $MKFILE.tmp
769
770 # Find the version of the command files, if it corresponds with the building of
771 # a specific package
772 vrs=`grep "^$name-version" $JHAHLFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
773 # If $vrs isn't empty, we've got a package...
774 if [ "$vrs" != "" ] ; then
775 # Deal with non-standard names
776 case $name in
777 tcl) FILE="$name$vrs-src.tar" ;;
778 uclibc) FILE="uClibc-$vrs.tar" ;;
779 gcc) FILE=gcc-core-$vrs.tar ;;
780 *) FILE="$name-$vrs.tar" ;;
781 esac
782 # Insert instructions for unpacking the package and to set the PKGDIR variable.
783(
784cat << EOF
785 @\$(call unpack,$FILE)
786 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
787 chown -R hlfs \$(HLFS)\$(SRC)/\$\$ROOT && \\
788 echo "export PKGDIR=\$(HLFS)\$(SRC)/\$\$ROOT" > envars && \\
789EOF
790) >> $MKFILE.tmp
791 fi
792
793 case $this_script in
794 *binutils* ) # Dump the path to sources directory for later removal
795 echo -e '\techo "$(HLFS)$(SRC)/$$ROOT" >> sources-dir' >> $MKFILE.tmp
796 ;;
797 *adjusting* ) # For the Adjusting phase we must to cd to the binutils-build directory.
798 echo -e '\t@echo "export PKGDIR=$(HLFS)$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
799 ;;
800 * ) # Everything else, add a true statment so we don't confuse make
801 echo -e '\ttrue' >> $MKFILE.tmp
802 ;;
803 esac
804
805 # Insert date and disk usage at the top of the log file, the script run
806 # and date and disk usage again at the bottom of the log file.
807(
808cat << EOF
809 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(HLFS)\`\n" >logs/$this_script && \\
810 su - hlfs -c "source /home/hlfs/.bashrc && $JHAHLFSDIR/commands/$file" >>logs/$this_script 2>&1 && \\
811 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(HLFS)\`\n" >>logs/$this_script
812EOF
813) >> $MKFILE.tmp
814
815 # Remove the build directory(ies) except if the package build fails
816 # (so we can review config.cache, config.log, etc.)
817 # For Binutils the sources must be retained for some time.
818 if [ "$vrs" != "" ] ; then
819 if [[ ! `_IS_ $this_script binutils` ]]; then
820(
821cat << EOF
822 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
823 rm -r \$(HLFS)\$(SRC)/\$\$ROOT && \\
824 if [ -e \$(HLFS)\$(SRC)/$name-build ]; then \\
825 rm -r \$(HLFS)\$(SRC)/$name-build; \\
826 fi;
827EOF
828) >> $MKFILE.tmp
829 fi
830 fi
831
832 # Remove the Binutils pass 1 sources after a successful Adjusting phase.
833 if [[ `_IS_ $this_script adjusting` ]] ; then
834(
835cat << EOF
836 @rm -r \`cat sources-dir\` && \\
837 rm -r \$(HLFS)\$(SRC)/binutils-build && \\
838 rm sources-dir
839EOF
840) >> $MKFILE.tmp
841 fi
842
843 # Include a touch of the target name so make can check if it's already been made.
844 echo -e '\t@touch $@' >> $MKFILE.tmp
845 #
846 #--------------------------------------------------------------------#
847 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
848 #--------------------------------------------------------------------#
849
850 # Keep the script file name for Makefile dependencies.
851 PREV=$this_script
852 done # end for file in chapter05/*
853}
854
855
856#----------------------------#
857chapter6_Makefiles() { # sysroot or chroot build phase
858#----------------------------#
859 local TARGET LOADER
860
861 #
862 # Set these definitions early and only once
863 #
864 if [[ ${MODEL} = "uclibc" ]]; then
865 TARGET="pc-linux-uclibc"; LOADER="ld-uClibc.so.0"
866 else
867 TARGET="pc-linux-gnu"; LOADER="ld-linux.so.2"
868 fi
869
870 echo -e "${YELLOW} Processing Chapter-6 scripts ${OFF}"
871 for file in chapter06/* ; do
872 # Keep the script file name
873 this_script=`basename $file`
874
875 # Skip this script depending on jhahlfs.conf flags set.
876 case $this_script in
877 # We'll run the chroot commands differently than the others, so skip them in the
878 # dependencies and target creation.
879 *chroot* ) continue ;;
880 # Test if the stripping phase must be skipped
881 *-stripping* ) [[ "$STRIP" = "0" ]] && continue ;;
882 # Select the appropriate library
883 *glibc*) [[ ${MODEL} = "uclibc" ]] && continue ;;
884 *uclibc*) [[ ${MODEL} = "glibc" ]] && continue ;;
885 *) ;;
886 esac
887
888 # First append each name of the script files to a list (this will become
889 # the names of the targets in the Makefile
890 chapter6="$chapter6 $this_script"
891
892 # Grab the name of the target
893 name=`echo $this_script | sed -e 's@[0-9]\{3\}-@@'`
894
895 #
896 # Sed replacement for 'nodump' tag in xml scripts until Manuel has a chance to fix them
897 #
898 case $name in
899 kernfs) # Remove sysctl code if host does not have grsecurity enabled
900 if [[ "$GRSECURITY_HOST" = "0" ]]; then
901 sed '/sysctl/d' -i chapter06/$this_script
902 fi
903 ;;
904 module-init-tools)
905 if [[ "$TEST" = "0" ]]; then # This needs rework....
906 sed '/make distclean/d' -i chapter06/$this_script
907 fi
908 ;;
909 glibc) # PATCH.. Turn off error trapping for the remainder of the script.
910 sed 's|^make install|make install; set +e|' -i chapter06/$this_script
911 ;;
912 uclibc) # PATCH..
913 sed 's/EST5EDT/${TIMEZONE}/' -i chapter06/$this_script
914 # PATCH.. Cannot use interactive programs/scripts.
915 sed 's/make menuconfig/make oldconfig/' -i chapter06/$this_script
916 sed 's@^cd gettext-runtime@cd ../gettext-*/gettext-runtime@' -i chapter06/$this_script
917 ;;
918 gcc) # PATCH..
919 sed 's/rm /rm -f /' -i chapter06/$this_script
920 ;;
921 esac
922
923 #--------------------------------------------------------------------#
924 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
925 #--------------------------------------------------------------------#
926 #
927 # Drop in the name of the target on a new line, and the previous target
928 # as a dependency. Also call the echo_message function.
929 echo -e "\n$this_script: $PREV
930 @\$(call echo_message, Building)" >> $MKFILE.tmp
931
932 # Find the version of the command files, if it corresponds with the building of
933 # a specific package
934 vrs=`grep "^$name-version" $JHAHLFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
935
936 # If $vrs isn't empty, we've got a package...
937 # Insert instructions for unpacking the package and changing directories
938 if [ "$vrs" != "" ] ; then
939 # Deal with non-standard names
940 case $name in
941 tcl) FILE="$name$vrs-src.tar.*" ;;
942 uclibc) FILE="uClibc-$vrs.tar.*" ;;
943 gcc) FILE="gcc-core-$vrs.tar.*" ;;
944 *) FILE="$name-$vrs.tar.*" ;;
945 esac
946(
947cat << EOF
948 @\$(call unpack2,$FILE)
949 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
950 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
951 echo "export target=$(uname -m)-${TARGET}" >> envars && \\
952 echo "export ldso=/lib/${LOADER}" >> envars
953EOF
954) >> $MKFILE.tmp
955 fi
956
957 case $this_script in
958 *readjusting*) # For the Re-Adjusting phase we must to cd to the binutils-build directory.
959 echo -e '\t@echo "export PKGDIR=$(SRC)/binutils-build" > envars' >> $MKFILE.tmp
960 ;;
961 *glibc* | *uclibc* ) # For glibc and uClibc we need to set TIMEZONE envar.
962 echo -e '\t@echo "export TIMEZONE=$(TIMEZONE)" >> envars' >> $MKFILE.tmp
963 ;;
964 *groff* ) # For Groff we need to set PAGE envar.
965 echo -e '\t@echo "export PAGE=$(PAGE)" >> envars' >> $MKFILE.tmp
966 ;;
967 esac
968
969
970 # In the mount of kernel filesystems we need to set HLFS and not to use chroot.
971 if [[ `_IS_ $this_script kernfs` ]] ; then
972(
973cat << EOF
974 @echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(HLFS)\`\n" >logs/$this_script && \\
975 export HLFS=\$(HLFS) && commands/$file >>logs/$this_script 2>&1 && \\
976 echo -e "\n\`date\`\n\nKB: \`du -sk --exclude={0,1}??-* \$(HLFS)\`\n" >>logs/$this_script
977EOF
978) >> $MKFILE.tmp
979
980 # The rest of Chapter06
981 else
982(
983cat << EOF
984 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(HLFS)\`\n" >logs/$this_script && \\
985 \$(CHROOT1) 'cd /jhahlfs && source envars && /jhahlfs/commands/$file >>/jhahlfs/logs/$this_script 2>&1' && \\
986 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(HLFS)\`\n" >>logs/$this_script
987EOF
988) >> $MKFILE.tmp
989 fi
990
991 # Remove the build directory(ies) except if the package build fails.
992 if [ "$vrs" != "" ] ; then
993(
994cat << EOF
995 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
996 rm -r \$(HLFS)\$(SRC)/\$\$ROOT && \\
997 if [ -e \$(HLFS)\$(SRC)/$name-build ]; then \\
998 rm -r \$(HLFS)\$(SRC)/$name-build; \\
999 fi;
1000EOF
1001) >> $MKFILE.tmp
1002 fi
1003
1004 # Remove the Binutils pass 2 sources after a successful Re-Adjusting phase.
1005 if [[ `_IS_ $this_script readjusting` ]] ; then
1006(
1007cat << EOF
1008 @rm -r \`cat sources-dir\` && \\
1009 rm -r \$(HLFS)\$(SRC)/binutils-build && \\
1010 rm sources-dir
1011EOF
1012) >> $MKFILE.tmp
1013 fi
1014
1015 # Include a touch of the target name so make can check if it's already been made.
1016 echo -e '\t@touch $@' >> $MKFILE.tmp
1017 #
1018 #--------------------------------------------------------------------#
1019 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
1020 #--------------------------------------------------------------------#
1021
1022 # Keep the script file name for Makefile dependencies.
1023 PREV=$this_script
1024 done # end for file in chapter06/*
1025
1026}
1027
1028#----------------------------#
1029chapter7_Makefiles() { # Create a bootable system.. kernel, bootscripts..etc
1030#----------------------------#
1031
1032 echo "${YELLOW} Processing Chapter-7 scripts ${OFF}"
1033 for file in chapter07/*; do
1034 # Keep the script file name
1035 this_script=`basename $file`
1036
1037 # Grub must be configured manually.
1038 # The filesystems can't be unmounted via Makefile and the user
1039 # should enter the chroot environment to create the root
1040 # password, edit several files and setup Grub.
1041 case $this_script in
1042 *grub) continue ;;
1043 *reboot) continue ;;
1044 *console) continue ;; # Use the file generated by lfs-bootscripts
1045
1046 *kernel) # How does Manuel add this string to the file..
1047 sed 's|cd \$PKGDIR.*||' -i chapter07/$this_script
1048 # You cannot run menuconfig from within the makefile
1049 sed 's|make menuconfig|make oldconfig|' -i chapter07/$this_script
1050 # The files in the conglomeration dir are xxx.bz2
1051 sed 's|.patch.gz|.patch.bz2|' -i chapter07/$this_script
1052 sed 's|gunzip|bunzip2|' -i chapter07/$this_script
1053 # If defined include the keymap in the kernel
1054 if [[ -n "$KEYMAP" ]]; then
1055 sed "s|^loadkeys -m.*>|loadkeys -m $KEYMAP >|" -i chapter07/$this_script
1056 else
1057 sed '/loadkeys -m/d' -i chapter07/$this_script
1058 sed '/drivers\/char/d' -i chapter07/$this_script
1059 fi
1060 # If no .config file is supplied, the kernel build is skipped
1061 [[ -z $CONFIG ]] && continue
1062 ;;
1063 *usage) # The script bombs, disable error trapping
1064 sed 's|set -e|set +e|' -i chapter07/$this_script
1065 ;;
1066 *profile) # Add the config values to the script
1067 sed "s|LC_ALL=\*\*EDITME.*EDITME\*\*|LC_ALL=$LC_ALL|" -i chapter07/$this_script
1068 sed "s|LANG=\*\*EDITME.*EDITME\*\*|LANG=$LANG|" -i chapter07/$this_script
1069 ;;
1070 esac
1071
1072 # First append then name of the script file to a list (this will become
1073 # the names of the targets in the Makefile
1074 chapter7="$chapter7 $this_script"
1075
1076 #--------------------------------------------------------------------#
1077 # >>>>>>>> START BUILDING A Makefile ENTRY <<<<<<<< #
1078 #--------------------------------------------------------------------#
1079 #
1080 # Drop in the name of the target on a new line, and the previous target
1081 # as a dependency. Also call the echo_message function.
1082 echo -e "\n$this_script: $PREV
1083 @\$(call echo_message, Building)" >> $MKFILE.tmp
1084
1085 if [[ `_IS_ $this_script bootscripts` ]] ; then
1086 vrs=`grep "^lfs-bootscripts-version" $JHAHLFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
1087 FILE="lfs-bootscripts-$vrs.tar.*"
1088 # The bootscript pkg references both lfs AND blfs bootscripts...
1089 # see XML script for other additions to bootscripts file
1090 # PATCH
1091 vrs=`grep "^blfs-bootscripts-version" $JHAHLFSDIR/packages | sed -e 's/.* //' -e 's/"//g'`
1092 sed "s|make install$|make install; cd ../blfs-bootscripts-$vrs|" -i chapter07/$this_script
1093(
1094cat << EOF
1095 @\$(call unpack2,$FILE)
1096 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
1097 echo "export PKGDIR=\$(SRC)/\$\$ROOT" > envars && \\
1098 echo "\$(HLFS)\$(SRC)/blfs-bootscripts-$vrs" > sources-dir
1099EOF
1100) >> $MKFILE.tmp
1101 fi
1102
1103 if [[ `_IS_ $this_script kernel` ]] ; then
1104 # not much really, script does everything..
1105 echo -e "\t@cp -f $CONFIG \$(HLFS)/sources/kernel-config" >> $MKFILE.tmp
1106 fi
1107
1108 # Check if we have a real /etc/fstab file
1109 if [[ `_IS_ $this_script fstab` ]] && [[ -n "$FSTAB" ]] ; then
1110(
1111cat << EOF
1112 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(HLFS)\`\n" >logs/$this_script && \\
1113 cp -v $FSTAB \$(HLFS)/etc/fstab >>logs/$this_script 2>&1 && \\
1114 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(HLFS)\`\n" >>logs/$this_script
1115EOF
1116) >> $MKFILE.tmp
1117 else
1118 # Initialize the log and run the script
1119(
1120cat << EOF
1121 @echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(HLFS)\`\n" >logs/$this_script && \\
1122 \$(CHROOT2) 'cd /jhahlfs && source envars && /jhahlfs/commands/$file >>/jhahlfs/logs/$this_script 2>&1' && \\
1123 echo -e "\n\`date\`\n\nKB: \`du -skx --exclude={0,1}??-* \$(HLFS)\`\n" >>logs/$this_script
1124EOF
1125) >> $MKFILE.tmp
1126 fi
1127
1128 # Remove the build directory except if the package build fails.
1129 if [[ `_IS_ $this_script bootscripts` ]]; then
1130(
1131cat << EOF
1132 @ROOT=\`head -n1 /tmp/unpacked | sed 's@^./@@;s@/.*@@'\` && \\
1133 rm -r \$(HLFS)\$(SRC)/\$\$ROOT
1134 @rm -r \`cat sources-dir\` && \\
1135 rm sources-dir
1136
1137EOF
1138) >> $MKFILE.tmp
1139 fi
1140
1141 # Include a touch of the target name so make can check if it's already been made.
1142 echo -e '\t@touch $@' >> $MKFILE.tmp
1143 #
1144 #--------------------------------------------------------------------#
1145 # >>>>>>>> END OF Makefile ENTRY <<<<<<<< #
1146 #--------------------------------------------------------------------#
1147
1148 # Keep the script file name for Makefile dependencies.
1149 PREV=$this_script
1150 done # for file in chapter07/*
1151}
1152
1153
1154#----------------------------#
1155build_Makefile() { # Construct a Makefile from the book scripts
1156#----------------------------#
1157 echo -e "${GREEN}Creating Makefile... ${OFF}"
1158
1159 cd $JHAHLFSDIR/commands
1160 # Start with a clean Makefile.tmp file
1161 >$MKFILE.tmp
1162
1163 chapter4_Makefiles
1164 chapter5_Makefiles
1165 chapter6_Makefiles
1166 chapter7_Makefiles
1167
1168 # Add a header, some variables and include the function file
1169 # to the top of the real Makefile.
1170(
1171 cat << EOF
1172$HEADER
1173
1174SRC= /sources
1175HLFS= $BUILDDIR
1176PAGE= $PAGE
1177TIMEZONE= $TIMEZONE
1178
1179include hlfs-functions
1180
1181EOF
1182) > $MKFILE
1183
1184
1185 # Add chroot commands
1186 i=1
1187 for file in chapter06/*chroot* ; do
1188 chroot=`cat $file | sed -e '/#!\/bin\/sh/d' \
1189 -e '/^export/d' \
1190 -e '/^logout/d' \
1191 -e 's@ \\\@ @g' | tr -d '\n' | sed -e 's/ */ /g' \
1192 -e 's|\\$|&&|g' \
1193 -e 's|exit||g' \
1194 -e 's|$| -c|' \
1195 -e 's|"$$HLFS"|$(HLFS)|'\
1196 -e 's|set -e||'`
1197 echo -e "CHROOT$i= $chroot\n" >> $MKFILE
1198 i=`expr $i + 1`
1199 done
1200
1201 # Drop in the main target 'all:' and the chapter targets with each sub-target
1202 # as a dependency.
1203(
1204 cat << EOF
1205all: chapter4 chapter5 chapter6 chapter7
1206 @\$(call echo_finished,$VERSION)
1207
1208chapter4: 020-creatingtoolsdir 021-addinguser 022-settingenvironment
1209
1210chapter5: chapter4 $chapter5 restore-hlfs-env
1211
1212chapter6: chapter5 $chapter6
1213
1214chapter7: chapter6 $chapter7
1215
1216clean-all: clean
1217 rm -rf ./{commands,logs,Makefile,dump-hlfs-scripts.xsl,functions,packages,patches}
1218
1219clean: clean-chapter7 clean-chapter6 clean-chapter5 clean-chapter4
1220
1221clean-chapter4:
1222 -if [ ! -f user-hlfs-exist ]; then \\
1223 userdel hlfs; \\
1224 rm -rf /home/hlfs; \\
1225 fi;
1226 rm -rf \$(HLFS)/tools
1227 rm -f /tools
1228 rm -f envars user-hlfs-exist
1229 rm -f 02* logs/02*.log
1230
1231clean-chapter5:
1232 rm -rf \$(HLFS)/tools/*
1233 rm -f $chapter5 restore-hlfs-env sources-dir
1234 cd logs && rm -f $chapter5 && cd ..
1235
1236clean-chapter6:
1237 -umount \$(HLFS)/sys
1238 -umount \$(HLFS)/proc
1239 -umount \$(HLFS)/dev/shm
1240 -umount \$(HLFS)/dev/pts
1241 -umount \$(HLFS)/dev
1242 rm -rf \$(HLFS)/{bin,boot,dev,etc,home,lib,media,mnt,opt,proc,root,sbin,srv,sys,tmp,usr,var}
1243 rm -f $chapter6
1244 cd logs && rm -f $chapter6 && cd ..
1245
1246clean-chapter7:
1247 rm -f $chapter7
1248 cd logs && rm -f $chapter7 && cd ..
1249
1250restore-hlfs-env:
1251 @\$(call echo_message, Building)
1252 @if [ -f /home/hlfs/.bashrc.XXX ]; then \\
1253 mv -fv /home/hlfs/.bashrc.XXX /home/hlfs/.bashrc; \\
1254 fi;
1255 @if [ -f /home/hlfs/.bash_profile.XXX ]; then \\
1256 mv -v /home/hlfs/.bash_profile.XXX /home/hlfs/.bash_profile; \\
1257 fi;
1258 @chown hlfs:hlfs /home/hlfs/.bash* && \\
1259 touch \$@
1260
1261EOF
1262) >> $MKFILE
1263
1264 # Bring over the items from the Makefile.tmp
1265 cat $MKFILE.tmp >> $MKFILE
1266 rm $MKFILE.tmp
1267 echo -ne "${GREEN}done\n${OFF}"
1268}
1269
1270#----------------------------#
1271run_make() { # Execute the newly constructed Makefile
1272#----------------------------#
1273 # Test if make must be run.
1274 if [ "$RUNMAKE" = "1" ] ; then
1275 # Test to make sure we're running the build as root
1276 if [ "$UID" != "0" ] ; then
1277 echo "You must be logged in as root to successfully build HLFS."
1278 exit 1
1279 fi
1280 # Build the system
1281 if [ -e $MKFILE ] ; then
1282 echo -ne "Building the HLFS system...\n"
1283 cd $JHAHLFSDIR && make
1284 echo -ne "done\n"
1285 fi
1286 fi
1287}
1288
1289
1290
1291###################################
1292### MAIN ###
1293###################################
1294
1295# Evaluate any command line switches
1296
1297while test $# -gt 0 ; do
1298 case $1 in
1299 --version | -V ) 'clear'; echo "$version" ; exit 0; ;;
1300 --help | -h ) usage | less
1301 'clear' ; exit 0
1302 ;;
1303
1304 --HLFS-version | -L )
1305 test $# = 1 && eval "$exit_missing_arg"
1306 shift
1307 case $1 in
1308 dev* | SVN | trunk )
1309 BOOK="" # necessary to overide any value set inside jhahlfs.conf
1310 WC=
1311 HLFSVRS=development
1312 ;;
1313 * )
1314 echo "$1 is an unsupported version at this time."
1315 exit 1
1316 ;;
1317 esac
1318 ;;
1319
1320 --directory | -d )
1321 test $# = 1 && eval "$exit_missing_arg"
1322 shift
1323 BUILDDIR=$1
1324 JHAHLFSDIR=$BUILDDIR/jhahlfs
1325 LOGDIR=$JHAHLFSDIR/logs
1326 MKFILE=$JHAHLFSDIR/Makefile
1327 ;;
1328
1329 --working-copy | -W )
1330 test $# = 1 && eval "$exit_missing_arg"
1331 shift
1332 if [ -f $1/patches.ent ] ; then
1333 WC=1
1334 BOOK=$1
1335 else
1336 echo -e "\nLook like $1 isn't a supported working copy."
1337 echo -e "Verify your selection and the command line.\n"
1338 exit 1
1339 fi
1340 ;;
1341
1342 --get-packages | -P ) HPKG=1 ;;
1343 --run-make | -M ) RUNMAKE=1 ;;
1344 --rebuild ) CLEAN=1 ;;
1345
1346 --readme )
1347 'clear'
1348 echo "$_inline_doc" | less
1349 'clear'; exit
1350 ;;
1351
1352 --fstab )
1353 test $# = 1 && eval "$exit_missing_arg"
1354 shift
1355 if [ -f $1 ] ; then
1356 FSTAB=$1
1357 else
1358 echo -e "\nFile $1 not found. Verify your command line.\n"
1359 exit 1
1360 fi
1361 ;;
1362
1363 --kernel-config | -C )
1364 test $# = 1 && eval "$exit_missing_arg"
1365 shift
1366 if [ -f $1 ] ; then
1367 CONFIG=$1
1368 else
1369 echo -e "\nFile $1 not found. Verify your command line.\n"
1370 exit 1
1371 fi
1372 ;;
1373 * )
1374 echo "$usage"
1375 exit 1
1376 ;;
1377 esac
1378 shift
1379done
1380
1381# Prevents setting "-d /" by mistake.
1382if [ $BUILDDIR = / ] ; then
1383 echo -ne "\nThe root directory can't be used to build HLFS.\n\n"
1384 exit 1
1385fi
1386
1387# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
1388# and notify the user about that.
1389if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
1390 no_empty_builddir
1391fi
1392
1393# If requested, clean the build directory
1394clean_builddir
1395
1396# Find the download client to use, if not already specified.
1397if [ -z $DL ] ; then
1398 if [ `type -p wget` ] ; then
1399 DL=wget
1400 elif [ `type -p curl` ] ; then
1401 DL=curl
1402 else
1403 eval "$no_dl_client"
1404 fi
1405fi
1406
1407# Set the document location..
1408# if set by conf file leave it alone otherwise load the specified version
1409BOOK=${BOOK:=hlfs-$HLFSVRS}
1410
1411[[ ! -d $JHAHLFSDIR ]] && mkdir -pv $JHAHLFSDIR
1412[[ ! -d $LOGDIR ]] && mkdir -v $LOGDIR
1413if [[ "$PWD" != "$JHAHLFSDIR" ]]; then
1414 cp -v $FILES $JHAHLFSDIR/
1415 sed 's,FAKEDIR,'$BOOK',' $XSL > $JHAHLFSDIR/dump-hlfs-scripts.xsl
1416 export XSL=$JHAHLFSDIR/dump-hlfs-scripts.xsl
1417fi
1418
1419>$LOGDIR/$LOG
1420
1421
1422# Check for minumum gcc and kernel versions
1423check_requirements 1 # 0/1 0-do not display values.
1424validate_config 1 # 0/1 0-do not display values
1425get_book
1426build_Makefile
1427run_make
Note: See TracBrowser for help on using the repository browser.