source: master.sh@ e5d0f27

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since e5d0f27 was a6655ff, checked in by Manuel Canales Esparcia <manuel@…>, 18 years ago

Avoiding hardcoded supported books versions.

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