source: master.sh@ b5aa524

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

Merged r2665 from trunk.

  • Property mode set to 100755
File size: 13.8 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
[40ccddf]101 # Common options for all 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)
190 if [ -f $1/patches.ent ] ; then
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)
199 if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
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 ;;
216 blfs)
217 if [ -f $1/use-unzip.xml ] ; then
218 WC=1
219 BOOK=$1
220 else
[da626a9]221 echo -e "\nLooks like $1 isn't a BLFS working copy."
[5627958]222 exit 1
223 fi
224 ;;
[4532c37]225 esac
226 ;;
[0170229]227
[40ccddf]228 # Common options for LFS, CLFS and HLFS
[4612459]229 --comparasion | -C )
230 test $# = 1 && eval "$exit_missing_arg"
231 shift
[02d1ae7]232 case $1 in
[4612459]233 ICA) RUN_ICA=1
234 RUN_FARCE=0
[fb68d23]235 COMPARE=1
[4612459]236 ;;
237 farce) RUN_ICA=0
238 RUN_FARCE=1
[fb68d23]239 COMPARE=1
[4612459]240 ;;
241 both) RUN_ICA=1
242 RUN_FARCE=1
[fb68d23]243 COMPARE=1
[97520c9]244 ;;
[4612459]245 *)
[c58f330]246 echo -e "\n$1 is an unknown analysis method."
[4612459]247 exit 1
248 ;;
249 esac
250 ;;
[42346b2]251
[40ccddf]252 --fstab | -F )
253 test $# = 1 && eval "$exit_missing_arg"
254 shift
255 if [ -f $1 ] ; then
256 FSTAB=$1
257 else
258 echo -e "\nFile $1 not found. Verify your command line.\n"
259 exit 1
260 fi
261 ;;
262
263 --kernel-config | -K )
264 test $# = 1 && eval "$exit_missing_arg"
265 shift
266 if [ -f $1 ] ; then
267 CONFIG=$1
268 else
269 echo -e "\nFile $1 not found. Verify your command line.\n"
270 exit 1
271 fi
272 ;;
273
[bd99331]274 --make | -M ) RUNMAKE=1 ;;
[40ccddf]275
276 --rebuild | -R ) CLEAN=1 ;;
277
[bd99331]278 # CLFS options
279 --arch | -A )
280 test $# = 1 && eval "$exit_missing_arg"
281 shift
282 case $1 in
283 x86 )
284 ARCH=x86
285 TARGET="i686-pc-linux-gnu"
286 ;;
287 i486 )
288 ARCH=x86
289 TARGET="i486-pc-linux-gnu"
290 ;;
291 i586 )
292 ARCH=x86
293 TARGET="i586-pc-linux-gnu"
294 ;;
295 ppc )
296 ARCH=ppc
297 TARGET="powerpc-unknown-linux-gnu"
298 ;;
299 mips )
300 ARCH=mips
301 TARGET="mips-unknown-linux-gnu"
302 ;;
303 mipsel )
304 ARCH=mips
305 TARGET="mipsel-unknown-linux-gnu"
306 ;;
307 sparc )
308 ARCH=sparc
309 TARGET="sparcv9-unknown-linux-gnu"
310 ;;
311 x86_64-64 )
312 ARCH=x86_64-64
313 TARGET="x86_64-unknown-linux-gnu"
314 ;;
315 mips64-64 )
316 ARCH=mips64-64
317 TARGET="mips-unknown-linux-gnu"
318 ;;
319 mipsel64-64 )
320 ARCH=mips64-64
321 TARGET="mipsel-unknown-linux-gnu"
322 ;;
323 sparc64-64 )
324 ARCH=sparc64-64
325 TARGET="sparc64-unknown-linux-gnu"
326 ;;
327 alpha )
328 ARCH=alpha
329 TARGET="alpha-unknown-linux-gnu"
330 ;;
331 x86_64 )
332 ARCH=x86_64
333 TARGET="x86_64-unknown-linux-gnu"
334 TARGET32="i686-pc-linux-gnu"
335 ;;
336 mips64 )
337 ARCH=mips64
338 TARGET="mips-unknown-linux-gnu"
339 TARGET32="mips-unknown-linux-gnu"
340 ;;
341 mipsel64 )
342 ARCH=mips64
343 TARGET="mipsel-unknown-linux-gnu"
344 TARGET32="mipsel-unknown-linux-gnu"
345 ;;
346 sparc64 )
347 ARCH=sparc64
348 TARGET="sparc64-unknown-linux-gnu"
349 TARGET32="sparcv9-unknown-linux-gnu"
350 ;;
351 ppc64 )
352 ARCH=ppc64
353 TARGET="powerpc64-unknown-linux-gnu"
354 TARGET32="powerpc-unknown-linux-gnu"
355 ;;
356 * )
357 echo -e "\n$1 is an unknown or unsopported arch."
358 exit 1
359 ;;
360 esac
361 ;;
362
[5ff30ff]363 --boot-config )
364 test $# = 1 && eval "$exit_missing_arg"
365 shift
366 if [ -f $1 ] ; then
367 BOOT_CONFIG=$1
368 else
369 echo -e "\nFile $1 not found. Verify your command line.\n"
370 exit 1
371 fi
372 ;;
373
[bd99331]374 --method )
375 test $# = 1 && eval "$exit_missing_arg"
376 shift
377 case $1 in
378 chroot | boot )
379 METHOD=$1
380 ;;
381 * )
382 echo -e "\n$1 isn't a valid build method."
383 exit 1
384 ;;
385 esac
386 ;;
387
[890acc6]388 # HLFS options
389 --model )
390 test $# = 1 && eval "$exit_missing_arg"
391 shift
392 case $1 in
393 glibc | uclibc )
394 MODEL=$1
395 ;;
396 * )
397 echo -e "\n$1 isn't a valid libc model."
398 exit 1
399 ;;
400 esac
401 ;;
402
403 # BLFS options
404 --dependencies )
405 test $# = 1 && eval "$exit_missing_arg"
406 shift
407 case $1 in
408 0 | 1 | 2 )
409 DEPEND=$1
410 ;;
411 * )
412 echo -e "\n$1 isn't a valid dependencies level."
413 exit 1
414 ;;
415 esac
416 ;;
417
[bd99331]418 # Unknown options
[e794f06]419 * ) usage ;;
[0170229]420 esac
421 shift
422done
423
424#===================================================
425# Set the document location...
[13e816f]426# BOOK is either defined in
[0170229]427# xxx.config
428# comand line
[13e816f]429# default
[d95b8f2]430# If set by conf file or cmd line leave it
[0170229]431# alone otherwise load the default version
432#===================================================
433BOOK=${BOOK:=$PROGNAME-$LFSVRS}
434#===================================================
435
[13e816f]436
437# Check for minumum gcc and kernel versions
438#check_requirements 1 # 0/1 0-do not display values.
[f15fe85]439echo
[13e816f]440check_version "2.6.2" "`uname -r`" "KERNEL"
441check_version "3.0" "$BASH_VERSION" "BASH"
442check_version "3.0" "`gcc -dumpversion`" "GCC"
[e1edff3]443tarVer=`tar --version`
444check_version "1.15.0" "${tarVer##* }" "TAR"
[65d83a6]445echo "${SD_BORDER}${nl_}"
[13e816f]446
[3051f95]447validate_config
[65d83a6]448echo "${SD_BORDER}${nl_}"
[13e816f]449
[7e6ddf0]450echo -n "Are you happy with these settings? yes/no (no): "
[13e816f]451read ANSWER
452if [ x$ANSWER != "xyes" ] ; then
453 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
454 exit 1
455fi
[65d83a6]456echo "${nl_}${SD_BORDER}${nl_}"
[13e816f]457
[bb8e6bc]458# Loadd additional modules or configuration files based on global settings
459# compare module
460if [[ "$COMPARE" = "1" ]]; then
461 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
462 source $COMMON_DIR/func_compare.sh
463 [[ $? > 0 ]] && echo "$COMMON_DIR/func_compare.sh did not load.." && exit
464 [[ $VERBOSITY > 0 ]] && echo "OK"
465fi
466#
[2c2471d]467# optimize module
468if [[ "$OPTIMIZE" != "0" ]]; then
469 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
470 source optimize/optimize_functions
471 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
472 [[ $VERBOSITY > 0 ]] && echo "OK"
473fi
474#
[bb8e6bc]475# optimize configurations
476if [[ "$OPTIMIZE" != "0" ]]; then
477 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
478 source optimize/opt_config
479 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
480 [[ $VERBOSITY > 0 ]] && echo "OK"
481fi
482#
483
[066991c]484# Validate optimize settings, if required
485[[ "$OPTIMIZE" != "0" ]] && validate_opt_settings
486
[13e816f]487# Prevents setting "-d /" by mistake.
488
489if [ $BUILDDIR = / ] ; then
490 echo -ne "\nThe root directory can't be used to build LFS.\n\n"
491 exit 1
492fi
493
494# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
495# and notify the user about that.
496
497if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
498 eval "$no_empty_builddir"
499fi
500
501# If requested, clean the build directory
502clean_builddir
503
[0170229]504if [[ ! -d $JHALFSDIR ]]; then
[a110145]505 mkdir -p $JHALFSDIR
[0170229]506fi
507
[13e816f]508if [[ "$PWD" != "$JHALFSDIR" ]]; then
[a110145]509 cp $COMMON_DIR/makefile-functions $JHALFSDIR/
[d0e48ec]510 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
[fb68d23]511 if [[ "$COMPARE" != "0" ]] ; then
[cc020f4]512 mkdir -p $JHALFSDIR/extras
[4612459]513 cp extras/* $JHALFSDIR/extras
[ed0a142]514 fi
[0170229]515 if [[ -n "$FILES" ]]; then
[9c90294]516 # pushd/popd necessary to deal with mulitiple files
[a110145]517 pushd $PACKAGE_DIR 1> /dev/null
518 cp $FILES $JHALFSDIR/
519 popd 1> /dev/null
[0170229]520 fi
[708a612]521 if [[ "$PROGNAME" != "blfs" ]]; then
522 [[ "$REPORT" = "1" ]] && cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
523 [[ "$GETPKG" = "1" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
524 fi
[12a5707]525 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
[0170229]526 export XSL=$JHALFSDIR/${XSL}
527fi
528
529if [[ ! -d $LOGDIR ]]; then
[a110145]530 mkdir $LOGDIR
[0170229]531fi
[3cc7540]532
533# After be sure that all look sane and if REPORT=1, dump the settings to a file
534# This file will be used to create the REPORT header
[708a612]535[[ "$PROGNAME" != "blfs" ]] && [[ "$REPORT" = "1" ]] && validate_config > $JHALFSDIR/jhalfs.config
[3cc7540]536
[0170229]537>$LOGDIR/$LOG
538
539get_book
[65d83a6]540echo "${SD_BORDER}${nl_}"
[12a5707]541
[0170229]542build_Makefile
[65d83a6]543echo "${SD_BORDER}${nl_}"
[12a5707]544
[386bc75]545run_make
[0170229]546
Note: See TracBrowser for help on using the repository browser.