source: master.sh@ b414549

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

POC for optimizations code.

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