source: trunk/kBuild/env.sh@ 1589

Last change on this file since 1589 was 1589, checked in by bird, 17 years ago

parisc and armv5tejl uname -m response.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 17.5 KB
Line 
1#!/bin/sh
2# $Id: env.sh 1589 2008-05-01 15:34:39Z bird $
3## @file
4# Environment setup script.
5#
6
7#
8# Copyright (c) 2005-2008 knut st. osmundsen <bird-kBuild-spam@anduin.net>
9#
10# This file is part of kBuild.
11#
12# kBuild is free software; you can redistribute it and/or modify
13# it under the terms of the GNU General Public License as published by
14# the Free Software Foundation; either version 2 of the License, or
15# (at your option) any later version.
16#
17# kBuild is distributed in the hope that it will be useful,
18# but WITHOUT ANY WARRANTY; without even the implied warranty of
19# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20# GNU General Public License for more details.
21#
22# You should have received a copy of the GNU General Public License
23# along with kBuild; if not, write to the Free Software
24# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25#
26#
27#set -x
28
29#
30# Check if we're in eval mode or not.
31#
32ERR_REDIR=1
33DBG_REDIR=1
34EVAL_OPT=
35EVAL_EXPORT="export "
36DBG_OPT=
37QUIET_OPT=
38FULL_OPT=
39LEGACY_OPT=
40VAR_OPT=
41VALUE_ONLY_OPT=
42EXP_TYPE_OPT=
43while test $# -gt 0;
44do
45 case "$1" in
46 "--debug-script")
47 DBG_OPT="true"
48 ;;
49 "--no-debug-script")
50 DBG_OPT=
51 ;;
52 "--quiet")
53 QUIET_OPT="true"
54 ;;
55 "--verbose")
56 QUIET_OPT=
57 ;;
58 "--full")
59 FULL_OPT="true"
60 ;;
61 "--normal")
62 FULL_OPT=
63 ;;
64 "--legacy")
65 LEGACY_OPT="true"
66 ;;
67 "--no-legacy")
68 LEGACY_OPT=
69 ;;
70 "--eval")
71 EVAL_OPT="true"
72 ERR_REDIR=2
73 DBG_REDIR=2
74 ;;
75 "--set")
76 EVAL_OPT="true"
77 EVAL_EXPORT=""
78 ERR_REDIR=2
79 DBG_REDIR=2
80 ;;
81 "--var")
82 shift
83 VAR_OPT="${VAR_OPT} $1"
84 ERR_REDIR=2
85 DBG_REDIR=2
86 ;;
87 "--value-only")
88 VALUE_ONLY_OPT="true"
89 ;;
90 "--name-and-value")
91 VALUE_ONLY_OPT=
92 ;;
93 "--release")
94 EXP_TYPE_OPT=1
95 KBUILD_TYPE=release
96 BUILD_TYPE=
97 ;;
98 "--debug")
99 EXP_TYPE_OPT=1
100 KBUILD_TYPE=debug
101 BUILD_TYPE=
102 ;;
103 "--profile")
104 EXP_TYPE_OPT=1
105 KBUILD_TYPE=profile
106 BUILD_TYPE=
107 ;;
108
109 "--help")
110 echo "kBuild Environment Setup Script, v0.1.3"
111 echo ""
112 echo "syntax: $0 [options] [command [args]]"
113 echo " or: $0 [options] --var <varname>"
114 echo " or: $0 [options] --eval"
115 echo " or: $0 [options] --eval --var <varname>"
116 echo ""
117 echo "The first form will execute the command, or if no command is given start"
118 echo "an interactive shell."
119 echo "The second form will print the specfified variable(s)."
120 echo "The third form will print all exported variables suitable for bourne shell"
121 echo "evalutation."
122 echo "The forth form will only print the specified variable(s)."
123 echo ""
124 echo "Options:"
125 echo " --debug, --release, --profile"
126 echo " Alternative way of specifying KBUILD_TYPE."
127 echo " --debug-script, --no-debug-script"
128 echo " Controls debug output. Default: --no-debug-script"
129 echo " --quiet, --verbose"
130 echo " Controls informational output. Default: --verbose"
131 echo " --full, --normal"
132 echo " Controls the variable set. Default: --normal"
133 echo " --legacy, --no-legacy"
134 echo " Include legacy variables in result. Default: --no-legacy"
135 echo " --value-only, --name-and-value"
136 echo " Controls what the result of a --var query. Default: --name-and-value"
137 echo " --set, --export"
138 echo " Whether --eval explicitly export the variables. --set is useful for"
139 echo " getting a list of environment vars for a commandline, while --eval"
140 echo " is useful for eval `env.sh`. Default: --export"
141 echo ""
142 exit 1
143 ;;
144 *)
145 break
146 ;;
147 esac
148 shift
149done
150
151
152#
153# Deal with legacy environment variables.
154#
155if test -n "$PATH_KBUILD"; then
156 if test -n "$KBUILD_PATH" -a "$KBUILD_PATH" != "$PATH_KBUILD"; then
157 echo "$0: error: KBUILD_PATH ($KBUILD_PATH) and PATH_KBUILD ($PATH_KBUILD) disagree." 1>&${ERR_REDIR}
158 sleep 1
159 exit 1
160 fi
161 KBUILD_PATH=$PATH_KBUILD
162fi
163if test -n "$PATH_KBUILD_BIN"; then
164 if test -n "$KBUILD_BIN_PATH" -a "$KBUILD_BIN_PATH" != "$PATH_KBUILD_BIN"; then
165 echo "$0: error: KBUILD_BIN_PATH ($KBUILD_BIN_PATH) and PATH_KBUILD_BIN ($PATH_KBUILD_BIN) disagree." 1>&${ERR_REDIR}
166 sleep 1
167 exit 1
168 fi
169 KBUILD_BIN_PATH=$PATH_KBUILD_BIN
170fi
171
172if test -n "$BUILD_TYPE"; then
173 if test -n "$KBUILD_TYPE" -a "$KBUILD_TYPE" != "$BUILD_TYPE"; then
174 echo "$0: error: KBUILD_TYPE ($KBUILD_TYPE) and BUILD_TYPE ($BUILD_TYPE) disagree." 1>&${ERR_REDIR}
175 sleep 1
176 exit 1
177 fi
178 KBUILD_TYPE=$BUILD_TYPE
179fi
180
181if test -n "$BUILD_PLATFORM"; then
182 if test -n "$KBUILD_HOST" -a "$KBUILD_HOST" != "$BUILD_PLATFORM"; then
183 echo "$0: error: KBUILD_HOST ($KBUILD_HOST) and BUILD_PLATFORM ($BUILD_PLATFORM) disagree." 1>&${ERR_REDIR}
184 sleep 1
185 exit 1
186 fi
187 KBUILD_HOST=$BUILD_PLATFORM
188fi
189if test -n "$BUILD_PLATFORM_ARCH"; then
190 if test -n "$KBUILD_HOST_ARCH" -a "$KBUILD_HOST_ARCH" != "$BUILD_PLATFORM_ARCH"; then
191 echo "$0: error: KBUILD_HOST_ARCH ($KBUILD_HOST_ARCH) and BUILD_PLATFORM_ARCH ($BUILD_PLATFORM_ARCH) disagree." 1>&${ERR_REDIR}
192 sleep 1
193 exit 1
194 fi
195 KBUILD_HOST_ARCH=$BUILD_PLATFORM_ARCH
196fi
197if test -n "$BUILD_PLATFORM_CPU"; then
198 if test -n "$KBUILD_HOST_CPU" -a "$KBUILD_HOST_CPU" != "$BUILD_PLATFORM_CPU"; then
199 echo "$0: error: KBUILD_HOST_CPU ($KBUILD_HOST_CPU) and BUILD_PLATFORM_CPU ($BUILD_PLATFORM_CPU) disagree." 1>&${ERR_REDIR}
200 sleep 1
201 exit 1
202 fi
203 KBUILD_HOST_CPU=$BUILD_PLATFORM_CPU
204fi
205
206if test -n "$BUILD_TARGET"; then
207 if test -n "$KBUILD_TARGET" -a "$KBUILD_TARGET" != "$BUILD_TARGET"; then
208 echo "$0: error: KBUILD_TARGET ($KBUILD_TARGET) and BUILD_TARGET ($BUILD_TARGET) disagree." 1>&${ERR_REDIR}
209 sleep 1
210 exit 1
211 fi
212 KBUILD_TARGET=$BUILD_TARGET
213fi
214if test -n "$BUILD_TARGET_ARCH"; then
215 if test -n "$KBUILD_TARGET_ARCH" -a "$KBUILD_TARGET_ARCH" != "$BUILD_TARGET_ARCH"; then
216 echo "$0: error: KBUILD_TARGET_ARCH ($KBUILD_TARGET_ARCH) and BUILD_TARGET_ARCH ($BUILD_TARGET_ARCH) disagree." 1>&${ERR_REDIR}
217 sleep 1
218 exit 1
219 fi
220 KBUILD_TARGET_ARCH=$BUILD_TARGET_ARCH
221fi
222if test -n "$BUILD_TARGET_CPU"; then
223 if test -n "$KBUILD_TARGET_CPU" -a "$KBUILD_TARGET_CPU" != "$BUILD_TARGET_CPU"; then
224 echo "$0: error: KBUILD_TARGET_CPU ($KBUILD_TARGET_CPU) and BUILD_TARGET_CPU ($BUILD_TARGET_CPU) disagree." 1>&${ERR_REDIR}
225 sleep 1
226 exit 1
227 fi
228 KBUILD_TARGET_CPU=$BUILD_TARGET_CPU
229fi
230
231
232#
233# Set default build type.
234#
235if test -z "$KBUILD_TYPE"; then
236 KBUILD_TYPE=release
237fi
238test -n "$DBG_OPT" && echo "dbg: KBUILD_TYPE=$KBUILD_TYPE" 1>&${DBG_REDIR}
239
240#
241# Determin the host platform.
242#
243# The CPU isn't important, only the other two are. But, since the cpu,
244# arch and platform (and build type) share a common key space, try make
245# sure any new additions are unique. (See header.kmk, KBUILD_OSES/ARCHES.)
246#
247if test -z "$KBUILD_HOST"; then
248 KBUILD_HOST=`uname`
249 case "$KBUILD_HOST" in
250 linux|Linux|GNU/Linux|LINUX)
251 KBUILD_HOST=linux
252 ;;
253
254 os2|OS/2|OS2)
255 KBUILD_HOST=os2
256 ;;
257
258 freebsd|FreeBSD|FREEBSD)
259 KBUILD_HOST=freebsd
260 ;;
261
262 openbsd|OpenBSD|OPENBSD)
263 KBUILD_HOST=openbsd
264 ;;
265
266 netbsd|NetBSD|NETBSD)
267 KBUILD_HOST=netbsd
268 ;;
269
270 Darwin|darwin)
271 KBUILD_HOST=darwin
272 ;;
273
274 SunOS)
275 KBUILD_HOST=solaris
276 ;;
277
278 WindowsNT|CYGWIN_NT-*)
279 KBUILD_HOST=win
280 ;;
281
282 *)
283 echo "$0: unknown os $KBUILD_HOST" 1>&${ERR_REDIR}
284 sleep 1
285 exit 1
286 ;;
287 esac
288fi
289test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST=$KBUILD_HOST" 1>&${DBG_REDIR}
290
291if test -z "$KBUILD_HOST_ARCH"; then
292 # Try deduce it from the cpu if given.
293 if test -n "$KBUILD_HOST_CPU"; then
294 case "$KBUILD_HOST_CPU" in
295 i[3456789]86)
296 KBUILD_HOST_ARCH='x86'
297 ;;
298 k8|k8l|k9|k10)
299 KBUILD_HOST_ARCH='amd64'
300 ;;
301 esac
302 fi
303fi
304if test -z "$KBUILD_HOST_ARCH"; then
305 # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
306 if test "$KBUILD_HOST" = "solaris"; then
307 KBUILD_HOST_ARCH=`isainfo | cut -f 1 -d ' '`
308
309 else
310 KBUILD_HOST_ARCH=`uname -m`
311 fi
312 case "$KBUILD_HOST_ARCH" in
313 x86_64|AMD64|amd64|k8|k8l|k9|k10)
314 KBUILD_HOST_ARCH='amd64'
315 ;;
316 x86|i86pc|ia32|i[3456789]86)
317 KBUILD_HOST_ARCH='x86'
318 ;;
319 sparc32|sparc)
320 KBUILD_HOST_ARCH='sparc32'
321 ;;
322 sparc64)
323 KBUILD_HOST_ARCH='sparc64'
324 ;;
325 s390)
326 KBUILD_HOST_ARCH='s390'
327 ;;
328 s390x)
329 KBUILD_HOST_ARCH='s390x'
330 ;;
331 ppc32|ppc|powerpc)
332 KBUILD_HOST_ARCH='ppc32'
333 ;;
334 ppc64|powerpc64)
335 KBUILD_HOST_ARCH='ppc64'
336 ;;
337 mips32|mips)
338 KBUILD_HOST_ARCH='mips32'
339 ;;
340 mips64)
341 KBUILD_HOST_ARCH='mips64'
342 ;;
343 ia64)
344 KBUILD_HOST_ARCH='ia64'
345 ;;
346 hppa32|parisc32|parisc)
347 KBUILD_HOST_ARCH='hppa32'
348 ;;
349 hppa64|parisc64)
350 KBUILD_HOST_ARCH='hppa64'
351 ;;
352 arm|armv4l|armv5tel|armv5tejl)
353 KBUILD_HOST_ARCH='arm'
354 ;;
355 alpha)
356 KBUILD_HOST_ARCH='alpha'
357 ;;
358
359 *) echo "$0: unknown cpu/arch - $KBUILD_HOST_ARCH" 1>&${ERR_REDIR}
360 sleep 1
361 exit 1
362 ;;
363 esac
364
365fi
366test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_ARCH=$KBUILD_HOST_ARCH" 1>&${DBG_REDIR}
367
368if test -z "$KBUILD_HOST_CPU"; then
369 KBUILD_HOST_CPU="blend"
370fi
371test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_CPU=$KBUILD_HOST_CPU" 1>&${DBG_REDIR}
372
373#
374# The target platform.
375# Defaults to the host when not specified.
376#
377if test -z "$KBUILD_TARGET"; then
378 KBUILD_TARGET="$KBUILD_HOST"
379fi
380test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET=$KBUILD_TARGET" 1>&${DBG_REDIR}
381
382if test -z "$KBUILD_TARGET_ARCH"; then
383 KBUILD_TARGET_ARCH="$KBUILD_HOST_ARCH"
384fi
385test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH" 1>&${DBG_REDIR}
386
387if test -z "$KBUILD_TARGET_CPU"; then
388 if test "$KBUILD_TARGET_ARCH" = "$KBUILD_HOST_ARCH"; then
389 KBUILD_TARGET_CPU="$KBUILD_HOST_CPU"
390 else
391 KBUILD_TARGET_CPU="blend"
392 fi
393fi
394test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_CPU=$KBUILD_TARGET_CPU" 1>&${DBG_REDIR}
395
396#
397# Determin executable extension and path separator.
398#
399_SUFF_EXE=
400_PATH_SEP=":"
401case "$KBUILD_HOST" in
402 os2|win|nt)
403 _SUFF_EXE=".exe"
404 _PATH_SEP=";"
405 ;;
406esac
407
408#
409# Determin KBUILD_PATH from the script location and calc KBUILD_BIN_PATH from there.
410#
411if test -z "$KBUILD_PATH"; then
412 KBUILD_PATH=`dirname "$0"`
413 KBUILD_PATH=`cd "$KBUILD_PATH" ; /bin/pwd`
414fi
415if test ! -f "$KBUILD_PATH/footer.kmk" -o ! -f "$KBUILD_PATH/header.kmk" -o ! -f "$KBUILD_PATH/rules.kmk"; then
416 echo "$0: error: KBUILD_PATH ($KBUILD_PATH) is not pointing to a popluated kBuild directory." 1>&${ERR_REDIR}
417 sleep 1
418 exit 1
419fi
420test -n "$DBG_OPT" && echo "dbg: KBUILD_PATH=$KBUILD_PATH" 1>&${DBG_REDIR}
421
422if test -z "$KBUILD_BIN_PATH"; then
423 KBUILD_BIN_PATH="${KBUILD_PATH}/bin/${KBUILD_HOST}.${KBUILD_HOST_ARCH}"
424fi
425test -n "$DBG_OPT" && echo "dbg: KBUILD_BIN_PATH=${KBUILD_BIN_PATH}" 1>&${DBG_REDIR}
426
427#
428# Add the bin/x.y/ directory to the PATH.
429# NOTE! Once bootstrapped this is the only thing that is actually necessary.
430#
431PATH="${KBUILD_BIN_PATH}${_PATH_SEP}$PATH"
432test -n "$DBG_OPT" && echo "dbg: PATH=$PATH" 1>&${DBG_REDIR}
433
434#
435# Sanity and x bits.
436#
437if test ! -d "${KBUILD_BIN_PATH}/"; then
438 echo "$0: warning: The bin directory for this platform doesn't exist. (${KBUILD_BIN_PATH}/)" 1>&${ERR_REDIR}
439else
440 for prog in kmk kDepPre kDepIDB kmk_append kmk_ash kmk_cat kmk_cp kmk_echo kmk_install kmk_ln kmk_mkdir kmk_mv kmk_rm kmk_rmdir kmk_sed;
441 do
442 chmod a+x ${KBUILD_BIN_PATH}/${prog} > /dev/null 2>&1
443 if test ! -f "${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE}"; then
444 echo "$0: warning: The ${prog} program doesn't exist for this platform. (${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE})" 1>&${ERR_REDIR}
445 fi
446 done
447fi
448
449#
450# The environment is in place, now take the requested action.
451#
452MY_RC=0
453if test -n "${VAR_OPT}"; then
454 # Echo variable values or variable export statements.
455 for var in ${VAR_OPT};
456 do
457 val=
458 case "$var" in
459 PATH)
460 val=$PATH
461 ;;
462 KBUILD_PATH)
463 val=$KBUILD_PATH
464 ;;
465 KBUILD_BIN_PATH)
466 val=$KBUILD_BIN_PATH
467 ;;
468 KBUILD_HOST)
469 val=$KBUILD_HOST
470 ;;
471 KBUILD_HOST_ARCH)
472 val=$KBUILD_HOST_ARCH
473 ;;
474 KBUILD_HOST_CPU)
475 val=$KBUILD_HOST_CPU
476 ;;
477 KBUILD_TARGET)
478 val=$KBUILD_TARGET
479 ;;
480 KBUILD_TARGET_ARCH)
481 val=$KBUILD_TARGET_ARCH
482 ;;
483 KBUILD_TARGET_CPU)
484 val=$KBUILD_TARGET_CPU
485 ;;
486 KBUILD_TYPE)
487 val=$KBUILD_TYPE
488 ;;
489 *)
490 echo "$0: error: Unknown variable $var specified in --var request." 1>&${ERR_REDIR}
491 sleep 1
492 exit 1
493 ;;
494 esac
495
496 if test -n "$EVAL_OPT"; then
497 echo "${EVAL_EXPORT} $var=$val"
498 else
499 if test -n "$VALUE_ONLY_OPT"; then
500 echo "$val"
501 else
502 echo "$var=$val"
503 fi
504 fi
505 done
506else
507 if test -n "$EVAL_OPT"; then
508 # Echo statements for the shell to evaluate.
509 test -n "$DBG_OPT" && echo "dbg: echoing exported variables" 1>&${DBG_REDIR}
510 echo "${EVAL_EXPORT} PATH=${PATH}"
511 test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && echo "${EVAL_EXPORT} KBUILD_TYPE=${KBUILD_TYPE}"
512 if test -n "${FULL_OPT}"; then
513 echo "${EVAL_EXPORT} KBUILD_PATH=${KBUILD_PATH}"
514 echo "${EVAL_EXPORT} KBUILD_HOST=${KBUILD_HOST}"
515 echo "${EVAL_EXPORT} KBUILD_HOST_ARCH=${KBUILD_HOST_ARCH}"
516 echo "${EVAL_EXPORT} KBUILD_HOST_CPU=${KBUILD_HOST_CPU}"
517 echo "${EVAL_EXPORT} KBUILD_TARGET=${KBUILD_TARGET}"
518 echo "${EVAL_EXPORT} KBUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}"
519 echo "${EVAL_EXPORT} KBUILD_TARGET_CPU=${KBUILD_TARGET_CPU}"
520
521 if test -n "${LEGACY_OPT}"; then
522 echo "${EVAL_EXPORT} PATH_KBUILD=${KBUILD_PATH}"
523 echo "${EVAL_EXPORT} BUILD_TYPE=${KBUILD_TYPE}"
524 echo "${EVAL_EXPORT} BUILD_PLATFORM=${KBUILD_HOST}"
525 echo "${EVAL_EXPORT} BUILD_PLATFORM_ARCH=${KBUILD_HOST_ARCH}"
526 echo "${EVAL_EXPORT} BUILD_PLATFORM_CPU=${KBUILD_HOST_CPU}"
527 echo "${EVAL_EXPORT} BUILD_TARGET=${KBUILD_TARGET}"
528 echo "${EVAL_EXPORT} BUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}"
529 echo "${EVAL_EXPORT} BUILD_TARGET_CPU=${KBUILD_TARGET_CPU}"
530 fi
531 fi
532 else
533 # Export variables.
534 export PATH
535 test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && export KBUILD_TYPE
536 if test -n "${FULL_OPT}"; then
537 export KBUILD_PATH
538 export KBUILD_HOST
539 export KBUILD_HOST_ARCH
540 export KBUILD_HOST_CPU
541 export KBUILD_TARGET
542 export KBUILD_TARGET_ARCH
543 export KBUILD_TARGET_CPU
544
545 if test -n "${LEGACY_OPT}"; then
546 export PATH_KBUILD=$KBUILD_PATH
547 export BUILD_TYPE=$KBUILD_TYPE
548 export BUILD_PLATFORM=$KBUILD_HOST
549 export BUILD_PLATFORM_ARCH=$KBUILD_HOST_ARCH
550 export BUILD_PLATFORM_CPU=$KBUILD_HOST_CPU
551 export BUILD_TARGET=$KBUILD_TARGET
552 export BUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH
553 export BUILD_TARGET_CPU=$KBUILD_TARGET_CPU
554 fi
555 fi
556
557 # Execute command or spawn shell.
558 if test $# -eq 0; then
559 test -z "${QUIET_OPT}" && echo "$0: info: Spawning work shell..." 1>&${ERR_REDIR}
560 if test "$TERM" != 'dumb' -a -n "$BASH"; then
561 export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
562 fi
563 $SHELL -i
564 MY_RC=$?
565 else
566 test -z "${QUIET_OPT}" && echo "$0: info: Executing command: $*" 1>&${ERR_REDIR}
567 $*
568 MY_RC=$?
569 test -z "${QUIET_OPT}" -a "$MY_RC" -ne 0 && echo "$0: info: rc=$MY_RC: $*" 1>&${ERR_REDIR}
570 fi
571 fi
572fi
573test -n "$DBG_OPT" && echo "dbg: finished (rc=$MY_RC)" 1>&${DBG_REDIR}
574exit $MY_RC
575
Note: See TracBrowser for help on using the repository browser.