source: master.sh@ 944d69d

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

Bug fix

  • Property mode set to 100755
File size: 12.6 KB
RevLine 
[0170229]1#!/bin/bash
[12a5707]2# $Id$
[0170229]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() {
[f7590ba]17 echo -e "\n\t${BOLD}Goodbye and thank you for choosing ${L_arrow}jhalfs-X${R_arrow}\n"
[0170229]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
[12a5707]42 PROGNAME=$(basename $0)
43 COMMON_DIR="common"
[26a8fdf]44 PACKAGE_DIR=$(echo $PROGNAME | tr [a-z] [A-Z])
[12a5707]45 MODULE=$PACKAGE_DIR/master.sh
46MODULE_CONFIG=$PACKAGE_DIR/config
[26a8fdf]47 VERBOSITY=0
[12a5707]48
[26a8fdf]49[[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
[12a5707]50source $COMMON_DIR/common-functions
51[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
[26a8fdf]52[[ $VERBOSITY > 0 ]] && echo "OK"
[12a5707]53#
[26a8fdf]54[[ $VERBOSITY > 0 ]] && echo -n "Loading masterscript conf..."
[12a5707]55source $COMMON_DIR/config
[13e816f]56[[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
[26a8fdf]57[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]58#
[d6614ab]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
[a5fa1a9]62[[ $VERBOSITY > 0 ]] && echo "OK"
63#
[26a8fdf]64[[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
[0170229]65source $MODULE_CONFIG
66[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
[26a8fdf]67[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]68#
[26a8fdf]69[[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
[0170229]70source $MODULE
[12a5707]71[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
[26a8fdf]72[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]73#
[26a8fdf]74[[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
[0170229]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#*******************************************************************#
[26a8fdf]86[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
[12a5707]87source $COMMON_DIR/func_check_version.sh
88[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[26a8fdf]89[[ $VERBOSITY > 0 ]] && echo "OK"
[0170229]90
[26a8fdf]91[[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
[12a5707]92source $COMMON_DIR/func_validate_configs.sh
93[[ $? > 0 ]] && echo " function module did not load.." && exit 2
[26a8fdf]94[[ $VERBOSITY > 0 ]] && echo "OK"
95[[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
[0170229]96
97
98###################################
[4612459]99### MAIN ###
[0170229]100###################################
101
102# Evaluate any command line switches
103
104while test $# -gt 0 ; do
105 case $1 in
[40ccddf]106 # Common options for all books
[5627958]107 --book | -B )
[0170229]108 test $# = 1 && eval "$exit_missing_arg"
109 shift
110 case $1 in
111 dev* | SVN | trunk )
112 LFSVRS=development
113 ;;
[5627958]114 *) if [[ "$PROGNAME" = "lfs" ]]; then
115 case $1 in
[d95b8f2]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 ;;
[18911500]121 * )
122 echo "$1 is an unsupported version at this time."
123 exit 0
124 ;;
[5627958]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."
[d95b8f2]128 exit 0
129 fi
[0170229]130 ;;
131 esac
132 ;;
133
[c16cedc]134 --directory | -D )
[0170229]135 test $# = 1 && eval "$exit_missing_arg"
136 shift
[e95c26c]137 case $1 in
138 -* )
[ea29b1f]139 echo -e "\n$1 isn't a valid build directory."
[e95c26c]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
[0170229]150 ;;
151
[e2b5b99]152 --get-packages | -G ) HPKG=1 ;;
[c16cedc]153
[e2b5b99]154 --help | -h ) usage | more && exit ;;
[c16cedc]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
[0170229]176 --working-copy | -W )
177 test $# = 1 && eval "$exit_missing_arg"
178 shift
[5627958]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
[da626a9]185 echo -e "\nLooks like $1 isn't a LFS working copy."
[5627958]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
[da626a9]194 echo -e "\nLooks like $1 isn't a CLFS working copy."
[5627958]195 exit 1
196 fi
197 ;;
198 hlfs)
199 if [ -f $1/template.xml ] ; then
200 WC=1
201 BOOK=$1
202 else
[da626a9]203 echo -e "\nLooks like $1 isn't a HLFS working copy."
[5627958]204 exit 1
205 fi
206 ;;
207 blfs)
208 if [ -f $1/use-unzip.xml ] ; then
209 WC=1
210 BOOK=$1
211 else
[da626a9]212 echo -e "\nLooks like $1 isn't a BLFS working copy."
[5627958]213 exit 1
214 fi
215 ;;
[4532c37]216 esac
217 ;;
[0170229]218
[40ccddf]219 # Common options for LFS, CLFS and HLFS
[4612459]220 --comparasion | -C )
221 test $# = 1 && eval "$exit_missing_arg"
222 shift
[02d1ae7]223 case $1 in
[4612459]224 ICA) RUN_ICA=1
225 RUN_FARCE=0
[fb68d23]226 COMPARE=1
[4612459]227 ;;
228 farce) RUN_ICA=0
229 RUN_FARCE=1
[fb68d23]230 COMPARE=1
[4612459]231 ;;
232 both) RUN_ICA=1
233 RUN_FARCE=1
[fb68d23]234 COMPARE=1
[97520c9]235 ;;
[4612459]236 *)
237 echo -e "\n$1 is an unknown analisys method."
238 exit 1
239 ;;
240 esac
241 ;;
[42346b2]242
[40ccddf]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
[bd99331]265 --make | -M ) RUNMAKE=1 ;;
[40ccddf]266
267 --rebuild | -R ) CLEAN=1 ;;
268
[bd99331]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
[5ff30ff]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
[bd99331]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
[890acc6]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
[bd99331]413 # Unknown options
[e794f06]414 * ) usage ;;
[0170229]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...
[13e816f]433# BOOK is either defined in
[0170229]434# xxx.config
435# comand line
[13e816f]436# default
[d95b8f2]437# If set by conf file or cmd line leave it
[0170229]438# alone otherwise load the default version
439#===================================================
440BOOK=${BOOK:=$PROGNAME-$LFSVRS}
441#===================================================
442
[13e816f]443
444# Check for minumum gcc and kernel versions
445#check_requirements 1 # 0/1 0-do not display values.
[f15fe85]446echo
[13e816f]447check_version "2.6.2" "`uname -r`" "KERNEL"
448check_version "3.0" "$BASH_VERSION" "BASH"
449check_version "3.0" "`gcc -dumpversion`" "GCC"
[e1edff3]450tarVer=`tar --version`
451check_version "1.15.0" "${tarVer##* }" "TAR"
[13e816f]452echo "---------------${nl_}"
453
[3051f95]454validate_config
[13e816f]455echo "---------------${nl_}"
456
[7e6ddf0]457echo -n "Are you happy with these settings? yes/no (no): "
[13e816f]458read ANSWER
459if [ x$ANSWER != "xyes" ] ; then
460 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
461 exit 1
462fi
[a110145]463echo "${nl_}---------------${nl_}"
[13e816f]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
[0170229]482if [[ ! -d $JHALFSDIR ]]; then
[a110145]483 mkdir -p $JHALFSDIR
[0170229]484fi
485
[13e816f]486if [[ "$PWD" != "$JHALFSDIR" ]]; then
[a110145]487 cp $COMMON_DIR/makefile-functions $JHALFSDIR/
[fb68d23]488 if [[ "$COMPARE" != "0" ]] ; then
[cc020f4]489 mkdir -p $JHALFSDIR/extras
[4612459]490 cp extras/* $JHALFSDIR/extras
[ed0a142]491 fi
[0170229]492 if [[ -n "$FILES" ]]; then
[9c90294]493 # pushd/popd necessary to deal with mulitiple files
[a110145]494 pushd $PACKAGE_DIR 1> /dev/null
495 cp $FILES $JHALFSDIR/
496 popd 1> /dev/null
[0170229]497 fi
[12a5707]498 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
[0170229]499 export XSL=$JHALFSDIR/${XSL}
500fi
501
502if [[ ! -d $LOGDIR ]]; then
[a110145]503 mkdir $LOGDIR
[0170229]504fi
505>$LOGDIR/$LOG
506
507get_book
508echo "---------------${nl_}"
[12a5707]509
[0170229]510build_Makefile
511echo "---------------${nl_}"
[12a5707]512
[386bc75]513run_make
[0170229]514
Note: See TracBrowser for help on using the repository browser.