source: master.sh@ c361b24

experimental
Last change on this file since c361b24 was 3fa20d4, checked in by George Boudreau <georgeb@…>, 18 years ago

Miss a 0/1->n/y conversion

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