source: master.sh@ 3b63c8c

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

Updated experimental branch to current trunk code.

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