source: master.sh@ f2382aa

experimental
Last change on this file since f2382aa was 613d46b, checked in by George Boudreau <georgeb@…>, 18 years ago

Added new configuration tool.. <make> menuconfig. Needs work, especially inline help text

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