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
RevLine 
[0170229]1#!/bin/bash
[12a5707]2# $Id$
[0170229]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() {
[f7590ba]17 echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}jhalfs-X${R_arrow}\n"
[0170229]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
[12a5707]42 PROGNAME=$(basename $0)
43 COMMON_DIR="common"
[26a8fdf]44 PACKAGE_DIR=$(echo $PROGNAME | tr [a-z] [A-Z])
[12a5707]45 MODULE=$PACKAGE_DIR/master.sh
46MODULE_CONFIG=$PACKAGE_DIR/config
[26a8fdf]47 VERBOSITY=0
[12a5707]48
[26a8fdf]49[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
[12a5707]50source $COMMON_DIR/common-functions
51[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
[26a8fdf]52[[ $VERBOSITY > 0 ]] && echo "OK"
[12a5707]53#
[26a8fdf]54[[ $VERBOSITY > 0 ]] && echo -n "Loading masterscript conf..."
[12a5707]55source $COMMON_DIR/config
[13e816f]56[[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
[26a8fdf]57[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]58#
[26a8fdf]59[[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
[0170229]60source $MODULE_CONFIG
61[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
[26a8fdf]62[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]63#
[26a8fdf]64[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
[0170229]65source $MODULE
[12a5707]66[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
[26a8fdf]67[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]68#
[65d83a6]69[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[0170229]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#*******************************************************************#
[26a8fdf]81[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
[12a5707]82source $COMMON_DIR/func_check_version.sh
83[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[26a8fdf]84[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]85
[26a8fdf]86[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
[12a5707]87source $COMMON_DIR/func_validate_configs.sh
88[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[26a8fdf]89[[ $VERBOSITY > 0 ]] && echo "OK"
[65d83a6]90[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
[0170229]91
92
93###################################
[4612459]94### MAIN ###
[0170229]95###################################
96
97# Evaluate any command line switches
98
99while test $# -gt 0 ; do
100 case $1 in
[25b52e2]101 # Common options for {C,H}LFS books
[5627958]102 --book | -B )
[0170229]103 test $# = 1 && eval "$exit_missing_arg"
104 shift
105 case $1 in
106 dev* | SVN | trunk )
107 LFSVRS=development
108 ;;
[5627958]109 *) if [[ "$PROGNAME" = "lfs" ]]; then
110 case $1 in
[d95b8f2]111 6.1.1 )
112 echo "For stable 6.1.1 book, please use jhalfs-0.2."
113 exit 0
114 ;;
[18911500]115 * )
116 echo "$1 is an unsupported version at this time."
117 exit 0
118 ;;
[5627958]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."
[d95b8f2]122 exit 0
123 fi
[0170229]124 ;;
125 esac
126 ;;
127
[c16cedc]128 --directory | -D )
[0170229]129 test $# = 1 && eval "$exit_missing_arg"
130 shift
[e95c26c]131 case $1 in
132 -* )
[ea29b1f]133 echo -e "\n$1 isn't a valid build directory."
[e95c26c]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
[0170229]144 ;;
145
[3e7af38]146 --get-packages | -G ) GETPKG=1 ;;
[c16cedc]147
[e2b5b99]148 --help | -h ) usage | more && exit ;;
[c16cedc]149
[53588e2]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
[c16cedc]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
[0170229]185 --working-copy | -W )
186 test $# = 1 && eval "$exit_missing_arg"
187 shift
[5627958]188 case $PROGNAME in # Poor checks. We should find better ones.
189 lfs)
[f8615e5]190 if [ -d $1/chapter09 ] ; then
[5627958]191 WC=1
192 BOOK=$1
193 else
[da626a9]194 echo -e "\nLooks like $1 isn't a LFS working copy."
[5627958]195 exit 1
196 fi
197 ;;
198 clfs)
[f8615e5]199 if [ -d $1/cross-tools ] ; then
[5627958]200 WC=1
201 BOOK=$1
202 else
[da626a9]203 echo -e "\nLooks like $1 isn't a CLFS working copy."
[5627958]204 exit 1
205 fi
206 ;;
207 hlfs)
208 if [ -f $1/template.xml ] ; then
209 WC=1
210 BOOK=$1
211 else
[da626a9]212 echo -e "\nLooks like $1 isn't a HLFS working copy."
[5627958]213 exit 1
214 fi
215 ;;
[4532c37]216 esac
217 ;;
[0170229]218
[4612459]219 --comparasion | -C )
220 test $# = 1 && eval "$exit_missing_arg"
221 shift
[02d1ae7]222 case $1 in
[4612459]223 ICA) RUN_ICA=1
224 RUN_FARCE=0
[fb68d23]225 COMPARE=1
[4612459]226 ;;
227 farce) RUN_ICA=0
228 RUN_FARCE=1
[fb68d23]229 COMPARE=1
[4612459]230 ;;
231 both) RUN_ICA=1
232 RUN_FARCE=1
[fb68d23]233 COMPARE=1
[97520c9]234 ;;
[4612459]235 *)
[c58f330]236 echo -e "\n$1 is an unknown analysis method."
[4612459]237 exit 1
238 ;;
239 esac
240 ;;
[42346b2]241
[40ccddf]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
[bd99331]264 --make | -M ) RUNMAKE=1 ;;
[40ccddf]265
266 --rebuild | -R ) CLEAN=1 ;;
267
[bd99331]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
[5ff30ff]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
[bd99331]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
[890acc6]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
[bd99331]393 # Unknown options
[e794f06]394 * ) usage ;;
[0170229]395 esac
396 shift
397done
398
399#===================================================
400# Set the document location...
[13e816f]401# BOOK is either defined in
[0170229]402# xxx.config
403# comand line
[13e816f]404# default
[d95b8f2]405# If set by conf file or cmd line leave it
[0170229]406# alone otherwise load the default version
407#===================================================
408BOOK=${BOOK:=$PROGNAME-$LFSVRS}
409#===================================================
410
[13e816f]411
412# Check for minumum gcc and kernel versions
413#check_requirements 1 # 0/1 0-do not display values.
[f15fe85]414echo
[13e816f]415check_version "2.6.2" "`uname -r`" "KERNEL"
416check_version "3.0" "$BASH_VERSION" "BASH"
417check_version "3.0" "`gcc -dumpversion`" "GCC"
[e1edff3]418tarVer=`tar --version`
419check_version "1.15.0" "${tarVer##* }" "TAR"
[65d83a6]420echo "${SD_BORDER}${nl_}"
[13e816f]421
[3051f95]422validate_config
[65d83a6]423echo "${SD_BORDER}${nl_}"
[7e6ddf0]424echo -n "Are you happy with these settings? yes/no (no): "
[13e816f]425read ANSWER
426if [ x$ANSWER != "xyes" ] ; then
427 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
428 exit 1
429fi
[65d83a6]430echo "${nl_}${SD_BORDER}${nl_}"
[13e816f]431
[3a27393]432# Load additional modules or configuration files based on global settings
[bb8e6bc]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#
[2c2471d]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"
[3a27393]447 #
448 # optimize configurations
[bb8e6bc]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"
[3a27393]453 # Validate optimize settings, if required
454 validate_opt_settings
[bb8e6bc]455fi
456#
457
[13e816f]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
[0170229]467if [[ ! -d $JHALFSDIR ]]; then
[a110145]468 mkdir -p $JHALFSDIR
[0170229]469fi
[3a27393]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#
[13e816f]483if [[ "$PWD" != "$JHALFSDIR" ]]; then
[a110145]484 cp $COMMON_DIR/makefile-functions $JHALFSDIR/
[d0e48ec]485 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
[fb68d23]486 if [[ "$COMPARE" != "0" ]] ; then
[cc020f4]487 mkdir -p $JHALFSDIR/extras
[4612459]488 cp extras/* $JHALFSDIR/extras
[ed0a142]489 fi
[3a27393]490 #
[0170229]491 if [[ -n "$FILES" ]]; then
[9c90294]492 # pushd/popd necessary to deal with mulitiple files
[a110145]493 pushd $PACKAGE_DIR 1> /dev/null
494 cp $FILES $JHALFSDIR/
495 popd 1> /dev/null
[0170229]496 fi
[3a27393]497 #
[25b52e2]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
[708a612]503 fi
[3a27393]504 #
[25b52e2]505 [[ "$GETPKG" = "1" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
506 #
[12a5707]507 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
[0170229]508 export XSL=$JHALFSDIR/${XSL}
509fi
510
511get_book
[65d83a6]512echo "${SD_BORDER}${nl_}"
[12a5707]513
[0170229]514build_Makefile
[65d83a6]515echo "${SD_BORDER}${nl_}"
[12a5707]516
[386bc75]517run_make
Note: See TracBrowser for help on using the repository browser.