source: master.sh@ 794295d

experimental
Last change on this file since 794295d was 398a037, checked in by George Boudreau <georgeb@…>, 18 years ago

Mods to most files to allow for reduction of internal functions and reduction in the size of the generated makefile

  • Property mode set to 100755
File size: 14.3 KB
RevLine 
[0170229]1#!/bin/bash
[12a5707]2# $Id$
[0170229]3set -e
4
5
6#>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
7#-----------------------#
8simple_error() { # Basic error trap.... JUST DIE
9#-----------------------#
10 # If +e then disable text output
11 if [[ "$-" =~ "e" ]]; then
12 echo -e "\n${RED}ERROR:${GREEN} basic error trapped!${OFF}\n" >&2
13 fi
14}
15
16see_ya() {
[f7590ba]17 echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}jhalfs-X${R_arrow}\n"
[0170229]18}
19##### Simple error TRAPS
20# ctrl-c SIGINT
21# ctrl-y
22# ctrl-z SIGTSTP
23# SIGHUP 1 HANGUP
24# SIGINT 2 INTRERRUPT FROM KEYBOARD Ctrl-C
25# SIGQUIT 3
26# SIGKILL 9 KILL
27# SIGTERM 15 TERMINATION
28# SIGSTOP 17,18,23 STOP THE PROCESS
29#####
30set -e
31trap see_ya 0
32trap simple_error ERR
33trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
34#>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
35
36
37if [ ! -L $0 ] ; then
38 echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
39 exit 1
40fi
41
[12a5707]42 PROGNAME=$(basename $0)
43 COMMON_DIR="common"
[26a8fdf]44 PACKAGE_DIR=$(echo $PROGNAME | tr [a-z] [A-Z])
[12a5707]45 MODULE=$PACKAGE_DIR/master.sh
46MODULE_CONFIG=$PACKAGE_DIR/config
[26a8fdf]47 VERBOSITY=0
[12a5707]48
[26a8fdf]49[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
[12a5707]50source $COMMON_DIR/common-functions
51[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
[26a8fdf]52[[ $VERBOSITY > 0 ]] && echo "OK"
[12a5707]53#
[26a8fdf]54[[ $VERBOSITY > 0 ]] && echo -n "Loading masterscript conf..."
[12a5707]55source $COMMON_DIR/config
[13e816f]56[[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
[26a8fdf]57[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]58#
[26a8fdf]59[[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
[0170229]60source $MODULE_CONFIG
61[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
[26a8fdf]62[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]63#
[26a8fdf]64[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
[0170229]65source $MODULE
[12a5707]66[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
[26a8fdf]67[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]68#
[65d83a6]69[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[0170229]70
[613d46b]71if [[ -e using_menuconfig ]]; then
[398a037]72 [[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
[613d46b]73 source configuration
[398a037]74 [[ $? > 0 ]] && echo "file:configuration did not load.." && exit 1
75 [[ $VERBOSITY > 0 ]] && echo "OK"
[9485eba]76
[613d46b]77 #--- Working directories
78 SCRIPT_ROOT=jhalfs
79 JHALFSDIR=$BUILDDIR/$SCRIPT_ROOT
80 LOGDIR=$JHALFSDIR/logs
81 TESTLOGDIR=$JHALFSDIR/test-logs
82 MKFILE=$JHALFSDIR/Makefile
83 #--- ICA report log directory
84 ICALOGDIR=$LOGDIR/ICA
85 #--- farce report log directory
86 FARCELOGDIR=$LOGDIR/farce
87
[398a037]88 if [[ ! -z ${BRANCH_ID} ]]; then
89 case $BRANCH_ID in
90 dev* | SVN | trunk )
91 case $PROGNAME in
92 clfs2 ) TREE=branches/clfs-2.0/BOOK ;;
93 *) TREE=trunk/BOOK ;;
94 esac
95 LFSVRS=development
96 ;;
97 branch-* )
98 LFSVRS=${BRANCH_ID}
99 TREE=branches/${BRANCH_ID#branch-}/BOOK
100 ;;
101 * )
102 case $PROGNAME in
103 lfs | hlfs )
104 LFSVRS=${BRANCH_ID}
105 TREE=tags/${BRANCH_ID}/BOOK
106 ;;
107 clfs | clfs2 )
108 LFSVRS=${BRANCH_ID}
109 TREE=tags/${BRANCH_ID}
110 ;;
111 esac
112 ;;
[613d46b]113 esac
[398a037]114 fi
[613d46b]115fi
[0170229]116
117#===========================================================
118# If the var BOOK contains something then, maybe, it points
119# to a working doc.. set WC=1, else 'null'
120#===========================================================
121WC=${BOOK:+1}
122#===========================================================
123
124
125#*******************************************************************#
[26a8fdf]126[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
[12a5707]127source $COMMON_DIR/func_check_version.sh
128[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[26a8fdf]129[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]130
[26a8fdf]131[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
[12a5707]132source $COMMON_DIR/func_validate_configs.sh
133[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[26a8fdf]134[[ $VERBOSITY > 0 ]] && echo "OK"
[65d83a6]135[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[0170229]136
137
138###################################
[4612459]139### MAIN ###
[0170229]140###################################
141
142# Evaluate any command line switches
143
144while test $# -gt 0 ; do
145 case $1 in
[25b52e2]146 # Common options for {C,H}LFS books
[5627958]147 --book | -B )
[0170229]148 test $# = 1 && eval "$exit_missing_arg"
149 shift
150 case $1 in
151 dev* | SVN | trunk )
152 LFSVRS=development
[3b63c8c]153 TREE=trunk/BOOK
[0170229]154 ;;
[3b63c8c]155 branch-* )
156 LFSVRS=$1
157 TREE=branches/${1#branch-}/BOOK
158 ;;
159 * )
160 case $PROGNAME in
161 lfs | hlfs )
162 LFSVRS=$1
163 TREE=tags/$1/BOOK
164 ;;
165 clfs )
166 LFSVRS=$1
167 TREE=tags/$1
168 ;;
169 esac
[0170229]170 ;;
171 esac
172 ;;
173
[c16cedc]174 --directory | -D )
[0170229]175 test $# = 1 && eval "$exit_missing_arg"
176 shift
[e95c26c]177 case $1 in
178 -* )
[ea29b1f]179 echo -e "\n$1 isn't a valid build directory."
[e95c26c]180 echo -e "Directory names can't start with - .\n"
181 exit 1
182 ;;
183 * )
184 BUILDDIR=$1
[460ea63]185 JHALFSDIR=$BUILDDIR/${SCRIPT_ROOT}
[e95c26c]186 LOGDIR=$JHALFSDIR/logs
[e35e794]187 TESTLOGDIR=$JHALFSDIR/test-logs
[e95c26c]188 MKFILE=$JHALFSDIR/Makefile
189 ;;
190 esac
[0170229]191 ;;
192
[3e7af38]193 --get-packages | -G ) GETPKG=1 ;;
[c16cedc]194
[e2b5b99]195 --help | -h ) usage | more && exit ;;
[c16cedc]196
[53588e2]197 --optimize | -O )
198 test $# = 1 && eval "$exit_missing_arg"
199 shift
200 case $1 in
201 0 | 1 | 2 )
202 OPTIMIZE=$1
203 ;;
204 * )
205 echo -e "\n$1 isn't a valid optimize level value."
206 echo -e "You must use 0, 1, or 2.\n"
207 exit 1
208 ;;
209 esac
210 ;;
211
[c16cedc]212 --testsuites | -T )
213 test $# = 1 && eval "$exit_missing_arg"
214 shift
215 case $1 in
216 0 | 1 | 2 | 3 )
217 TEST=$1
218 ;;
219 * )
220 echo -e "\n$1 isn't a valid testsuites level value."
221 echo -e "You must to use 0, 1, 2, or 3.\n"
222 exit 1
223 ;;
224 esac
225 ;;
226
227 --version | -V )
228 echo "$version"
229 exit 0
230 ;;
231
[0170229]232 --working-copy | -W )
233 test $# = 1 && eval "$exit_missing_arg"
234 shift
[5627958]235 case $PROGNAME in # Poor checks. We should find better ones.
236 lfs)
[f8615e5]237 if [ -d $1/chapter09 ] ; then
[5627958]238 WC=1
239 BOOK=$1
240 else
[3b63c8c]241 echo -e "\nLooks like $1 isn't an LFS working copy."
[5627958]242 exit 1
243 fi
244 ;;
245 clfs)
[f8615e5]246 if [ -d $1/cross-tools ] ; then
[5627958]247 WC=1
248 BOOK=$1
249 else
[da626a9]250 echo -e "\nLooks like $1 isn't a CLFS working copy."
[5627958]251 exit 1
252 fi
253 ;;
254 hlfs)
255 if [ -f $1/template.xml ] ; then
256 WC=1
257 BOOK=$1
258 else
[3b63c8c]259 echo -e "\nLooks like $1 isn't an HLFS working copy."
[5627958]260 exit 1
261 fi
262 ;;
[4532c37]263 esac
264 ;;
[0170229]265
[3b63c8c]266 --comparison | -C )
[4612459]267 test $# = 1 && eval "$exit_missing_arg"
268 shift
[02d1ae7]269 case $1 in
[4612459]270 ICA) RUN_ICA=1
271 RUN_FARCE=0
[fb68d23]272 COMPARE=1
[4612459]273 ;;
274 farce) RUN_ICA=0
275 RUN_FARCE=1
[fb68d23]276 COMPARE=1
[4612459]277 ;;
278 both) RUN_ICA=1
279 RUN_FARCE=1
[fb68d23]280 COMPARE=1
[97520c9]281 ;;
[4612459]282 *)
[c58f330]283 echo -e "\n$1 is an unknown analysis method."
[4612459]284 exit 1
285 ;;
286 esac
287 ;;
[42346b2]288
[40ccddf]289 --fstab | -F )
290 test $# = 1 && eval "$exit_missing_arg"
291 shift
292 if [ -f $1 ] ; then
293 FSTAB=$1
294 else
295 echo -e "\nFile $1 not found. Verify your command line.\n"
296 exit 1
297 fi
298 ;;
299
300 --kernel-config | -K )
301 test $# = 1 && eval "$exit_missing_arg"
302 shift
303 if [ -f $1 ] ; then
304 CONFIG=$1
305 else
306 echo -e "\nFile $1 not found. Verify your command line.\n"
307 exit 1
308 fi
309 ;;
310
[3b63c8c]311 --run-make | -M ) RUNMAKE=1 ;;
[40ccddf]312
313 --rebuild | -R ) CLEAN=1 ;;
314
[bd99331]315 # CLFS options
316 --arch | -A )
317 test $# = 1 && eval "$exit_missing_arg"
318 shift
319 case $1 in
[3b63c8c]320 arm )
321 ARCH=arm
322 TARGET="arm-unknown-linux-gnu"
323 ;;
[bd99331]324 x86 )
325 ARCH=x86
326 TARGET="i686-pc-linux-gnu"
327 ;;
328 i486 )
329 ARCH=x86
330 TARGET="i486-pc-linux-gnu"
331 ;;
332 i586 )
333 ARCH=x86
334 TARGET="i586-pc-linux-gnu"
335 ;;
336 ppc )
337 ARCH=ppc
338 TARGET="powerpc-unknown-linux-gnu"
339 ;;
340 mips )
341 ARCH=mips
342 TARGET="mips-unknown-linux-gnu"
343 ;;
344 mipsel )
345 ARCH=mips
346 TARGET="mipsel-unknown-linux-gnu"
347 ;;
348 sparc )
349 ARCH=sparc
350 TARGET="sparcv9-unknown-linux-gnu"
351 ;;
352 x86_64-64 )
353 ARCH=x86_64-64
354 TARGET="x86_64-unknown-linux-gnu"
355 ;;
356 mips64-64 )
357 ARCH=mips64-64
358 TARGET="mips-unknown-linux-gnu"
359 ;;
360 mipsel64-64 )
361 ARCH=mips64-64
362 TARGET="mipsel-unknown-linux-gnu"
363 ;;
364 sparc64-64 )
365 ARCH=sparc64-64
366 TARGET="sparc64-unknown-linux-gnu"
367 ;;
368 alpha )
369 ARCH=alpha
370 TARGET="alpha-unknown-linux-gnu"
371 ;;
372 x86_64 )
373 ARCH=x86_64
374 TARGET="x86_64-unknown-linux-gnu"
375 TARGET32="i686-pc-linux-gnu"
376 ;;
377 mips64 )
378 ARCH=mips64
379 TARGET="mips-unknown-linux-gnu"
380 TARGET32="mips-unknown-linux-gnu"
381 ;;
382 mipsel64 )
383 ARCH=mips64
384 TARGET="mipsel-unknown-linux-gnu"
385 TARGET32="mipsel-unknown-linux-gnu"
386 ;;
387 sparc64 )
388 ARCH=sparc64
389 TARGET="sparc64-unknown-linux-gnu"
390 TARGET32="sparcv9-unknown-linux-gnu"
391 ;;
392 ppc64 )
393 ARCH=ppc64
394 TARGET="powerpc64-unknown-linux-gnu"
395 TARGET32="powerpc-unknown-linux-gnu"
396 ;;
397 * )
[3b63c8c]398 echo -e "\n$1 is an unknown or unsupported arch."
[bd99331]399 exit 1
400 ;;
401 esac
402 ;;
403
[5ff30ff]404 --boot-config )
405 test $# = 1 && eval "$exit_missing_arg"
406 shift
407 if [ -f $1 ] ; then
408 BOOT_CONFIG=$1
409 else
410 echo -e "\nFile $1 not found. Verify your command line.\n"
411 exit 1
412 fi
413 ;;
414
[bd99331]415 --method )
416 test $# = 1 && eval "$exit_missing_arg"
417 shift
418 case $1 in
419 chroot | boot )
420 METHOD=$1
421 ;;
422 * )
423 echo -e "\n$1 isn't a valid build method."
424 exit 1
425 ;;
426 esac
427 ;;
428
[890acc6]429 # HLFS options
430 --model )
431 test $# = 1 && eval "$exit_missing_arg"
432 shift
433 case $1 in
434 glibc | uclibc )
435 MODEL=$1
436 ;;
437 * )
438 echo -e "\n$1 isn't a valid libc model."
439 exit 1
440 ;;
441 esac
442 ;;
443
[bd99331]444 # Unknown options
[e794f06]445 * ) usage ;;
[0170229]446 esac
447 shift
448done
449
450#===================================================
451# Set the document location...
[13e816f]452# BOOK is either defined in
[0170229]453# xxx.config
454# comand line
[13e816f]455# default
[d95b8f2]456# If set by conf file or cmd line leave it
[0170229]457# alone otherwise load the default version
458#===================================================
459BOOK=${BOOK:=$PROGNAME-$LFSVRS}
460#===================================================
461
[13e816f]462
[3b63c8c]463# Check for minimum gcc and kernel versions
[13e816f]464#check_requirements 1 # 0/1 0-do not display values.
[f15fe85]465echo
[13e816f]466check_version "2.6.2" "`uname -r`" "KERNEL"
467check_version "3.0" "$BASH_VERSION" "BASH"
468check_version "3.0" "`gcc -dumpversion`" "GCC"
[e35e794]469tarVer=`tar --version | head -n1 | cut -d " " -f4`
470check_version "1.15.0" "${tarVer}" "TAR"
[65d83a6]471echo "${SD_BORDER}${nl_}"
[13e816f]472
[3051f95]473validate_config
[65d83a6]474echo "${SD_BORDER}${nl_}"
[7e6ddf0]475echo -n "Are you happy with these settings? yes/no (no): "
[13e816f]476read ANSWER
477if [ x$ANSWER != "xyes" ] ; then
478 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
479 exit 1
480fi
[65d83a6]481echo "${nl_}${SD_BORDER}${nl_}"
[13e816f]482
[3a27393]483# Load additional modules or configuration files based on global settings
[bb8e6bc]484# compare module
485if [[ "$COMPARE" = "1" ]]; then
486 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
487 source $COMMON_DIR/func_compare.sh
488 [[ $? > 0 ]] && echo "$COMMON_DIR/func_compare.sh did not load.." && exit
489 [[ $VERBOSITY > 0 ]] && echo "OK"
490fi
491#
[2c2471d]492# optimize module
493if [[ "$OPTIMIZE" != "0" ]]; then
494 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
495 source optimize/optimize_functions
496 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
497 [[ $VERBOSITY > 0 ]] && echo "OK"
[3a27393]498 #
499 # optimize configurations
[bb8e6bc]500 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
501 source optimize/opt_config
502 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
503 [[ $VERBOSITY > 0 ]] && echo "OK"
[3a27393]504 # Validate optimize settings, if required
505 validate_opt_settings
[bb8e6bc]506fi
507#
508
[13e816f]509# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
510# and notify the user about that.
511if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
512 eval "$no_empty_builddir"
513fi
514
515# If requested, clean the build directory
516clean_builddir
517
[0170229]518if [[ ! -d $JHALFSDIR ]]; then
[a110145]519 mkdir -p $JHALFSDIR
[0170229]520fi
[3a27393]521#
522# Create $BUILDDIR/sources even though it could be created by get_sources()
523if [[ ! -d $BUILDDIR/sources ]]; then
524 mkdir -p $BUILDDIR/sources
525fi
526#
527# Create the log directory
528if [[ ! -d $LOGDIR ]]; then
529 mkdir $LOGDIR
530fi
531>$LOGDIR/$LOG
532#
[e35e794]533[[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
[3a27393]534#
[13e816f]535if [[ "$PWD" != "$JHALFSDIR" ]]; then
[460ea63]536 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
[e35e794]537 #
[d0e48ec]538 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
[e35e794]539 #
[fb68d23]540 if [[ "$COMPARE" != "0" ]] ; then
[cc020f4]541 mkdir -p $JHALFSDIR/extras
[4612459]542 cp extras/* $JHALFSDIR/extras
[ed0a142]543 fi
[3a27393]544 #
[0170229]545 if [[ -n "$FILES" ]]; then
[3b63c8c]546 # pushd/popd necessary to deal with multiple files
[a110145]547 pushd $PACKAGE_DIR 1> /dev/null
548 cp $FILES $JHALFSDIR/
549 popd 1> /dev/null
[0170229]550 fi
[3a27393]551 #
[25b52e2]552 if [[ "$REPORT" = "1" ]]; then
553 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
[3b63c8c]554 # After being sure that all looks sane, dump the settings to a file
[25b52e2]555 # This file will be used to create the REPORT header
556 validate_config > $JHALFSDIR/jhalfs.config
[708a612]557 fi
[3a27393]558 #
[25b52e2]559 [[ "$GETPKG" = "1" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
560 #
[3b63c8c]561 cp $COMMON_DIR/packages.xsl $JHALFSDIR/
562 #
[12a5707]563 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
[0170229]564 export XSL=$JHALFSDIR/${XSL}
565fi
566
567get_book
[65d83a6]568echo "${SD_BORDER}${nl_}"
[12a5707]569
[0170229]570build_Makefile
[65d83a6]571echo "${SD_BORDER}${nl_}"
[12a5707]572
[386bc75]573run_make
Note: See TracBrowser for help on using the repository browser.