source: master.sh@ 53588e2

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

Applied optimize patch from Jeremy Byron.

  • Property mode set to 100755
File size: 13.1 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 --optimize | -O )
161 test $# = 1 && eval "$exit_missing_arg"
162 shift
163 case $1 in
164 0 | 1 | 2 )
165 OPTIMIZE=$1
166 ;;
167 * )
168 echo -e "\n$1 isn't a valid optimize level value."
169 echo -e "You must use 0, 1, or 2.\n"
170 exit 1
171 ;;
172 esac
173 ;;
174
175 --testsuites | -T )
176 test $# = 1 && eval "$exit_missing_arg"
177 shift
178 case $1 in
179 0 | 1 | 2 | 3 )
180 TEST=$1
181 ;;
182 * )
183 echo -e "\n$1 isn't a valid testsuites level value."
184 echo -e "You must to use 0, 1, 2, or 3.\n"
185 exit 1
186 ;;
187 esac
188 ;;
189
190 --version | -V )
191 echo "$version"
192 exit 0
193 ;;
194
195 --working-copy | -W )
196 test $# = 1 && eval "$exit_missing_arg"
197 shift
198 case $PROGNAME in # Poor checks. We should find better ones.
199 lfs)
200 if [ -f $1/patches.ent ] ; then
201 WC=1
202 BOOK=$1
203 else
204 echo -e "\nLooks like $1 isn't a LFS working copy."
205 exit 1
206 fi
207 ;;
208 clfs)
209 if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
210 WC=1
211 BOOK=$1
212 else
213 echo -e "\nLooks like $1 isn't a CLFS working copy."
214 exit 1
215 fi
216 ;;
217 hlfs)
218 if [ -f $1/template.xml ] ; then
219 WC=1
220 BOOK=$1
221 else
222 echo -e "\nLooks like $1 isn't a HLFS working copy."
223 exit 1
224 fi
225 ;;
226 blfs)
227 if [ -f $1/use-unzip.xml ] ; then
228 WC=1
229 BOOK=$1
230 else
231 echo -e "\nLooks like $1 isn't a BLFS working copy."
232 exit 1
233 fi
234 ;;
235 esac
236 ;;
237
238 # Common options for LFS, CLFS and HLFS
239 --comparasion | -C )
240 test $# = 1 && eval "$exit_missing_arg"
241 shift
242 case $1 in
243 ICA) RUN_ICA=1
244 RUN_FARCE=0
245 COMPARE=1
246 ;;
247 farce) RUN_ICA=0
248 RUN_FARCE=1
249 COMPARE=1
250 ;;
251 both) RUN_ICA=1
252 RUN_FARCE=1
253 COMPARE=1
254 ;;
255 *)
256 echo -e "\n$1 is an unknown analysis method."
257 exit 1
258 ;;
259 esac
260 ;;
261
262 --fstab | -F )
263 test $# = 1 && eval "$exit_missing_arg"
264 shift
265 if [ -f $1 ] ; then
266 FSTAB=$1
267 else
268 echo -e "\nFile $1 not found. Verify your command line.\n"
269 exit 1
270 fi
271 ;;
272
273 --kernel-config | -K )
274 test $# = 1 && eval "$exit_missing_arg"
275 shift
276 if [ -f $1 ] ; then
277 CONFIG=$1
278 else
279 echo -e "\nFile $1 not found. Verify your command line.\n"
280 exit 1
281 fi
282 ;;
283
284 --make | -M ) RUNMAKE=1 ;;
285
286 --rebuild | -R ) CLEAN=1 ;;
287
288 # CLFS options
289 --arch | -A )
290 test $# = 1 && eval "$exit_missing_arg"
291 shift
292 case $1 in
293 x86 )
294 ARCH=x86
295 TARGET="i686-pc-linux-gnu"
296 ;;
297 i486 )
298 ARCH=x86
299 TARGET="i486-pc-linux-gnu"
300 ;;
301 i586 )
302 ARCH=x86
303 TARGET="i586-pc-linux-gnu"
304 ;;
305 ppc )
306 ARCH=ppc
307 TARGET="powerpc-unknown-linux-gnu"
308 ;;
309 mips )
310 ARCH=mips
311 TARGET="mips-unknown-linux-gnu"
312 ;;
313 mipsel )
314 ARCH=mips
315 TARGET="mipsel-unknown-linux-gnu"
316 ;;
317 sparc )
318 ARCH=sparc
319 TARGET="sparcv9-unknown-linux-gnu"
320 ;;
321 x86_64-64 )
322 ARCH=x86_64-64
323 TARGET="x86_64-unknown-linux-gnu"
324 ;;
325 mips64-64 )
326 ARCH=mips64-64
327 TARGET="mips-unknown-linux-gnu"
328 ;;
329 mipsel64-64 )
330 ARCH=mips64-64
331 TARGET="mipsel-unknown-linux-gnu"
332 ;;
333 sparc64-64 )
334 ARCH=sparc64-64
335 TARGET="sparc64-unknown-linux-gnu"
336 ;;
337 alpha )
338 ARCH=alpha
339 TARGET="alpha-unknown-linux-gnu"
340 ;;
341 x86_64 )
342 ARCH=x86_64
343 TARGET="x86_64-unknown-linux-gnu"
344 TARGET32="i686-pc-linux-gnu"
345 ;;
346 mips64 )
347 ARCH=mips64
348 TARGET="mips-unknown-linux-gnu"
349 TARGET32="mips-unknown-linux-gnu"
350 ;;
351 mipsel64 )
352 ARCH=mips64
353 TARGET="mipsel-unknown-linux-gnu"
354 TARGET32="mipsel-unknown-linux-gnu"
355 ;;
356 sparc64 )
357 ARCH=sparc64
358 TARGET="sparc64-unknown-linux-gnu"
359 TARGET32="sparcv9-unknown-linux-gnu"
360 ;;
361 ppc64 )
362 ARCH=ppc64
363 TARGET="powerpc64-unknown-linux-gnu"
364 TARGET32="powerpc-unknown-linux-gnu"
365 ;;
366 * )
367 echo -e "\n$1 is an unknown or unsopported arch."
368 exit 1
369 ;;
370 esac
371 ;;
372
373 --boot-config )
374 test $# = 1 && eval "$exit_missing_arg"
375 shift
376 if [ -f $1 ] ; then
377 BOOT_CONFIG=$1
378 else
379 echo -e "\nFile $1 not found. Verify your command line.\n"
380 exit 1
381 fi
382 ;;
383
384 --method )
385 test $# = 1 && eval "$exit_missing_arg"
386 shift
387 case $1 in
388 chroot | boot )
389 METHOD=$1
390 ;;
391 * )
392 echo -e "\n$1 isn't a valid build method."
393 exit 1
394 ;;
395 esac
396 ;;
397
398 # HLFS options
399 --model )
400 test $# = 1 && eval "$exit_missing_arg"
401 shift
402 case $1 in
403 glibc | uclibc )
404 MODEL=$1
405 ;;
406 * )
407 echo -e "\n$1 isn't a valid libc model."
408 exit 1
409 ;;
410 esac
411 ;;
412
413 # BLFS options
414 --dependencies )
415 test $# = 1 && eval "$exit_missing_arg"
416 shift
417 case $1 in
418 0 | 1 | 2 )
419 DEPEND=$1
420 ;;
421 * )
422 echo -e "\n$1 isn't a valid dependencies level."
423 exit 1
424 ;;
425 esac
426 ;;
427
428 # Unknown options
429 * ) usage ;;
430 esac
431 shift
432done
433
434#===================================================
435# Set the document location...
436# BOOK is either defined in
437# xxx.config
438# comand line
439# default
440# If set by conf file or cmd line leave it
441# alone otherwise load the default version
442#===================================================
443BOOK=${BOOK:=$PROGNAME-$LFSVRS}
444#===================================================
445
446
447# Check for minumum gcc and kernel versions
448#check_requirements 1 # 0/1 0-do not display values.
449echo
450check_version "2.6.2" "`uname -r`" "KERNEL"
451check_version "3.0" "$BASH_VERSION" "BASH"
452check_version "3.0" "`gcc -dumpversion`" "GCC"
453tarVer=`tar --version`
454check_version "1.15.0" "${tarVer##* }" "TAR"
455echo "${SD_BORDER}${nl_}"
456
457validate_config
458echo "${SD_BORDER}${nl_}"
459
460echo -n "Are you happy with these settings? yes/no (no): "
461read ANSWER
462if [ x$ANSWER != "xyes" ] ; then
463 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
464 exit 1
465fi
466echo "${nl_}${SD_BORDER}${nl_}"
467
468# Prevents setting "-d /" by mistake.
469
470if [ $BUILDDIR = / ] ; then
471 echo -ne "\nThe root directory can't be used to build LFS.\n\n"
472 exit 1
473fi
474
475# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
476# and notify the user about that.
477
478if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
479 eval "$no_empty_builddir"
480fi
481
482# If requested, clean the build directory
483clean_builddir
484
485if [[ ! -d $JHALFSDIR ]]; then
486 mkdir -p $JHALFSDIR
487fi
488
489if [[ "$PWD" != "$JHALFSDIR" ]]; then
490 cp $COMMON_DIR/makefile-functions $JHALFSDIR/
491 [[ "$OPTIMIZE" != "0" ]] && cp $COMMON_DIR/opt_override $JHALFSDIR/
492 if [[ "$COMPARE" != "0" ]] ; then
493 mkdir -p $JHALFSDIR/extras
494 cp extras/* $JHALFSDIR/extras
495 fi
496 if [[ -n "$FILES" ]]; then
497 # pushd/popd necessary to deal with mulitiple files
498 pushd $PACKAGE_DIR 1> /dev/null
499 cp $FILES $JHALFSDIR/
500 popd 1> /dev/null
501 fi
502 [[ "$REPORT" = "1" ]] && cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
503 [[ "$GETPKG" = "1" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
504 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
505 export XSL=$JHALFSDIR/${XSL}
506fi
507
508if [[ ! -d $LOGDIR ]]; then
509 mkdir $LOGDIR
510fi
511
512# After be sure that all look sane and if REPORT=1, dump the settings to a file
513# This file will be used to create the REPORT header
514[[ "$REPORT" = "1" ]] && validate_config > $JHALFSDIR/jhalfs.config
515
516>$LOGDIR/$LOG
517
518get_book
519echo "${SD_BORDER}${nl_}"
520
521build_Makefile
522echo "${SD_BORDER}${nl_}"
523
524run_make
525
Note: See TracBrowser for help on using the repository browser.