source: master.sh@ c483858

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

Ported r2581:2583 from trunk.

  • 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 compare module..."
60source $COMMON_DIR/func_compare.sh
61[[ $? > 0 ]] && echo "$COMMON_DIR/func_compare.sh did not load.." && exit
62[[ $VERBOSITY > 0 ]] && echo "OK"
63#
64[[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
65source $MODULE_CONFIG
66[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
67[[ $VERBOSITY > 0 ]] && echo "OK"
68#
69[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
70source $MODULE
71[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
72[[ $VERBOSITY > 0 ]] && echo "OK"
73#
74[[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
75
76
77#===========================================================
78# If the var BOOK contains something then, maybe, it points
79# to a working doc.. set WC=1, else 'null'
80#===========================================================
81WC=${BOOK:+1}
82#===========================================================
83
84
85#*******************************************************************#
86[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
87source $COMMON_DIR/func_check_version.sh
88[[ $? > 0 ]] && echo " function module did not load.." && exit 2
89[[ $VERBOSITY > 0 ]] && echo "OK"
90
91[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
92source $COMMON_DIR/func_validate_configs.sh
93[[ $? > 0 ]] && echo " function module did not load.." && exit 2
94[[ $VERBOSITY > 0 ]] && echo "OK"
95[[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
96
97
98###################################
99### MAIN ###
100###################################
101
102# Evaluate any command line switches
103
104while test $# -gt 0 ; do
105 case $1 in
106 # Common options for all books
107 --book | -B )
108 test $# = 1 && eval "$exit_missing_arg"
109 shift
110 case $1 in
111 dev* | SVN | trunk )
112 LFSVRS=development
113 ;;
114 *) if [[ "$PROGNAME" = "lfs" ]]; then
115 case $1 in
116 6.1.1 )
117 echo "For stable 6.1.1 book, please use jhalfs-0.2."
118 exit 0
119 ;;
120 udev*) LFSVRS=udev_update ;;
121 * )
122 echo "$1 is an unsupported version at this time."
123 exit 0
124 ;;
125 esac
126 else
127 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."
128 exit 0
129 fi
130 ;;
131 esac
132 ;;
133
134 --directory | -D )
135 test $# = 1 && eval "$exit_missing_arg"
136 shift
137 case $1 in
138 -* )
139 echo -e "\n$1 isn't a valid build directory."
140 echo -e "Directory names can't start with - .\n"
141 exit 1
142 ;;
143 * )
144 BUILDDIR=$1
145 JHALFSDIR=$BUILDDIR/jhalfs
146 LOGDIR=$JHALFSDIR/logs
147 MKFILE=$JHALFSDIR/Makefile
148 ;;
149 esac
150 ;;
151
152 --get-packages | -G ) HPKG=1 ;;
153
154 --help | -h ) usage | more && exit ;;
155
156 --testsuites | -T )
157 test $# = 1 && eval "$exit_missing_arg"
158 shift
159 case $1 in
160 0 | 1 | 2 | 3 )
161 TEST=$1
162 ;;
163 * )
164 echo -e "\n$1 isn't a valid testsuites level value."
165 echo -e "You must to use 0, 1, 2, or 3.\n"
166 exit 1
167 ;;
168 esac
169 ;;
170
171 --version | -V )
172 echo "$version"
173 exit 0
174 ;;
175
176 --working-copy | -W )
177 test $# = 1 && eval "$exit_missing_arg"
178 shift
179 case $PROGNAME in # Poor checks. We should find better ones.
180 lfs)
181 if [ -f $1/patches.ent ] ; then
182 WC=1
183 BOOK=$1
184 else
185 echo -e "\nLooks like $1 isn't a LFS working copy."
186 exit 1
187 fi
188 ;;
189 clfs)
190 if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
191 WC=1
192 BOOK=$1
193 else
194 echo -e "\nLooks like $1 isn't a CLFS working copy."
195 exit 1
196 fi
197 ;;
198 hlfs)
199 if [ -f $1/template.xml ] ; then
200 WC=1
201 BOOK=$1
202 else
203 echo -e "\nLooks like $1 isn't a HLFS working copy."
204 exit 1
205 fi
206 ;;
207 blfs)
208 if [ -f $1/use-unzip.xml ] ; then
209 WC=1
210 BOOK=$1
211 else
212 echo -e "\nLooks like $1 isn't a BLFS working copy."
213 exit 1
214 fi
215 ;;
216 esac
217 ;;
218
219 # Common options for LFS, CLFS and HLFS
220 --comparasion | -C )
221 test $# = 1 && eval "$exit_missing_arg"
222 shift
223 case $1 in
224 ICA) RUN_ICA=1
225 RUN_FARCE=0
226 COMPARE=1
227 ;;
228 farce) RUN_ICA=0
229 RUN_FARCE=1
230 COMPARE=1
231 ;;
232 both) RUN_ICA=1
233 RUN_FARCE=1
234 COMPARE=1
235 ;;
236 *)
237 echo -e "\n$1 is an unknown analisys method."
238 exit 1
239 ;;
240 esac
241 ;;
242
243 --fstab | -F )
244 test $# = 1 && eval "$exit_missing_arg"
245 shift
246 if [ -f $1 ] ; then
247 FSTAB=$1
248 else
249 echo -e "\nFile $1 not found. Verify your command line.\n"
250 exit 1
251 fi
252 ;;
253
254 --kernel-config | -K )
255 test $# = 1 && eval "$exit_missing_arg"
256 shift
257 if [ -f $1 ] ; then
258 CONFIG=$1
259 else
260 echo -e "\nFile $1 not found. Verify your command line.\n"
261 exit 1
262 fi
263 ;;
264
265 --make | -M ) RUNMAKE=1 ;;
266
267 --rebuild | -R ) CLEAN=1 ;;
268
269 # CLFS options
270 --arch | -A )
271 test $# = 1 && eval "$exit_missing_arg"
272 shift
273 case $1 in
274 x86 )
275 ARCH=x86
276 TARGET="i686-pc-linux-gnu"
277 ;;
278 i486 )
279 ARCH=x86
280 TARGET="i486-pc-linux-gnu"
281 ;;
282 i586 )
283 ARCH=x86
284 TARGET="i586-pc-linux-gnu"
285 ;;
286 ppc )
287 ARCH=ppc
288 TARGET="powerpc-unknown-linux-gnu"
289 ;;
290 mips )
291 ARCH=mips
292 TARGET="mips-unknown-linux-gnu"
293 ;;
294 mipsel )
295 ARCH=mips
296 TARGET="mipsel-unknown-linux-gnu"
297 ;;
298 sparc )
299 ARCH=sparc
300 TARGET="sparcv9-unknown-linux-gnu"
301 ;;
302 sparcv8 )
303 ARCH=sparcv8
304 TARGET="sparc-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# Find the download client to use, if not already specified.
420
421if [ -z $DL ] ; then
422 if [ `type -p wget` ] ; then
423 DL=wget
424 elif [ `type -p curl` ] ; then
425 DL=curl
426 else
427 eval "$no_dl_client"
428 fi
429fi
430
431#===================================================
432# Set the document location...
433# BOOK is either defined in
434# xxx.config
435# comand line
436# default
437# If set by conf file or cmd line leave it
438# alone otherwise load the default version
439#===================================================
440BOOK=${BOOK:=$PROGNAME-$LFSVRS}
441#===================================================
442
443
444# Check for minumum gcc and kernel versions
445#check_requirements 1 # 0/1 0-do not display values.
446echo
447check_version "2.6.2" "`uname -r`" "KERNEL"
448check_version "3.0" "$BASH_VERSION" "BASH"
449check_version "3.0" "`gcc -dumpversion`" "GCC"
450tarVer=`tar --version`
451check_version "1.15.0" "${tarVer##* }" "TAR"
452echo "---------------${nl_}"
453
454validate_config
455echo "---------------${nl_}"
456
457echo -n "Are you happy with these settings? yes/no (no): "
458read ANSWER
459if [ x$ANSWER != "xyes" ] ; then
460 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
461 exit 1
462fi
463echo "${nl_}---------------${nl_}"
464
465# Prevents setting "-d /" by mistake.
466
467if [ $BUILDDIR = / ] ; then
468 echo -ne "\nThe root directory can't be used to build LFS.\n\n"
469 exit 1
470fi
471
472# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
473# and notify the user about that.
474
475if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
476 eval "$no_empty_builddir"
477fi
478
479# If requested, clean the build directory
480clean_builddir
481
482if [[ ! -d $JHALFSDIR ]]; then
483 mkdir -p $JHALFSDIR
484fi
485
486if [[ "$PWD" != "$JHALFSDIR" ]]; then
487 cp $COMMON_DIR/makefile-functions $JHALFSDIR/
488 if [[ "$COMPARE" != "0" ]] ; then
489 mkdir -p $JHALFSDIR/extras
490 cp extras/* $JHALFSDIR/extras
491 fi
492 if [[ -n "$FILES" ]]; then
493 # pushd/popd necessary to deal with mulitiple files
494 pushd $PACKAGE_DIR 1> /dev/null
495 cp $FILES $JHALFSDIR/
496 popd 1> /dev/null
497 fi
498 [[ "$REPORT" = "1" ]] && cp $COMMON_DIR/create-sbu_du-report.sh $JHALFSDIR/
499 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
500 export XSL=$JHALFSDIR/${XSL}
501fi
502
503if [[ ! -d $LOGDIR ]]; then
504 mkdir $LOGDIR
505fi
506
507# After be sure that all look sane and if REPORT=1, dump the settings to a file
508# This file will be used to create the REPORT header
509[[ "$REPORT" = "1" ]] && validate_config > $JHALFSDIR/jhalfs.config
510
511>$LOGDIR/$LOG
512
513get_book
514echo "---------------${nl_}"
515
516build_Makefile
517echo "---------------${nl_}"
518
519run_make
520
Note: See TracBrowser for help on using the repository browser.