source: master.sh@ d20c553

experimental
Last change on this file since d20c553 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
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-X${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 optimization config..."
60source $COMMON_DIR/opt_config
61[[ $? > 0 ]] && echo " $COMMON_DIR/opt_config did not load.." && exit
62[[ $VERBOSITY > 0 ]] && echo "OK"
63#
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
67[[ $VERBOSITY > 0 ]] && echo "OK"
68#
69[[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
70source $MODULE_CONFIG
71[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
72[[ $VERBOSITY > 0 ]] && echo "OK"
73#
74[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
75source $MODULE
76[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
77[[ $VERBOSITY > 0 ]] && echo "OK"
78#
79[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
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#*******************************************************************#
91[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
92source $COMMON_DIR/func_check_version.sh
93[[ $? > 0 ]] && echo " function module did not load.." && exit 2
94[[ $VERBOSITY > 0 ]] && echo "OK"
95
96[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
97source $COMMON_DIR/func_validate_configs.sh
98[[ $? > 0 ]] && echo " function module did not load.." && exit 2
99[[ $VERBOSITY > 0 ]] && echo "OK"
100[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
101
102
103###################################
104### MAIN ###
105###################################
106
107# Evaluate any command line switches
108
109while test $# -gt 0 ; do
110 case $1 in
111 # Common options for all books
112 --book | -B )
113 test $# = 1 && eval "$exit_missing_arg"
114 shift
115 case $1 in
116 dev* | SVN | trunk )
117 LFSVRS=development
118 ;;
119 *) if [[ "$PROGNAME" = "lfs" ]]; then
120 case $1 in
121 6.1.1 )
122 echo "For stable 6.1.1 book, please use jhalfs-0.2."
123 exit 0
124 ;;
125 * )
126 echo "$1 is an unsupported version at this time."
127 exit 0
128 ;;
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."
132 exit 0
133 fi
134 ;;
135 esac
136 ;;
137
138 --directory | -D )
139 test $# = 1 && eval "$exit_missing_arg"
140 shift
141 case $1 in
142 -* )
143 echo -e "\n$1 isn't a valid build directory."
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
154 ;;
155
156 --get-packages | -G ) GETPKG=1 ;;
157
158 --help | -h ) usage | more && exit ;;
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
180 --working-copy | -W )
181 test $# = 1 && eval "$exit_missing_arg"
182 shift
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
189 echo -e "\nLooks like $1 isn't a LFS working copy."
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
198 echo -e "\nLooks like $1 isn't a CLFS working copy."
199 exit 1
200 fi
201 ;;
202 hlfs)
203 if [ -f $1/template.xml ] ; then
204 WC=1
205 BOOK=$1
206 else
207 echo -e "\nLooks like $1 isn't a HLFS working copy."
208 exit 1
209 fi
210 ;;
211 blfs)
212 if [ -f $1/use-unzip.xml ] ; then
213 WC=1
214 BOOK=$1
215 else
216 echo -e "\nLooks like $1 isn't a BLFS working copy."
217 exit 1
218 fi
219 ;;
220 esac
221 ;;
222
223 # Common options for LFS, CLFS and HLFS
224 --comparasion | -C )
225 test $# = 1 && eval "$exit_missing_arg"
226 shift
227 case $1 in
228 ICA) RUN_ICA=1
229 RUN_FARCE=0
230 COMPARE=1
231 ;;
232 farce) RUN_ICA=0
233 RUN_FARCE=1
234 COMPARE=1
235 ;;
236 both) RUN_ICA=1
237 RUN_FARCE=1
238 COMPARE=1
239 ;;
240 *)
241 echo -e "\n$1 is an unknown analysis method."
242 exit 1
243 ;;
244 esac
245 ;;
246
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
269 --make | -M ) RUNMAKE=1 ;;
270
271 --rebuild | -R ) CLEAN=1 ;;
272
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
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
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
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
413 # Unknown options
414 * ) usage ;;
415 esac
416 shift
417done
418
419#===================================================
420# Set the document location...
421# BOOK is either defined in
422# xxx.config
423# comand line
424# default
425# If set by conf file or cmd line leave it
426# alone otherwise load the default version
427#===================================================
428BOOK=${BOOK:=$PROGNAME-$LFSVRS}
429#===================================================
430
431
432# Check for minumum gcc and kernel versions
433#check_requirements 1 # 0/1 0-do not display values.
434echo
435check_version "2.6.2" "`uname -r`" "KERNEL"
436check_version "3.0" "$BASH_VERSION" "BASH"
437check_version "3.0" "`gcc -dumpversion`" "GCC"
438tarVer=`tar --version`
439check_version "1.15.0" "${tarVer##* }" "TAR"
440echo "${SD_BORDER}${nl_}"
441
442validate_config
443echo "${SD_BORDER}${nl_}"
444
445echo -n "Are you happy with these settings? yes/no (no): "
446read ANSWER
447if [ x$ANSWER != "xyes" ] ; then
448 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
449 exit 1
450fi
451echo "${nl_}${SD_BORDER}${nl_}"
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
470if [[ ! -d $JHALFSDIR ]]; then
471 mkdir -p $JHALFSDIR
472fi
473
474if [[ "$PWD" != "$JHALFSDIR" ]]; then
475 cp $COMMON_DIR/makefile-functions $JHALFSDIR/
476 [[ "$OPTIMIZE" = "1" ]] && cp $COMMON_DIR/opt_override $JHALFSDIR/
477 if [[ "$COMPARE" != "0" ]] ; then
478 mkdir -p $JHALFSDIR/extras
479 cp extras/* $JHALFSDIR/extras
480 fi
481 if [[ -n "$FILES" ]]; then
482 # pushd/popd necessary to deal with mulitiple files
483 pushd $PACKAGE_DIR 1> /dev/null
484 cp $FILES $JHALFSDIR/
485 popd 1> /dev/null
486 fi
487 [[ "$REPORT" = "1" ]] && cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
488 [[ "$GETPKG" = "1" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
489 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
490 export XSL=$JHALFSDIR/${XSL}
491fi
492
493if [[ ! -d $LOGDIR ]]; then
494 mkdir $LOGDIR
495fi
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
501>$LOGDIR/$LOG
502
503get_book
504echo "${SD_BORDER}${nl_}"
505
506build_Makefile
507echo "${SD_BORDER}${nl_}"
508
509run_make
510
Note: See TracBrowser for help on using the repository browser.