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${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 | --fstab | -F )
|
---|
214 | test $# = 1 && eval "$exit_missing_arg"
|
---|
215 | shift
|
---|
216 | if [ -f $1 ] ; then
|
---|
217 | FSTAB=$1
|
---|
218 | else
|
---|
219 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
220 | exit 1
|
---|
221 | fi
|
---|
222 | ;;
|
---|
223 |
|
---|
224 | --kernel-config | -K )
|
---|
225 | test $# = 1 && eval "$exit_missing_arg"
|
---|
226 | shift
|
---|
227 | if [ -f $1 ] ; then
|
---|
228 | CONFIG=$1
|
---|
229 | else
|
---|
230 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
231 | exit 1
|
---|
232 | fi
|
---|
233 | ;;
|
---|
234 |
|
---|
235 | --make | -M ) RUNMAKE=1 ;;
|
---|
236 |
|
---|
237 | --rebuild | -R ) CLEAN=1 ;;
|
---|
238 |
|
---|
239 | # CLFS options
|
---|
240 | --arch | -A )
|
---|
241 | test $# = 1 && eval "$exit_missing_arg"
|
---|
242 | shift
|
---|
243 | case $1 in
|
---|
244 | x86 )
|
---|
245 | ARCH=x86
|
---|
246 | TARGET="i686-pc-linux-gnu"
|
---|
247 | ;;
|
---|
248 | i486 )
|
---|
249 | ARCH=x86
|
---|
250 | TARGET="i486-pc-linux-gnu"
|
---|
251 | ;;
|
---|
252 | i586 )
|
---|
253 | ARCH=x86
|
---|
254 | TARGET="i586-pc-linux-gnu"
|
---|
255 | ;;
|
---|
256 | ppc )
|
---|
257 | ARCH=ppc
|
---|
258 | TARGET="powerpc-unknown-linux-gnu"
|
---|
259 | ;;
|
---|
260 | mips )
|
---|
261 | ARCH=mips
|
---|
262 | TARGET="mips-unknown-linux-gnu"
|
---|
263 | ;;
|
---|
264 | mipsel )
|
---|
265 | ARCH=mips
|
---|
266 | TARGET="mipsel-unknown-linux-gnu"
|
---|
267 | ;;
|
---|
268 | sparc )
|
---|
269 | ARCH=sparc
|
---|
270 | TARGET="sparcv9-unknown-linux-gnu"
|
---|
271 | ;;
|
---|
272 | sparcv8 )
|
---|
273 | ARCH=sparcv8
|
---|
274 | TARGET="sparc-unknown-linux-gnu"
|
---|
275 | ;;
|
---|
276 | x86_64-64 )
|
---|
277 | ARCH=x86_64-64
|
---|
278 | TARGET="x86_64-unknown-linux-gnu"
|
---|
279 | ;;
|
---|
280 | mips64-64 )
|
---|
281 | ARCH=mips64-64
|
---|
282 | TARGET="mips-unknown-linux-gnu"
|
---|
283 | ;;
|
---|
284 | mipsel64-64 )
|
---|
285 | ARCH=mips64-64
|
---|
286 | TARGET="mipsel-unknown-linux-gnu"
|
---|
287 | ;;
|
---|
288 | sparc64-64 )
|
---|
289 | ARCH=sparc64-64
|
---|
290 | TARGET="sparc64-unknown-linux-gnu"
|
---|
291 | ;;
|
---|
292 | alpha )
|
---|
293 | ARCH=alpha
|
---|
294 | TARGET="alpha-unknown-linux-gnu"
|
---|
295 | ;;
|
---|
296 | x86_64 )
|
---|
297 | ARCH=x86_64
|
---|
298 | TARGET="x86_64-unknown-linux-gnu"
|
---|
299 | TARGET32="i686-pc-linux-gnu"
|
---|
300 | ;;
|
---|
301 | mips64 )
|
---|
302 | ARCH=mips64
|
---|
303 | TARGET="mips-unknown-linux-gnu"
|
---|
304 | TARGET32="mips-unknown-linux-gnu"
|
---|
305 | ;;
|
---|
306 | mipsel64 )
|
---|
307 | ARCH=mips64
|
---|
308 | TARGET="mipsel-unknown-linux-gnu"
|
---|
309 | TARGET32="mipsel-unknown-linux-gnu"
|
---|
310 | ;;
|
---|
311 | sparc64 )
|
---|
312 | ARCH=sparc64
|
---|
313 | TARGET="sparc64-unknown-linux-gnu"
|
---|
314 | TARGET32="sparcv9-unknown-linux-gnu"
|
---|
315 | ;;
|
---|
316 | ppc64 )
|
---|
317 | ARCH=ppc64
|
---|
318 | TARGET="powerpc64-unknown-linux-gnu"
|
---|
319 | TARGET32="powerpc-unknown-linux-gnu"
|
---|
320 | ;;
|
---|
321 | * )
|
---|
322 | echo -e "\n$1 is an unknown or unsopported arch."
|
---|
323 | exit 1
|
---|
324 | ;;
|
---|
325 | esac
|
---|
326 | ;;
|
---|
327 |
|
---|
328 | --boot-config )
|
---|
329 | test $# = 1 && eval "$exit_missing_arg"
|
---|
330 | shift
|
---|
331 | if [ -f $1 ] ; then
|
---|
332 | BOOT_CONFIG=$1
|
---|
333 | else
|
---|
334 | echo -e "\nFile $1 not found. Verify your command line.\n"
|
---|
335 | exit 1
|
---|
336 | fi
|
---|
337 | ;;
|
---|
338 |
|
---|
339 | --method )
|
---|
340 | test $# = 1 && eval "$exit_missing_arg"
|
---|
341 | shift
|
---|
342 | case $1 in
|
---|
343 | chroot | boot )
|
---|
344 | METHOD=$1
|
---|
345 | ;;
|
---|
346 | * )
|
---|
347 | echo -e "\n$1 isn't a valid build method."
|
---|
348 | exit 1
|
---|
349 | ;;
|
---|
350 | esac
|
---|
351 | ;;
|
---|
352 |
|
---|
353 | # HLFS options
|
---|
354 | --model )
|
---|
355 | test $# = 1 && eval "$exit_missing_arg"
|
---|
356 | shift
|
---|
357 | case $1 in
|
---|
358 | glibc | uclibc )
|
---|
359 | MODEL=$1
|
---|
360 | ;;
|
---|
361 | * )
|
---|
362 | echo -e "\n$1 isn't a valid libc model."
|
---|
363 | exit 1
|
---|
364 | ;;
|
---|
365 | esac
|
---|
366 | ;;
|
---|
367 |
|
---|
368 | # BLFS options
|
---|
369 | --dependencies )
|
---|
370 | test $# = 1 && eval "$exit_missing_arg"
|
---|
371 | shift
|
---|
372 | case $1 in
|
---|
373 | 0 | 1 | 2 )
|
---|
374 | DEPEND=$1
|
---|
375 | ;;
|
---|
376 | * )
|
---|
377 | echo -e "\n$1 isn't a valid dependencies level."
|
---|
378 | exit 1
|
---|
379 | ;;
|
---|
380 | esac
|
---|
381 | ;;
|
---|
382 |
|
---|
383 | # Unknown options
|
---|
384 | * ) usage ;;
|
---|
385 | esac
|
---|
386 | shift
|
---|
387 | done
|
---|
388 |
|
---|
389 | # Find the download client to use, if not already specified.
|
---|
390 |
|
---|
391 | if [ -z $DL ] ; then
|
---|
392 | if [ `type -p wget` ] ; then
|
---|
393 | DL=wget
|
---|
394 | elif [ `type -p curl` ] ; then
|
---|
395 | DL=curl
|
---|
396 | else
|
---|
397 | eval "$no_dl_client"
|
---|
398 | fi
|
---|
399 | fi
|
---|
400 |
|
---|
401 | #===================================================
|
---|
402 | # Set the document location...
|
---|
403 | # BOOK is either defined in
|
---|
404 | # xxx.config
|
---|
405 | # comand line
|
---|
406 | # default
|
---|
407 | # If set by conf file or cmd line leave it
|
---|
408 | # alone otherwise load the default version
|
---|
409 | #===================================================
|
---|
410 | BOOK=${BOOK:=$PROGNAME-$LFSVRS}
|
---|
411 | #===================================================
|
---|
412 |
|
---|
413 |
|
---|
414 | # Check for minumum gcc and kernel versions
|
---|
415 | #check_requirements 1 # 0/1 0-do not display values.
|
---|
416 | echo
|
---|
417 | check_version "2.6.2" "`uname -r`" "KERNEL"
|
---|
418 | check_version "3.0" "$BASH_VERSION" "BASH"
|
---|
419 | check_version "3.0" "`gcc -dumpversion`" "GCC"
|
---|
420 | tarVer=`tar --version`
|
---|
421 | check_version "1.15.0" "${tarVer##* }" "TAR"
|
---|
422 | echo "---------------${nl_}"
|
---|
423 |
|
---|
424 | validate_config
|
---|
425 | echo "---------------${nl_}"
|
---|
426 |
|
---|
427 | echo -n "Are you happy with these settings? yes/no (no): "
|
---|
428 | read ANSWER
|
---|
429 | if [ x$ANSWER != "xyes" ] ; then
|
---|
430 | echo "${nl_}Fix the configuration options and rerun the script.${nl_}"
|
---|
431 | exit 1
|
---|
432 | fi
|
---|
433 | echo "${nl_}---------------${nl_}"
|
---|
434 |
|
---|
435 | # Prevents setting "-d /" by mistake.
|
---|
436 |
|
---|
437 | if [ $BUILDDIR = / ] ; then
|
---|
438 | echo -ne "\nThe root directory can't be used to build LFS.\n\n"
|
---|
439 | exit 1
|
---|
440 | fi
|
---|
441 |
|
---|
442 | # If $BUILDDIR has subdirectories like tools/ or bin/, stop the run
|
---|
443 | # and notify the user about that.
|
---|
444 |
|
---|
445 | if [ -d $BUILDDIR/tools -o -d $BUILDDIR/bin ] && [ -z $CLEAN ] ; then
|
---|
446 | eval "$no_empty_builddir"
|
---|
447 | fi
|
---|
448 |
|
---|
449 | # If requested, clean the build directory
|
---|
450 | clean_builddir
|
---|
451 |
|
---|
452 | if [[ ! -d $JHALFSDIR ]]; then
|
---|
453 | mkdir -p $JHALFSDIR
|
---|
454 | fi
|
---|
455 |
|
---|
456 | if [[ "$PWD" != "$JHALFSDIR" ]]; then
|
---|
457 | cp $COMMON_DIR/makefile-functions $JHALFSDIR/
|
---|
458 | if [[ -n "$FILES" ]]; then
|
---|
459 | # pushd/popd necessary to deal with mulitiple files
|
---|
460 | pushd $PACKAGE_DIR 1> /dev/null
|
---|
461 | cp $FILES $JHALFSDIR/
|
---|
462 | popd 1> /dev/null
|
---|
463 | fi
|
---|
464 | sed 's,FAKEDIR,'$BOOK',' $PACKAGE_DIR/$XSL > $JHALFSDIR/${XSL}
|
---|
465 | export XSL=$JHALFSDIR/${XSL}
|
---|
466 | fi
|
---|
467 |
|
---|
468 | if [[ ! -d $LOGDIR ]]; then
|
---|
469 | mkdir $LOGDIR
|
---|
470 | fi
|
---|
471 | >$LOGDIR/$LOG
|
---|
472 |
|
---|
473 | get_book
|
---|
474 | echo "---------------${nl_}"
|
---|
475 |
|
---|
476 | build_Makefile
|
---|
477 | echo "---------------${nl_}"
|
---|
478 |
|
---|
479 | run_make
|
---|
480 |
|
---|