source: master.sh@ e95c26c

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

Added a poor-man test to --directory switch.

  • Property mode set to 100755
File size: 11.5 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
48echo -n "Loading common-functions module..."
49source $COMMON_DIR/common-functions
50[[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
51echo "OK"
52#
53
54echo -n "Loading masterscript conf..."
55source $COMMON_DIR/config
56[[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
57echo "OK"
58#
59echo -n "Loading config module <$MODULE_CONFIG>..."
60source $MODULE_CONFIG
61[[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
62echo "OK"
63#
64echo -n "Loading code module <$MODULE>..."
65source $MODULE
66[[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
67echo "OK"
68#
69echo "---------------${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#*******************************************************************#
81echo -n "Loading function <func_check_version.sh>..."
82source $COMMON_DIR/func_check_version.sh
83[[ $? > 0 ]] && echo " function module did not load.." && exit 2
84echo "OK"
85
86echo -n "Loading function <func_validate_configs.sh>..."
87source $COMMON_DIR/func_validate_configs.sh
88[[ $? > 0 ]] && echo " function module did not load.." && exit 2
89echo "OK"
90echo "---------------${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 alpha*) LFSVRS=alphabetical ;;
116 udev*) LFSVRS=udev_update ;;
117 * ) echo "$1 is an unsupported version at this time." ;;
118 esac
119 else
120 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."
121 exit 0
122 fi
123 ;;
124 esac
125 ;;
126
127 --directory | -D )
128 test $# = 1 && eval "$exit_missing_arg"
129 shift
130 case $1 in
131 -* )
132 echo -e "\n$1 isn't a valid build directory\n."
133 echo -e "Directory names can't start with - .\n"
134 exit 1
135 ;;
136 * )
137 BUILDDIR=$1
138 JHALFSDIR=$BUILDDIR/jhalfs
139 LOGDIR=$JHALFSDIR/logs
140 MKFILE=$JHALFSDIR/Makefile
141 ;;
142 esac
143 ;;
144
145 --get-packages | -G ) HPKG=1 ;;
146
147 --help | -h )
148 if [[ "$PROGNAME" = "blfs" ]]; then
149 blfs_usage
150 else
151 usage
152 fi
153 ;;
154
155 --testsuites | -T )
156 test $# = 1 && eval "$exit_missing_arg"
157 shift
158 case $1 in
159 0 | 1 | 2 | 3 )
160 TEST=$1
161 ;;
162 * )
163 echo -e "\n$1 isn't a valid testsuites level value."
164 echo -e "You must to use 0, 1, 2, or 3.\n"
165 exit 1
166 ;;
167 esac
168 ;;
169
170 --version | -V )
171 clear
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 "\nLook 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 "\nLook 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 "\nLook 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 "\nLook like $1 isn't a BLFS working copy."
213 exit 1
214 fi
215 ;;
216
217 # Common options for LFS, CLFS and HLFS
218 --fstab | -F )
219 test $# = 1 && eval "$exit_missing_arg"
220 shift
221 if [ -f $1 ] ; then
222 FSTAB=$1
223 else
224 echo -e "\nFile $1 not found. Verify your command line.\n"
225 exit 1
226 fi
227 ;;
228
229 --kernel-config | -K )
230 test $# = 1 && eval "$exit_missing_arg"
231 shift
232 if [ -f $1 ] ; then
233 CONFIG=$1
234 else
235 echo -e "\nFile $1 not found. Verify your command line.\n"
236 exit 1
237 fi
238 ;;
239
240 --make | -M ) RUNMAKE=1 ;;
241
242 --rebuild | -R ) CLEAN=1 ;;
243
244 # CLFS options
245 --arch | -A )
246 test $# = 1 && eval "$exit_missing_arg"
247 shift
248 case $1 in
249 x86 )
250 ARCH=x86
251 TARGET="i686-pc-linux-gnu"
252 ;;
253 i486 )
254 ARCH=x86
255 TARGET="i486-pc-linux-gnu"
256 ;;
257 i586 )
258 ARCH=x86
259 TARGET="i586-pc-linux-gnu"
260 ;;
261 ppc )
262 ARCH=ppc
263 TARGET="powerpc-unknown-linux-gnu"
264 ;;
265 mips )
266 ARCH=mips
267 TARGET="mips-unknown-linux-gnu"
268 ;;
269 mipsel )
270 ARCH=mips
271 TARGET="mipsel-unknown-linux-gnu"
272 ;;
273 sparc )
274 ARCH=sparc
275 TARGET="sparcv9-unknown-linux-gnu"
276 ;;
277 sparcv8 )
278 ARCH=sparcv8
279 TARGET="sparc-unknown-linux-gnu"
280 ;;
281 x86_64-64 )
282 ARCH=x86_64-64
283 TARGET="x86_64-unknown-linux-gnu"
284 ;;
285 mips64-64 )
286 ARCH=mips64-64
287 TARGET="mips-unknown-linux-gnu"
288 ;;
289 mipsel64-64 )
290 ARCH=mips64-64
291 TARGET="mipsel-unknown-linux-gnu"
292 ;;
293 sparc64-64 )
294 ARCH=sparc64-64
295 TARGET="sparc64-unknown-linux-gnu"
296 ;;
297 alpha )
298 ARCH=alpha
299 TARGET="alpha-unknown-linux-gnu"
300 ;;
301 x86_64 )
302 ARCH=x86_64
303 TARGET="x86_64-unknown-linux-gnu"
304 TARGET32="i686-pc-linux-gnu"
305 ;;
306 mips64 )
307 ARCH=mips64
308 TARGET="mips-unknown-linux-gnu"
309 TARGET32="mips-unknown-linux-gnu"
310 ;;
311 mipsel64 )
312 ARCH=mips64
313 TARGET="mipsel-unknown-linux-gnu"
314 TARGET32="mipsel-unknown-linux-gnu"
315 ;;
316 sparc64 )
317 ARCH=sparc64
318 TARGET="sparc64-unknown-linux-gnu"
319 TARGET32="sparcv9-unknown-linux-gnu"
320 ;;
321 ppc64 )
322 ARCH=ppc64
323 TARGET="powerpc64-unknown-linux-gnu"
324 TARGET32="powerpc-unknown-linux-gnu"
325 ;;
326 * )
327 echo -e "\n$1 is an unknown or unsopported arch."
328 exit 1
329 ;;
330 esac
331 ;;
332
333 --method )
334 test $# = 1 && eval "$exit_missing_arg"
335 shift
336 case $1 in
337 chroot | boot )
338 METHOD=$1
339 ;;
340 * )
341 echo -e "\n$1 isn't a valid build method."
342 exit 1
343 ;;
344 esac
345 ;;
346
347 --boot-config )
348 test $# = 1 && eval "$exit_missing_arg"
349 shift
350 if [ -f $1 ] ; then
351 BOOT_CONFIG=$1
352 else
353 echo -e "\nFile $1 not found. Verify your command line.\n"
354 exit 1
355 fi
356 ;;
357
358 # HLFS options
359 --model )
360 test $# = 1 && eval "$exit_missing_arg"
361 shift
362 case $1 in
363 glibc | uclibc )
364 MODEL=$1
365 ;;
366 * )
367 echo -e "\n$1 isn't a valid libc model."
368 exit 1
369 ;;
370 esac
371 ;;
372
373 # BLFS options
374 --dependencies )
375 test $# = 1 && eval "$exit_missing_arg"
376 shift
377 case $1 in
378 0 | 1 | 2 )
379 DEPEND=$1
380 ;;
381 * )
382 echo -e "\n$1 isn't a valid dependencies level."
383 exit 1
384 ;;
385 esac
386 ;;
387
388 # Unknown options
389 * )
390 if [[ "$PROGNAME" = "blfs" ]]; then
391 blfs_usage
392 else
393 usage
394 fi
395 ;;
396 esac
397 shift
398done
399
400# Find the download client to use, if not already specified.
401
402if [ -z $DL ] ; then
403 if [ `type -p wget` ] ; then
404 DL=wget
405 elif [ `type -p curl` ] ; then
406 DL=curl
407 else
408 eval "$no_dl_client"
409 fi
410fi
411
412#===================================================
413# Set the document location...
414# BOOK is either defined in
415# xxx.config
416# comand line
417# default
418# If set by conf file or cmd line leave it
419# alone otherwise load the default version
420#===================================================
421BOOK=${BOOK:=$PROGNAME-$LFSVRS}
422#===================================================
423
424
425# Check for minumum gcc and kernel versions
426#check_requirements 1 # 0/1 0-do not display values.
427check_version "2.6.2" "`uname -r`" "KERNEL"
428check_version "3.0" "$BASH_VERSION" "BASH"
429check_version "3.0" "`gcc -dumpversion`" "GCC"
430tarVer=`tar --version`
431check_version "1.15.0" "${tarVer##* }" "TAR"
432echo "---------------${nl_}"
433
434validate_config 1 # 0/1 0-do not display values
435echo "---------------${nl_}"
436
437echo -n "Are you happy with that settings? yes/no (no): "
438read ANSWER
439if [ x$ANSWER != "xyes" ] ; then
440 echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
441 exit 1
442fi
443
444# Prevents setting "-d /" by mistake.
445
446if [ $BUILDDIR = / ] ; then
447 echo -ne "\nThe root directory can't be used to build LFS.\n\n"
448 exit 1
449fi
450
451# If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
452# and notify the user about that.
453
454if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
455 eval "$no_empty_builddir"
456fi
457
458# If requested, clean the build directory
459clean_builddir
460
461if [[ ! -d $JHALFSDIR ]]; then
462 mkdir -pv $JHALFSDIR
463fi
464
465if [[ "$PWD" != "$JHALFSDIR" ]]; then
466 cp -v $COMMON_DIR/makefile-functions $JHALFSDIR/
467 if [[ -n "$FILES" ]]; then
468 # pushd/popd necessary to deal with mulitiple files
469 pushd $PACKAGE_DIR
470 cp -v $FILES $JHALFSDIR/
471 popd
472 fi
473 sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
474 export XSL=$JHALFSDIR/${XSL}
475fi
476
477if [[ ! -d $LOGDIR ]]; then
478 mkdir -v $LOGDIR
479fi
480>$LOGDIR/$LOG
481echo "---------------${nl_}"
482
483get_book
484echo "---------------${nl_}"
485
486build_Makefile
487echo "---------------${nl_}"
488
489run_make
490
Note: See TracBrowser for help on using the repository browser.