source: master.sh@ 0e97a6a

experimental
Last change on this file since 0e97a6a was 9485eba, checked in by George Boudreau <georgeb@…>, 18 years ago

Implement suggestion made byDan Nicholson for configurable user/group. Required many changes and allowed for the removal of user specific function calls. Tnx Dan

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