source: master.sh@ 1d14a64

experimental
Last change on this file since 1d14a64 was 1d14a64, checked in by George Boudreau <georgeb@…>, 18 years ago

Last of the missing menu vars

  • Property mode set to 100755
File size: 15.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${L_arrow}${BOLD}jhalfs-X${R_arrow} exit${OFF}\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
50if [[ -e using_menuconfig ]]; then
51 [[ $VERBOSITY > 0 ]] && echo -n "Loading config params from <configuration>..."
52 source configuration
53 [[ $? > 0 ]] && echo "file:configuration did not load.." && exit 1
54 [[ $VERBOSITY > 0 ]] && echo "OK"
55
56 #--- CONSTANTS
57 declare -r SVN="svn://svn.linuxfromscratch.org"
58 declare -r LOG=000-masterscript.log
59 # --- Server used if the file isn't found in SRC_ARCHIVE.
60 # As a last resort, the file will dowloaded from upstream, if possible.
61 SERVER=ftp://ftp.lfs-matrix.net
62 #--- Working directories
63 SCRIPT_ROOT=jhalfs
64 JHALFSDIR=$BUILDDIR/$SCRIPT_ROOT
65 LOGDIR=$JHALFSDIR/logs
66 TESTLOGDIR=$JHALFSDIR/test-logs
67 MKFILE=$JHALFSDIR/Makefile
68 #--- ICA report log directory
69 ICALOGDIR=$LOGDIR/ICA
70 #--- farce report log directory
71 FARCELOGDIR=$LOGDIR/farce
72 XSL=$PROGNAME.xsl
73 PKG_LST=unpacked
74
75 case $PROGNAME in
76 clfs2) LFSVRS=development; TREE=branches/clfs-2.0/BOOK ;;
77 *) LFSVRS=development; TREE=trunk/BOOK ;;
78 esac
79
80 if [[ ! -z ${BRANCH_ID} ]]; then
81 case $BRANCH_ID in
82 dev* | SVN | trunk )
83 case $PROGNAME in
84 clfs2 ) TREE=branches/clfs-2.0/BOOK ;;
85 *) TREE=trunk/BOOK ;;
86 esac
87 LFSVRS=development
88 ;;
89 branch-* )
90 LFSVRS=${BRANCH_ID}
91 TREE=branches/${BRANCH_ID#branch-}/BOOK
92 ;;
93 * )
94 case $PROGNAME in
95 lfs | hlfs )
96 LFSVRS=${BRANCH_ID}
97 TREE=tags/${BRANCH_ID}/BOOK
98 ;;
99 clfs | clfs2 )
100 LFSVRS=${BRANCH_ID}
101 TREE=tags/${BRANCH_ID}
102 ;;
103 esac
104 ;;
105 esac
106 fi
107 # These are boolean vars generated from Config.in.
108 # ISSUE: If a boolean parameter is not set <true> that
109 # variable is not defined by the menu app. This can
110 # cause a headache if you are not careful.
111 # The following parameters MUST be created and have a
112 # default value.
113 RUNMAKE=${RUNMAKE:-n}
114 GETPKG=${GETPKG:-n}
115 GETKERNEL=${GETKERNEL:-n}
116 COMPARE=${COMPARE:-n}
117 RUN_FARCE=${RUN_FARCE:-n}
118 RUN_ICA=${RUN_ICA:-n}
119 BOMB_TEST=${BOMB_TEST:-n}
120 STRIP=${STRIP:=n}
121 REPORT=${REPORT:=n}
122 VIMLANG=${VIMLANG:-n}
123 KEYMAP=${KEYMAP:=none}
124 GRSECURITY_HOST=${GRSECURITY_HOST:-n}
125
126else
127 #
128 [[ $VERBOSITY > 0 ]] && echo -n "Loading masterscript conf..."
129 source $COMMON_DIR/config
130 [[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
131 [[ $VERBOSITY > 0 ]] && echo "OK"
132 #
133 [[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
134 source $MODULE_CONFIG
135 [[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
136 [[ $VERBOSITY > 0 ]] && echo "OK"
137 #
138fi
139
140
141[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
142source $COMMON_DIR/common-functions
143[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
144[[ $VERBOSITY > 0 ]] && echo "OK"
145[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
146source $MODULE
147[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
148[[ $VERBOSITY > 0 ]] && echo "OK"
149#
150[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
151
152
153#===========================================================
154# If the var BOOK contains something then, maybe, it points
155# to a working doc.. set WC=1, else 'null'
156#===========================================================
157WC=${BOOK:+1}
158#===========================================================
159
160
161#*******************************************************************#
162[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
163source $COMMON_DIR/func_check_version.sh
164[[ $? > 0 ]] && echo " function module did not load.." && exit 2
165[[ $VERBOSITY > 0 ]] && echo "OK"
166
167[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
168source $COMMON_DIR/func_validate_configs.sh
169[[ $? > 0 ]] && echo " function module did not load.." && exit 2
170[[ $VERBOSITY > 0 ]] && echo "OK"
171[[ $VERBOSITY > 0 ]] && echo "${SD_BORDER}${nl_}"
172
173
174###################################
175### MAIN ###
176###################################
177
178# Evaluate any command line switches
179
180while test $# -gt 0 ; do
181 case $1 in
182 # Common options for {C,H}LFS books
183 --book | -B )
184 test $# = 1 && eval "$exit_missing_arg"
185 shift
186 case $1 in
187 dev* | SVN | trunk )
188 LFSVRS=development
189 TREE=trunk/BOOK
190 ;;
191 branch-* )
192 LFSVRS=$1
193 TREE=branches/${1#branch-}/BOOK
194 ;;
195 * )
196 case $PROGNAME in
197 lfs | hlfs )
198 LFSVRS=$1
199 TREE=tags/$1/BOOK
200 ;;
201 clfs )
202 LFSVRS=$1
203 TREE=tags/$1
204 ;;
205 esac
206 ;;
207 esac
208 ;;
209
210 --directory | -D )
211 test $# = 1 && eval "$exit_missing_arg"
212 shift
213 case $1 in
214 -* )
215 echo -e "\n$1 isn't a valid build directory."
216 echo -e "Directory names can't start with - .\n"
217 exit 1
218 ;;
219 * )
220 BUILDDIR=$1
221 JHALFSDIR=$BUILDDIR/${SCRIPT_ROOT}
222 LOGDIR=$JHALFSDIR/logs
223 TESTLOGDIR=$JHALFSDIR/test-logs
224 MKFILE=$JHALFSDIR/Makefile
225 ;;
226 esac
227 ;;
228
229 --get-packages | -G ) GETPKG=y ;;
230
231 --help | -h ) usage | more && exit ;;
232
233 --optimize | -O )
234 test $# = 1 && eval "$exit_missing_arg"
235 shift
236 case $1 in
237 0 | 1 | 2 )
238 OPTIMIZE=$1
239 ;;
240 * )
241 echo -e "\n$1 isn't a valid optimize level value."
242 echo -e "You must use 0, 1, or 2.\n"
243 exit 1
244 ;;
245 esac
246 ;;
247
248 --testsuites | -T )
249 test $# = 1 && eval "$exit_missing_arg"
250 shift
251 case $1 in
252 0 | 1 | 2 | 3 )
253 TEST=$1
254 ;;
255 * )
256 echo -e "\n$1 isn't a valid testsuites level value."
257 echo -e "You must to use 0, 1, 2, or 3.\n"
258 exit 1
259 ;;
260 esac
261 ;;
262
263 --version | -V )
264 echo "$version"
265 exit 0
266 ;;
267
268 --working-copy | -W )
269 test $# = 1 && eval "$exit_missing_arg"
270 shift
271 case $PROGNAME in # Poor checks. We should find better ones.
272 lfs)
273 if [ -d $1/chapter09 ] ; then
274 WC=1
275 BOOK=$1
276 else
277 echo -e "\nLooks like $1 isn't an LFS working copy."
278 exit 1
279 fi
280 ;;
281 clfs)
282 if [ -d $1/cross-tools ] ; then
283 WC=1
284 BOOK=$1
285 else
286 echo -e "\nLooks like $1 isn't a CLFS working copy."
287 exit 1
288 fi
289 ;;
290 hlfs)
291 if [ -f $1/template.xml ] ; then
292 WC=1
293 BOOK=$1
294 else
295 echo -e "\nLooks like $1 isn't an HLFS working copy."
296 exit 1
297 fi
298 ;;
299 esac
300 ;;
301
302 --comparison | -C )
303 test $# = 1 && eval "$exit_missing_arg"
304 shift
305 case $1 in
306 ICA) RUN_ICA=y; RUN_FARCE=n; COMPARE=y ;;
307 farce) RUN_ICA=n; RUN_FARCE=y; COMPARE=y ;;
308 both) RUN_ICA=y; RUN_FARCE=y; COMPARE=y ;;
309 *)
310 echo -e "\n$1 is an unknown analysis method."
311 exit 1
312 ;;
313 esac
314 ;;
315
316 --fstab | -F )
317 test $# = 1 && eval "$exit_missing_arg"
318 shift
319 if [ -f $1 ] ; then
320 FSTAB=$1
321 else
322 echo -e "\nFile $1 not found. Verify your command line.\n"
323 exit 1
324 fi
325 ;;
326
327 --kernel-config | -K )
328 test $# = 1 && eval "$exit_missing_arg"
329 shift
330 if [ -f $1 ] ; then
331 CONFIG=$1
332 else
333 echo -e "\nFile $1 not found. Verify your command line.\n"
334 exit 1
335 fi
336 ;;
337
338 --run-make | -M ) RUNMAKE=y ;;
339
340 --rebuild | -R ) CLEAN=y ;;
341
342 # CLFS options
343 --arch | -A )
344 test $# = 1 && eval "$exit_missing_arg"
345 shift
346 case $PROGNAME in
347 CLFS2)
348 case $1 in
349 arm) ARCH=arm; TARGET="arm-unknown-linux-gnu" ;;
350 x86) ARCH=x86; TARGET="i686-pc-linux-gnu" ;;
351 *) echo -e "\n$1 is an unknown or unsupported arch."; exit 1
352 esac
353 ;;
354 CLFS)
355 case $1 in
356 arm ) ARCH=arm; TARGET="arm-unknown-linux-gnu" ;;
357 x86 ) ARCH=x86; TARGET="i686-pc-linux-gnu" ;;
358 i486 ) ARCH=x86; TARGET="i486-pc-linux-gnu" ;;
359 i586 ) ARCH=x86; TARGET="i586-pc-linux-gnu" ;;
360 ppc ) ARCH=ppc; TARGET="powerpc-unknown-linux-gnu" ;;
361 mips ) ARCH=mips; TARGET="mips-unknown-linux-gnu" ;;
362 mipsel ) ARCH=mips; TARGET="mipsel-unknown-linux-gnu" ;;
363 sparc ) ARCH=sparc; TARGET="sparcv9-unknown-linux-gnu" ;;
364
365 x86_64-64 ) ARCH=x86_64-64; TARGET="x86_64-unknown-linux-gnu" ;;
366 mips64-64 ) ARCH=mips64-64; TARGET="mips-unknown-linux-gnu" ;;
367 mipsel64-64 ) ARCH=mips64-64; TARGET="mipsel-unknown-linux-gnu" ;;
368 sparc64-64 ) ARCH=sparc64-64; TARGET="sparc64-unknown-linux-gnu" ;;
369 alpha ) ARCH=alpha; TARGET="alpha-unknown-linux-gnu" ;;
370
371 x86_64 ) ARCH=x86_64; TARGET="x86_64-unknown-linux-gnu"; TARGET32="i686-pc-linux-gnu" ;;
372 mips64 ) ARCH=mips64; TARGET="mips-unknown-linux-gnu"; TARGET32="mips-unknown-linux-gnu" ;;
373 mipsel64 ) ARCH=mips64; TARGET="mipsel-unknown-linux-gnu"; TARGET32="mipsel-unknown-linux-gnu" ;;
374 sparc64 ) ARCH=sparc64; TARGET="sparc64-unknown-linux-gnu"; TARGET32="sparcv9-unknown-linux-gnu" ;;
375 ppc64 ) ARCH=ppc64; TARGET="powerpc64-unknown-linux-gnu"; TARGET32="powerpc-unknown-linux-gnu" ;;
376
377 * ) echo -e "\n$1 is an unknown or unsupported arch."; exit 1 ;;
378 esac
379 ;;
380 esac
381 ;;
382
383 --boot-config )
384 test $# = 1 && eval "$exit_missing_arg"
385 shift
386 if [ -f $1 ] ; then
387 BOOT_CONFIG=$1
388 else
389 echo -e "\nFile $1 not found. Verify your command line.\n"
390 exit 1
391 fi
392 ;;
393
394 --method )
395 test $# = 1 && eval "$exit_missing_arg"
396 shift
397 case $1 in
398 chroot | boot )
399 METHOD=$1
400 ;;
401 * )
402 echo -e "\n$1 isn't a valid build method."
403 exit 1
404 ;;
405 esac
406 ;;
407
408 # HLFS options
409 --model )
410 test $# = 1 && eval "$exit_missing_arg"
411 shift
412 case $1 in
413 glibc | uclibc )
414 MODEL=$1
415 ;;
416 * )
417 echo -e "\n$1 isn't a valid libc model."
418 exit 1
419 ;;
420 esac
421 ;;
422
423 # Unknown options
424 * ) usage ;;
425 esac
426 shift
427done
428
429
430#===================================================
431# Set the document location...
432# BOOK is either defined in
433# xxx.config
434# comand line
435# default
436# If set by conf file or cmd line leave it
437# alone otherwise load the default version
438#===================================================
439BOOK=${BOOK:=$PROGNAME-$LFSVRS}
440#===================================================
441
442
443# Check for minimum bash,tar,gcc and kernel versions
444echo
445check_version "2.6.2" "`uname -r`" "KERNEL"
446check_version "3.0" "$BASH_VERSION" "BASH"
447check_version "3.0" "`gcc -dumpversion`" "GCC"
448tarVer=`tar --version | head -n1 | cut -d " " -f4`
449check_version "1.15.0" "${tarVer}" "TAR"
450echo "${SD_BORDER}${nl_}"
451
452validate_config
453echo "${SD_BORDER}${nl_}"
454echo -n "Are you happy with these settings? yes/no (no): "
455read ANSWER
456if [ x$ANSWER != "xyes" ] ; then
457 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
458 exit 1
459fi
460echo "${nl_}${SD_BORDER}${nl_}"
461
462# Load additional modules or configuration files based on global settings
463# compare module
464if [[ "$COMPARE" = "y" ]]; then
465 [[ $VERBOSITY > 0 ]] && echo -n "Loading compare module..."
466 source $COMMON_DIR/func_compare.sh
467 [[ $? > 0 ]] && echo "$COMMON_DIR/func_compare.sh did not load.." && exit
468 [[ $VERBOSITY > 0 ]] && echo "OK"
469fi
470#
471# optimize module
472if [[ "$OPTIMIZE" != "0" ]]; then
473 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization module..."
474 source optimize/optimize_functions
475 [[ $? > 0 ]] && echo " optimize/optimize_functions did not load.." && exit
476 [[ $VERBOSITY > 0 ]] && echo "OK"
477 #
478 # optimize configurations
479 [[ $VERBOSITY > 0 ]] && echo -n "Loading optimization config..."
480 source optimize/opt_config
481 [[ $? > 0 ]] && echo " optimize/opt_config did not load.." && exit
482 [[ $VERBOSITY > 0 ]] && echo "OK"
483 # Validate optimize settings, if required
484 validate_opt_settings
485fi
486#
487
488# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
489# and notify the user about that.
490if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
491 eval "$no_empty_builddir"
492fi
493
494# If requested, clean the build directory
495clean_builddir
496
497if [[ ! -d $JHALFSDIR ]]; then
498 mkdir -p $JHALFSDIR
499fi
500#
501# Create $BUILDDIR/sources even though it could be created by get_sources()
502if [[ ! -d $BUILDDIR/sources ]]; then
503 mkdir -p $BUILDDIR/sources
504fi
505#
506# Create the log directory
507if [[ ! -d $LOGDIR ]]; then
508 mkdir $LOGDIR
509fi
510>$LOGDIR/$LOG
511#
512[[ "$TEST" != "0" ]] && [[ ! -d $TESTLOGDIR ]] && install -d -m 1777 $TESTLOGDIR
513#
514if [[ "$PWD" != "$JHALFSDIR" ]]; then
515 cp $COMMON_DIR/{makefile-functions,progress_bar.sh} $JHALFSDIR/
516 #
517 [[ "$OPTIMIZE" != "0" ]] && cp optimize/opt_override $JHALFSDIR/
518 #
519 if [[ "$COMPARE" = "y" ]]; then
520 mkdir -p $JHALFSDIR/extras
521 cp extras/* $JHALFSDIR/extras
522 fi
523 #
524 if [[ -n "$FILES" ]]; then
525 # pushd/popd necessary to deal with multiple files
526 pushd $PACKAGE_DIR 1> /dev/null
527 cp $FILES $JHALFSDIR/
528 popd 1> /dev/null
529 fi
530 #
531 if [[ "$REPORT" = "y" ]]; then
532 cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
533 # After being sure that all looks sane, dump the settings to a file
534 # This file will be used to create the REPORT header
535 validate_config > $JHALFSDIR/jhalfs.config
536 fi
537 #
538 [[ "$GETPKG" = "y" ]] && cp $COMMON_DIR/urls.xsl $JHALFSDIR/
539 #
540 cp $COMMON_DIR/packages.xsl $JHALFSDIR/
541 #
542 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
543 export XSL=$JHALFSDIR/${XSL}
544fi
545
546get_book
547echo "${SD_BORDER}${nl_}"
548
549build_Makefile
550echo "${SD_BORDER}${nl_}"
551
552run_make
Note: See TracBrowser for help on using the repository browser.