source: master.sh@ 4887f67

1.0 2.3 2.3.x 2.4 ablfs ablfs-more legacy new_features trunk
Last change on this file since 4887f67 was 1b65a84, checked in by Manuel Canales Esparcia <manuel@…>, 19 years ago

Merged optimize code from experimental branch.

  • Property mode set to 100755
File size: 13.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${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 config module <$MODULE_CONFIG>..."
60source $MODULE_CONFIG
61[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
62[[ $VERBOSITY > 0 ]] && echo "OK"
63#
64[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
65source $MODULE
66[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
67[[ $VERBOSITY > 0 ]] && echo "OK"
68#
69[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
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#*******************************************************************#
81[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
82source $COMMON_DIR/func_check_version.sh
83[[ $? > 0 ]] && echo " function module did not load.." && exit 2
84[[ $VERBOSITY > 0 ]] && echo "OK"
85
86[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
87source $COMMON_DIR/func_validate_configs.sh
88[[ $? > 0 ]] && echo " function module did not load.." && exit 2
89[[ $VERBOSITY > 0 ]] && echo "OK"
90[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
91
92
93###################################
94### MAIN ###
95###################################
96
97# Evaluate any command line switches
98
99while test $# -gt 0 ; do
100 case $1 in
101 # Common options for all books
102 --book | -B )
103 test $# = 1 && eval "$exit_missing_arg"
104 shift
105 case $1 in
106 dev* | SVN | trunk )
107 LFSVRS=development
108 ;;
109 *) if [[ "$PROGNAME" = "lfs" ]]; then
110 case $1 in
111 6.1.1 )
112 echo "For stable 6.1.1 book, please use jhalfs-0.2."
113 exit 0
114 ;;
115 * )
116 echo "$1 is an unsupported version at this time."
117 exit 0
118 ;;
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."
122 exit 0
123 fi
124 ;;
125 esac
126 ;;
127
128 --directory | -D )
129 test $# = 1 && eval "$exit_missing_arg"
130 shift
131 case $1 in
132 -* )
133 echo -e "\n$1 isn't a valid build directory."
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
144 ;;
145
146 --get-packages | -G ) GETPKG=1 ;;
147
148 --help | -h ) usage | more && exit ;;
149
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
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
185 --working-copy | -W )
186 test $# = 1 && eval "$exit_missing_arg"
187 shift
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
194 echo -e "\nLooks like $1 isn't a LFS working copy."
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
203 echo -e "\nLooks like $1 isn't a CLFS working copy."
204 exit 1
205 fi
206 ;;
207 hlfs)
208 if [ -f $1/template.xml ] ; then
209 WC=1
210 BOOK=$1
211 else
212 echo -e "\nLooks like $1 isn't a HLFS working copy."
213 exit 1
214 fi
215 ;;
216 blfs)
217 if [ -f $1/use-unzip.xml ] ; then
218 WC=1
219 BOOK=$1
220 else
221 echo -e "\nLooks like $1 isn't a BLFS working copy."
222 exit 1
223 fi
224 ;;
225 esac
226 ;;
227
228 # Common options for LFS, CLFS and HLFS
229 --comparasion | -C )
230 test $# = 1 && eval "$exit_missing_arg"
231 shift
232 case $1 in
233 ICA) RUN_ICA=1
234 RUN_FARCE=0
235 COMPARE=1
236 ;;
237 farce) RUN_ICA=0
238 RUN_FARCE=1
239 COMPARE=1
240 ;;
241 both) RUN_ICA=1
242 RUN_FARCE=1
243 COMPARE=1
244 ;;
245 *)
246 echo -e "\n$1 is an unknown analysis method."
247 exit 1
248 ;;
249 esac
250 ;;
251
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
274 --make | -M ) RUNMAKE=1 ;;
275
276 --rebuild | -R ) CLEAN=1 ;;
277
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
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
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
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
418 # Unknown options
419 * ) usage ;;
420 esac
421 shift
422done
423
424#===================================================
425# Set the document location...
426# BOOK is either defined in
427# xxx.config
428# comand line
429# default
430# If set by conf file or cmd line leave it
431# alone otherwise load the default version
432#===================================================
433BOOK=${BOOK:=$PROGNAME-$LFSVRS}
434#===================================================
435
436
437# Check for minumum gcc and kernel versions
438#check_requirements 1 # 0/1 0-do not display values.
439echo
440check_version "2.6.2" "`uname -r`" "KERNEL"
441check_version "3.0" "$BASH_VERSION" "BASH"
442check_version "3.0" "`gcc -dumpversion`" "GCC"
443tarVer=`tar --version`
444check_version "1.15.0" "${tarVer##* }" "TAR"
445echo "${SD_BORDER}${nl_}"
446
447validate_config
448echo "${SD_BORDER}${nl_}"
449
450echo -n "Are you happy with these settings? yes/no (no): "
451read ANSWER
452if [ x$ANSWER != "xyes" ] ; then
453 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
454 exit 1
455fi
456echo "${nl_}${SD_BORDER}${nl_}"
457
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#
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#
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
484# Validate optimize settings, if required
485[[ "$OPTIMIZE" != "0" ]] && validate_opt_settings
486
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
504if [[ ! -d $JHALFSDIR ]]; then
505 mkdir -p $JHALFSDIR
506fi
507
508if [[ "$PWD" != "$JHALFSDIR" ]]; then
509 cp $COMMON_DIR/makefile-functions $JHALFSDIR/
510 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
511 if [[ "$COMPARE" != "0" ]] ; then
512 mkdir -p $JHALFSDIR/extras
513 cp extras/* $JHALFSDIR/extras
514 fi
515 if [[ -n "$FILES" ]]; then
516 # pushd/popd necessary to deal with mulitiple files
517 pushd $PACKAGE_DIR 1> /dev/null
518 cp $FILES $JHALFSDIR/
519 popd 1> /dev/null
520 fi
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
525 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
526 export XSL=$JHALFSDIR/${XSL}
527fi
528
529if [[ ! -d $LOGDIR ]]; then
530 mkdir $LOGDIR
531fi
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
535[[ "$PROGNAME" != "blfs" ]] && [[ "$REPORT" = "1" ]] && validate_config > $JHALFSDIR/jhalfs.config
536
537>$LOGDIR/$LOG
538
539get_book
540echo "${SD_BORDER}${nl_}"
541
542build_Makefile
543echo "${SD_BORDER}${nl_}"
544
545run_make
546
Note: See TracBrowser for help on using the repository browser.