source: master.sh@ 9485eba

experimental
Last change on this file since 9485eba 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
Line 
1#!/bin/bash
2# $Id$
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() {
17 echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}jhalfs-X${R_arrow}\n"
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
42 PROGNAME=$(basename $0)
43 COMMON_DIR="common"
44 PACKAGE_DIR=$(echo $PROGNAME | tr [a-z] [A-Z])
45 MODULE=$PACKAGE_DIR/master.sh
46MODULE_CONFIG=$PACKAGE_DIR/config
47 VERBOSITY=0
48
49[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
50source $COMMON_DIR/common-functions
51[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
52[[ $VERBOSITY > 0 ]] && echo "OK"
53#
54[[ $VERBOSITY > 0 ]] && echo -n "Loading masterscript conf..."
55source $COMMON_DIR/config
56[[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
57[[ $VERBOSITY > 0 ]] && echo "OK"
58#
59[[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
60source $MODULE_CONFIG
61[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
62[[ $VERBOSITY > 0 ]] && echo "OK"
63#
64[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
65source $MODULE
66[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
67[[ $VERBOSITY > 0 ]] && echo "OK"
68#
69[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
70
71if [[ -e using_menuconfig ]]; then
72 source configuration
73
74
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
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#*******************************************************************#
123[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
124source $COMMON_DIR/func_check_version.sh
125[[ $? > 0 ]] && echo " function module did not load.." && exit 2
126[[ $VERBOSITY > 0 ]] && echo "OK"
127
128[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
129source $COMMON_DIR/func_validate_configs.sh
130[[ $? > 0 ]] && echo " function module did not load.." && exit 2
131[[ $VERBOSITY > 0 ]] && echo "OK"
132[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
133
134
135###################################
136### MAIN ###
137###################################
138
139# Evaluate any command line switches
140
141while test $# -gt 0 ; do
142 case $1 in
143 # Common options for {C,H}LFS books
144 --book | -B )
145 test $# = 1 && eval "$exit_missing_arg"
146 shift
147 case $1 in
148 dev* | SVN | trunk )
149 LFSVRS=development
150 TREE=trunk/BOOK
151 ;;
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
167 ;;
168 esac
169 ;;
170
171 --directory | -D )
172 test $# = 1 && eval "$exit_missing_arg"
173 shift
174 case $1 in
175 -* )
176 echo -e "\n$1 isn't a valid build directory."
177 echo -e "Directory names can't start with - .\n"
178 exit 1
179 ;;
180 * )
181 BUILDDIR=$1
182 JHALFSDIR=$BUILDDIR/${SCRIPT_ROOT}
183 LOGDIR=$JHALFSDIR/logs
184 TESTLOGDIR=$JHALFSDIR/test-logs
185 MKFILE=$JHALFSDIR/Makefile
186 ;;
187 esac
188 ;;
189
190 --get-packages | -G ) GETPKG=1 ;;
191
192 --help | -h ) usage | more && exit ;;
193
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
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
229 --working-copy | -W )
230 test $# = 1 && eval "$exit_missing_arg"
231 shift
232 case $PROGNAME in # Poor checks. We should find better ones.
233 lfs)
234 if [ -d $1/chapter09 ] ; then
235 WC=1
236 BOOK=$1
237 else
238 echo -e "\nLooks like $1 isn't an LFS working copy."
239 exit 1
240 fi
241 ;;
242 clfs)
243 if [ -d $1/cross-tools ] ; then
244 WC=1
245 BOOK=$1
246 else
247 echo -e "\nLooks like $1 isn't a CLFS working copy."
248 exit 1
249 fi
250 ;;
251 hlfs)
252 if [ -f $1/template.xml ] ; then
253 WC=1
254 BOOK=$1
255 else
256 echo -e "\nLooks like $1 isn't an HLFS working copy."
257 exit 1
258 fi
259 ;;
260 esac
261 ;;
262
263 --comparison | -C )
264 test $# = 1 && eval "$exit_missing_arg"
265 shift
266 case $1 in
267 ICA) RUN_ICA=1
268 RUN_FARCE=0
269 COMPARE=1
270 ;;
271 farce) RUN_ICA=0
272 RUN_FARCE=1
273 COMPARE=1
274 ;;
275 both) RUN_ICA=1
276 RUN_FARCE=1
277 COMPARE=1
278 ;;
279 *)
280 echo -e "\n$1 is an unknown analysis method."
281 exit 1
282 ;;
283 esac
284 ;;
285
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
308 --run-make | -M ) RUNMAKE=1 ;;
309
310 --rebuild | -R ) CLEAN=1 ;;
311
312 # CLFS options
313 --arch | -A )
314 test $# = 1 && eval "$exit_missing_arg"
315 shift
316 case $1 in
317 arm )
318 ARCH=arm
319 TARGET="arm-unknown-linux-gnu"
320 ;;
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 * )
395 echo -e "\n$1 is an unknown or unsupported arch."
396 exit 1
397 ;;
398 esac
399 ;;
400
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
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
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
441 # Unknown options
442 * ) usage ;;
443 esac
444 shift
445done
446
447#===================================================
448# Set the document location...
449# BOOK is either defined in
450# xxx.config
451# comand line
452# default
453# If set by conf file or cmd line leave it
454# alone otherwise load the default version
455#===================================================
456BOOK=${BOOK:=$PROGNAME-$LFSVRS}
457#===================================================
458
459
460# Check for minimum gcc and kernel versions
461#check_requirements 1 # 0/1 0-do not display values.
462echo
463check_version "2.6.2" "`uname -r`" "KERNEL"
464check_version "3.0" "$BASH_VERSION" "BASH"
465check_version "3.0" "`gcc -dumpversion`" "GCC"
466tarVer=`tar --version | head -n1 | cut -d " " -f4`
467check_version "1.15.0" "${tarVer}" "TAR"
468echo "${SD_BORDER}${nl_}"
469
470validate_config
471echo "${SD_BORDER}${nl_}"
472echo -n "Are you happy with these settings? yes/no (no): "
473read ANSWER
474if [ x$ANSWER != "xyes" ] ; then
475 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
476 exit 1
477fi
478echo "${nl_}${SD_BORDER}${nl_}"
479
480# Load additional modules or configuration files based on global settings
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#
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"
495 #
496 # optimize configurations
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"
501 # Validate optimize settings, if required
502 validate_opt_settings
503fi
504#
505
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
515if [[ ! -d $JHALFSDIR ]]; then
516 mkdir -p $JHALFSDIR
517fi
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#
530[[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
531#
532if [[ "$PWD" != "$JHALFSDIR" ]]; then
533 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
534 #
535 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
536 #
537 if [[ "$COMPARE" != "0" ]] ; then
538 mkdir -p $JHALFSDIR/extras
539 cp extras/* $JHALFSDIR/extras
540 fi
541 #
542 if [[ -n "$FILES" ]]; then
543 # pushd/popd necessary to deal with multiple files
544 pushd $PACKAGE_DIR 1> /dev/null
545 cp $FILES $JHALFSDIR/
546 popd 1> /dev/null
547 fi
548 #
549 if [[ "$REPORT" = "1" ]]; then
550 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
551 # After being sure that all looks sane, dump the settings to a file
552 # This file will be used to create the REPORT header
553 validate_config > $JHALFSDIR/jhalfs.config
554 fi
555 #
556 [[ "$GETPKG" = "1" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
557 #
558 cp $COMMON_DIR/packages.xsl $JHALFSDIR/
559 #
560 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
561 export XSL=$JHALFSDIR/${XSL}
562fi
563
564get_book
565echo "${SD_BORDER}${nl_}"
566
567build_Makefile
568echo "${SD_BORDER}${nl_}"
569
570run_make
Note: See TracBrowser for help on using the repository browser.