source: master.sh@ f8615e5

experimental
Last change on this file since f8615e5 was f8615e5, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Merged r2701 from trunk.

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