1 | #!/bin/bash
|
---|
2 | # $Id$
|
---|
3 | set -e
|
---|
4 |
|
---|
5 |
|
---|
6 | #>>>>>>>>>>>>>>>ERROR TRAPPING >>>>>>>>>>>>>>>>>>>>
|
---|
7 | #-----------------------#
|
---|
8 | simple_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 |
|
---|
16 | see_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 | #####
|
---|
30 | set -e
|
---|
31 | trap see_ya 0
|
---|
32 | trap simple_error ERR
|
---|
33 | trap 'echo -e "\n\n${RED}INTERRUPT${OFF} trapped\n" && exit 2' 1 2 3 15 17 18 23
|
---|
34 | #>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
|
---|
35 |
|
---|
36 |
|
---|
37 | if [ ! -L $0 ] ; then
|
---|
38 | echo "${nl_}${tab_}${BOLD}${RED}This script cannot be called directly: EXITING ${OFF}${nl_}"
|
---|
39 | exit 1
|
---|
40 | fi
|
---|
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
|
---|
46 | MODULE_CONFIG=$PACKAGE_DIR/config
|
---|
47 | VERBOSITY=0
|
---|
48 |
|
---|
49 | [[ $VERBOSITY > 0 ]] && echo -n "Loading common-functions module..."
|
---|
50 | source $COMMON_DIR/common-functions
|
---|
51 | [[ $? > 0 ]] && echo " $COMMON_DIR/common-functions did not load.." && exit
|
---|
52 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
53 | #
|
---|
54 |
|
---|
55 | [[ $VERBOSITY > 0 ]] && echo -n "Loading masterscript conf..."
|
---|
56 | source $COMMON_DIR/config
|
---|
57 | [[ $? > 0 ]] && echo "$COMMON_DIR/conf did not load.." && exit
|
---|
58 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
59 | #
|
---|
60 | [[ $VERBOSITY > 0 ]] && echo -n "Loading config module <$MODULE_CONFIG>..."
|
---|
61 | source $MODULE_CONFIG
|
---|
62 | [[ $? > 0 ]] && echo "$MODULE_CONFIG did not load.." && exit 1
|
---|
63 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
64 | #
|
---|
65 | [[ $VERBOSITY > 0 ]] && echo -n "Loading code module <$MODULE>..."
|
---|
66 | source $MODULE
|
---|
67 | [[ $? > 0 ]] && echo "$MODULE did not load.." && exit 2
|
---|
68 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
69 | #
|
---|
70 | [[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
|
---|
71 |
|
---|
72 |
|
---|
73 | #===========================================================
|
---|
74 | # If the var BOOK contains something then, maybe, it points
|
---|
75 | # to a working doc.. set WC=1, else 'null'
|
---|
76 | #===========================================================
|
---|
77 | WC=${BOOK:+1}
|
---|
78 | #===========================================================
|
---|
79 |
|
---|
80 |
|
---|
81 | #*******************************************************************#
|
---|
82 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_check_version.sh>..."
|
---|
83 | source $COMMON_DIR/func_check_version.sh
|
---|
84 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
85 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
86 |
|
---|
87 | [[ $VERBOSITY > 0 ]] && echo -n "Loading function <func_validate_configs.sh>..."
|
---|
88 | source $COMMON_DIR/func_validate_configs.sh
|
---|
89 | [[ $? > 0 ]] && echo " function module did not load.." && exit 2
|
---|
90 | [[ $VERBOSITY > 0 ]] && echo "OK"
|
---|
91 | [[ $VERBOSITY > 0 ]] && echo "---------------${nl_}"
|
---|
92 |
|
---|
93 |
|
---|
94 | ###################################
|
---|
95 | ### MAIN ###
|
---|
96 | ###################################
|
---|
97 |
|
---|
98 | # Evaluate any command line switches
|
---|
99 |
|
---|
100 | while test $# -gt 0 ; do
|
---|
101 | case $1 in
|
---|
102 | # Common options for all books
|
---|
103 | --book | -B )
|
---|
104 | test $# = 1 && eval "$exit_missing_arg"
|
---|
105 | shift
|
---|
106 | case $1 in
|
---|
107 | dev* | SVN | trunk )
|
---|
108 | LFSVRS=development
|
---|
109 | ;;
|
---|
110 | *) if [[ "$PROGNAME" = "lfs" ]]; then
|
---|
111 | case $1 in
|
---|
112 | 6.1.1 )
|
---|
113 | echo "For stable 6.1.1 book, please use jhalfs-0.2."
|
---|
114 | exit 0
|
---|
115 | ;;
|
---|
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."
|
---|
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 ) usage | more && exit ;;
|
---|
148 |
|
---|
149 | --testsuites | -T )
|
---|
150 | test $# = 1 && eval "$exit_missing_arg"
|
---|
151 | shift
|
---|
152 | case $1 in
|
---|
153 | 0 | 1 | 2 | 3 )
|
---|
154 | TEST=$1
|
---|
155 | ;;
|
---|
156 | * )
|
---|
157 | echo -e "\n$1 isn't a valid testsuites level value."
|
---|
158 | echo -e "You must to use 0, 1, 2, or 3.\n"
|
---|
159 | exit 1
|
---|
160 | ;;
|
---|
161 | esac
|
---|
162 | ;;
|
---|
163 |
|
---|
164 | --version | -V )
|
---|
165 | echo "$version"
|
---|
166 | exit 0
|
---|
167 | ;;
|
---|
168 |
|
---|
169 | --working-copy | -W )
|
---|
170 | test $# = 1 && eval "$exit_missing_arg"
|
---|
171 | shift
|
---|
172 | case $PROGNAME in # Poor checks. We should find better ones.
|
---|
173 | lfs)
|
---|
174 | if [ -f $1/patches.ent ] ; then
|
---|
175 | WC=1
|
---|
176 | BOOK=$1
|
---|
177 | else
|
---|
178 | echo -e "\nLooks like $1 isn't a LFS working copy."
|
---|
179 | exit 1
|
---|
180 | fi
|
---|
181 | ;;
|
---|
182 | clfs)
|
---|
183 | if [ -f $1/patches.ent ] && [ -f $1/packages.ent ]; then
|
---|
184 | WC=1
|
---|
185 | BOOK=$1
|
---|
186 | else
|
---|
187 | echo -e "\nLooks like $1 isn't a CLFS working copy."
|
---|
188 | exit 1
|
---|
189 | fi
|
---|
190 | ;;
|
---|
191 | hlfs)
|
---|
192 | if [ -f $1/template.xml ] ; then
|
---|
193 | WC=1
|
---|
194 | BOOK=$1
|
---|
195 | else
|
---|
196 | echo -e "\nLooks like $1 isn't a HLFS working copy."
|
---|
197 | exit 1
|
---|
198 | fi
|
---|
199 | ;;
|
---|
200 | blfs)
|
---|
201 | if [ -f $1/use-unzip.xml ] ; then
|
---|
202 | WC=1
|
---|
203 | BOOK=$1
|
---|
204 | else
|
---|
205 | echo -e "\nLooks like $1 isn't a BLFS working copy."
|
---|
206 | exit 1
|
---|
207 | fi
|
---|
208 | ;;
|
---|
209 | esac
|
---|
210 | ;;
|
---|
211 |
|
---|
212 | # Common options for LFS, CLFS and HLFS
|
---|
213 | --do-ICA ) RUN_ICA=1 ;;
|
---|
214 |
|
---|
215 | --fstab | -F )
|
---|
216 | test $# = 1 && eval "$exit_missing_arg"
|
---|
217 | shift
|
---|
218 | if [ -f $1 ] ; then
|
---|
219 | FSTAB=$1
|
---|
220 | else
|
---|
221 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
222 | exit 1
|
---|
223 | fi
|
---|
224 | ;;
|
---|
225 |
|
---|
226 | --kernel-config | -K )
|
---|
227 | test $# = 1 && eval "$exit_missing_arg"
|
---|
228 | shift
|
---|
229 | if [ -f $1 ] ; then
|
---|
230 | CONFIG=$1
|
---|
231 | else
|
---|
232 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
233 | exit 1
|
---|
234 | fi
|
---|
235 | ;;
|
---|
236 |
|
---|
237 | --make | -M ) RUNMAKE=1 ;;
|
---|
238 |
|
---|
239 | --rebuild | -R ) CLEAN=1 ;;
|
---|
240 |
|
---|
241 | # CLFS options
|
---|
242 | --arch | -A )
|
---|
243 | test $# = 1 && eval "$exit_missing_arg"
|
---|
244 | shift
|
---|
245 | case $1 in
|
---|
246 | x86 )
|
---|
247 | ARCH=x86
|
---|
248 | TARGET="i686-pc-linux-gnu"
|
---|
249 | ;;
|
---|
250 | i486 )
|
---|
251 | ARCH=x86
|
---|
252 | TARGET="i486-pc-linux-gnu"
|
---|
253 | ;;
|
---|
254 | i586 )
|
---|
255 | ARCH=x86
|
---|
256 | TARGET="i586-pc-linux-gnu"
|
---|
257 | ;;
|
---|
258 | ppc )
|
---|
259 | ARCH=ppc
|
---|
260 | TARGET="powerpc-unknown-linux-gnu"
|
---|
261 | ;;
|
---|
262 | mips )
|
---|
263 | ARCH=mips
|
---|
264 | TARGET="mips-unknown-linux-gnu"
|
---|
265 | ;;
|
---|
266 | mipsel )
|
---|
267 | ARCH=mips
|
---|
268 | TARGET="mipsel-unknown-linux-gnu"
|
---|
269 | ;;
|
---|
270 | sparc )
|
---|
271 | ARCH=sparc
|
---|
272 | TARGET="sparcv9-unknown-linux-gnu"
|
---|
273 | ;;
|
---|
274 | sparcv8 )
|
---|
275 | ARCH=sparcv8
|
---|
276 | TARGET="sparc-unknown-linux-gnu"
|
---|
277 | ;;
|
---|
278 | x86_64-64 )
|
---|
279 | ARCH=x86_64-64
|
---|
280 | TARGET="x86_64-unknown-linux-gnu"
|
---|
281 | ;;
|
---|
282 | mips64-64 )
|
---|
283 | ARCH=mips64-64
|
---|
284 | TARGET="mips-unknown-linux-gnu"
|
---|
285 | ;;
|
---|
286 | mipsel64-64 )
|
---|
287 | ARCH=mips64-64
|
---|
288 | TARGET="mipsel-unknown-linux-gnu"
|
---|
289 | ;;
|
---|
290 | sparc64-64 )
|
---|
291 | ARCH=sparc64-64
|
---|
292 | TARGET="sparc64-unknown-linux-gnu"
|
---|
293 | ;;
|
---|
294 | alpha )
|
---|
295 | ARCH=alpha
|
---|
296 | TARGET="alpha-unknown-linux-gnu"
|
---|
297 | ;;
|
---|
298 | x86_64 )
|
---|
299 | ARCH=x86_64
|
---|
300 | TARGET="x86_64-unknown-linux-gnu"
|
---|
301 | TARGET32="i686-pc-linux-gnu"
|
---|
302 | ;;
|
---|
303 | mips64 )
|
---|
304 | ARCH=mips64
|
---|
305 | TARGET="mips-unknown-linux-gnu"
|
---|
306 | TARGET32="mips-unknown-linux-gnu"
|
---|
307 | ;;
|
---|
308 | mipsel64 )
|
---|
309 | ARCH=mips64
|
---|
310 | TARGET="mipsel-unknown-linux-gnu"
|
---|
311 | TARGET32="mipsel-unknown-linux-gnu"
|
---|
312 | ;;
|
---|
313 | sparc64 )
|
---|
314 | ARCH=sparc64
|
---|
315 | TARGET="sparc64-unknown-linux-gnu"
|
---|
316 | TARGET32="sparcv9-unknown-linux-gnu"
|
---|
317 | ;;
|
---|
318 | ppc64 )
|
---|
319 | ARCH=ppc64
|
---|
320 | TARGET="powerpc64-unknown-linux-gnu"
|
---|
321 | TARGET32="powerpc-unknown-linux-gnu"
|
---|
322 | ;;
|
---|
323 | * )
|
---|
324 | echo -e "\n$1 is an unknown or unsopported arch."
|
---|
325 | exit 1
|
---|
326 | ;;
|
---|
327 | esac
|
---|
328 | ;;
|
---|
329 |
|
---|
330 | --boot-config )
|
---|
331 | test $# = 1 && eval "$exit_missing_arg"
|
---|
332 | shift
|
---|
333 | if [ -f $1 ] ; then
|
---|
334 | BOOT_CONFIG=$1
|
---|
335 | else
|
---|
336 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
337 | exit 1
|
---|
338 | fi
|
---|
339 | ;;
|
---|
340 |
|
---|
341 | --method )
|
---|
342 | test $# = 1 && eval "$exit_missing_arg"
|
---|
343 | shift
|
---|
344 | case $1 in
|
---|
345 | chroot | boot )
|
---|
346 | METHOD=$1
|
---|
347 | ;;
|
---|
348 | * )
|
---|
349 | echo -e "\n$1 isn't a valid build method."
|
---|
350 | exit 1
|
---|
351 | ;;
|
---|
352 | esac
|
---|
353 | ;;
|
---|
354 |
|
---|
355 | # HLFS options
|
---|
356 | --model )
|
---|
357 | test $# = 1 && eval "$exit_missing_arg"
|
---|
358 | shift
|
---|
359 | case $1 in
|
---|
360 | glibc | uclibc )
|
---|
361 | MODEL=$1
|
---|
362 | ;;
|
---|
363 | * )
|
---|
364 | echo -e "\n$1 isn't a valid libc model."
|
---|
365 | exit 1
|
---|
366 | ;;
|
---|
367 | esac
|
---|
368 | ;;
|
---|
369 |
|
---|
370 | # BLFS options
|
---|
371 | --dependencies )
|
---|
372 | test $# = 1 && eval "$exit_missing_arg"
|
---|
373 | shift
|
---|
374 | case $1 in
|
---|
375 | 0 | 1 | 2 )
|
---|
376 | DEPEND=$1
|
---|
377 | ;;
|
---|
378 | * )
|
---|
379 | echo -e "\n$1 isn't a valid dependencies level."
|
---|
380 | exit 1
|
---|
381 | ;;
|
---|
382 | esac
|
---|
383 | ;;
|
---|
384 |
|
---|
385 | # Unknown options
|
---|
386 | * ) usage ;;
|
---|
387 | esac
|
---|
388 | shift
|
---|
389 | done
|
---|
390 |
|
---|
391 | # Find the download client to use, if not already specified.
|
---|
392 |
|
---|
393 | if [ -z $DL ] ; then
|
---|
394 | if [ `type -p wget` ] ; then
|
---|
395 | DL=wget
|
---|
396 | elif [ `type -p curl` ] ; then
|
---|
397 | DL=curl
|
---|
398 | else
|
---|
399 | eval "$no_dl_client"
|
---|
400 | fi
|
---|
401 | fi
|
---|
402 |
|
---|
403 | #===================================================
|
---|
404 | # Set the document location...
|
---|
405 | # BOOK is either defined in
|
---|
406 | # xxx.config
|
---|
407 | # comand line
|
---|
408 | # default
|
---|
409 | # If set by conf file or cmd line leave it
|
---|
410 | # alone otherwise load the default version
|
---|
411 | #===================================================
|
---|
412 | BOOK=${BOOK:=$PROGNAME-$LFSVRS}
|
---|
413 | #===================================================
|
---|
414 |
|
---|
415 |
|
---|
416 | # Check for minumum gcc and kernel versions
|
---|
417 | #check_requirements 1 # 0/1 0-do not display values.
|
---|
418 | echo
|
---|
419 | check_version "2.6.2" "`uname -r`" "KERNEL"
|
---|
420 | check_version "3.0" "$BASH_VERSION" "BASH"
|
---|
421 | check_version "3.0" "`gcc -dumpversion`" "GCC"
|
---|
422 | tarVer=`tar --version`
|
---|
423 | check_version "1.15.0" "${tarVer##* }" "TAR"
|
---|
424 | echo "---------------${nl_}"
|
---|
425 |
|
---|
426 | validate_config
|
---|
427 | echo "---------------${nl_}"
|
---|
428 |
|
---|
429 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
430 | read ANSWER
|
---|
431 | if [ x$ANSWER != "xyes" ] ; then
|
---|
432 | echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
|
---|
433 | exit 1
|
---|
434 | fi
|
---|
435 | echo "${nl_}---------------${nl_}"
|
---|
436 |
|
---|
437 | # Prevents setting "-d /" by mistake.
|
---|
438 |
|
---|
439 | if [ $BUILDDIR = / ] ; then
|
---|
440 | echo -ne "\nThe root directory can't be used to build LFS.\n\n"
|
---|
441 | exit 1
|
---|
442 | fi
|
---|
443 |
|
---|
444 | # If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
|
---|
445 | # and notify the user about that.
|
---|
446 |
|
---|
447 | if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
|
---|
448 | eval "$no_empty_builddir"
|
---|
449 | fi
|
---|
450 |
|
---|
451 | # If requested, clean the build directory
|
---|
452 | clean_builddir
|
---|
453 |
|
---|
454 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
455 | mkdir -p $JHALFSDIR
|
---|
456 | fi
|
---|
457 |
|
---|
458 | if [[ "$PWD" != "$JHALFSDIR" ]]; then
|
---|
459 | cp $COMMON_DIR/makefile-functions $JHALFSDIR/
|
---|
460 | if [[ -n "$FILES" ]]; then
|
---|
461 | # pushd/popd necessary to deal with mulitiple files
|
---|
462 | pushd $PACKAGE_DIR 1> /dev/null
|
---|
463 | cp $FILES $JHALFSDIR/
|
---|
464 | popd 1> /dev/null
|
---|
465 | fi
|
---|
466 | sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
|
---|
467 | export XSL=$JHALFSDIR/${XSL}
|
---|
468 | fi
|
---|
469 |
|
---|
470 | if [[ ! -d $LOGDIR ]]; then
|
---|
471 | mkdir $LOGDIR
|
---|
472 | fi
|
---|
473 | >$LOGDIR/$LOG
|
---|
474 |
|
---|
475 | get_book
|
---|
476 | echo "---------------${nl_}"
|
---|
477 |
|
---|
478 | build_Makefile
|
---|
479 | echo "---------------${nl_}"
|
---|
480 |
|
---|
481 | run_make
|
---|
482 |
|
---|