4 # Environment setup script.
8 # Copyright (c) 2005-2008 knut st. osmundsen <bird-kBuild-spam@anduin.net>
10 # This file is part of kBuild.
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.
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.
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
30 # Check if we're in eval mode or not.
83 VAR_OPT
="${VAR_OPT} $1"
110 echo "kBuild Environment Setup Script, v0.1.3"
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>"
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"
122 echo "The forth form will only print the specified variable(s)."
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"
153 # Deal with legacy environment variables.
155 if 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}
161 KBUILD_PATH
=$PATH_KBUILD
163 if 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}
169 KBUILD_BIN_PATH
=$PATH_KBUILD_BIN
172 if 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}
178 KBUILD_TYPE
=$BUILD_TYPE
181 if 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}
187 KBUILD_HOST
=$BUILD_PLATFORM
189 if 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}
195 KBUILD_HOST_ARCH
=$BUILD_PLATFORM_ARCH
197 if 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}
203 KBUILD_HOST_CPU
=$BUILD_PLATFORM_CPU
206 if 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}
212 KBUILD_TARGET
=$BUILD_TARGET
214 if 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}
220 KBUILD_TARGET_ARCH
=$BUILD_TARGET_ARCH
222 if 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}
228 KBUILD_TARGET_CPU
=$BUILD_TARGET_CPU
233 # Set default build type.
235 if test -z "$KBUILD_TYPE"; then
238 test -n "$DBG_OPT" && echo "dbg: KBUILD_TYPE=$KBUILD_TYPE" 1>&${DBG_REDIR}
241 # Determin the host platform.
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.)
247 if test -z "$KBUILD_HOST"; then
249 case "$KBUILD_HOST" in
255 KBUILD_HOST
=dragonfly
258 freebsd|FreeBSD|FREEBSD
)
262 linux|Linux|GNU
/Linux|LINUX
)
266 netbsd|NetBSD|NETBSD
)
270 openbsd|OpenBSD|OPENBSD
)
282 WindowsNT|CYGWIN_NT-
*)
287 echo "$0: unknown os $KBUILD_HOST" 1>&${ERR_REDIR}
293 test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST=$KBUILD_HOST" 1>&${DBG_REDIR}
295 if test -z "$KBUILD_HOST_ARCH"; then
296 # Try deduce it from the cpu if given.
297 if test -n "$KBUILD_HOST_CPU"; then
298 case "$KBUILD_HOST_CPU" in
300 KBUILD_HOST_ARCH
='x86'
303 KBUILD_HOST_ARCH
='amd64'
308 if test -z "$KBUILD_HOST_ARCH"; then
309 # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
310 if test "$KBUILD_HOST" = "solaris"; then
311 KBUILD_HOST_ARCH
=`isainfo | cut -f 1 -d ' '`
314 KBUILD_HOST_ARCH
=`uname -m`
316 case "$KBUILD_HOST_ARCH" in
317 x86_64|AMD64|amd64|k8|k8l|k9|k10
)
318 KBUILD_HOST_ARCH
='amd64'
320 x86|i86pc|ia32|i
[3456789]86)
321 KBUILD_HOST_ARCH
='x86'
324 KBUILD_HOST_ARCH
='sparc32'
327 KBUILD_HOST_ARCH
='sparc64'
330 KBUILD_HOST_ARCH
='s390'
333 KBUILD_HOST_ARCH
='s390x'
336 KBUILD_HOST_ARCH
='ppc32'
339 KBUILD_HOST_ARCH
='ppc64'
342 KBUILD_HOST_ARCH
='mips32'
345 KBUILD_HOST_ARCH
='mips64'
348 KBUILD_HOST_ARCH
='ia64'
350 hppa32|parisc32|parisc
)
351 KBUILD_HOST_ARCH
='hppa32'
354 KBUILD_HOST_ARCH
='hppa64'
356 arm|armv4l|armv5tel|armv5tejl
)
357 KBUILD_HOST_ARCH
='arm'
360 KBUILD_HOST_ARCH
='alpha'
363 *) echo "$0: unknown cpu/arch - $KBUILD_HOST_ARCH" 1>&${ERR_REDIR}
370 test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_ARCH=$KBUILD_HOST_ARCH" 1>&${DBG_REDIR}
372 if test -z "$KBUILD_HOST_CPU"; then
373 KBUILD_HOST_CPU
="blend"
375 test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_CPU=$KBUILD_HOST_CPU" 1>&${DBG_REDIR}
378 # The target platform.
379 # Defaults to the host when not specified.
381 if test -z "$KBUILD_TARGET"; then
382 KBUILD_TARGET
="$KBUILD_HOST"
384 test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET=$KBUILD_TARGET" 1>&${DBG_REDIR}
386 if test -z "$KBUILD_TARGET_ARCH"; then
387 KBUILD_TARGET_ARCH
="$KBUILD_HOST_ARCH"
389 test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH" 1>&${DBG_REDIR}
391 if test -z "$KBUILD_TARGET_CPU"; then
392 if test "$KBUILD_TARGET_ARCH" = "$KBUILD_HOST_ARCH"; then
393 KBUILD_TARGET_CPU
="$KBUILD_HOST_CPU"
395 KBUILD_TARGET_CPU
="blend"
398 test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_CPU=$KBUILD_TARGET_CPU" 1>&${DBG_REDIR}
401 # Determin executable extension and path separator.
405 case "$KBUILD_HOST" in
413 # Determin KBUILD_PATH from the script location and calc KBUILD_BIN_PATH from there.
415 if test -z "$KBUILD_PATH"; then
416 KBUILD_PATH
=`dirname "$0"`
417 KBUILD_PATH
=`cd "$KBUILD_PATH" ; /bin/pwd`
419 if test ! -f "$KBUILD_PATH/footer.kmk" -o ! -f "$KBUILD_PATH/header.kmk" -o ! -f "$KBUILD_PATH/rules.kmk"; then
420 echo "$0: error: KBUILD_PATH ($KBUILD_PATH) is not pointing to a popluated kBuild directory." 1>&${ERR_REDIR}
424 test -n "$DBG_OPT" && echo "dbg: KBUILD_PATH=$KBUILD_PATH" 1>&${DBG_REDIR}
426 if test -z "$KBUILD_BIN_PATH"; then
427 KBUILD_BIN_PATH
="${KBUILD_PATH}/bin/${KBUILD_HOST}.${KBUILD_HOST_ARCH}"
429 test -n "$DBG_OPT" && echo "dbg: KBUILD_BIN_PATH=${KBUILD_BIN_PATH}" 1>&${DBG_REDIR}
432 # Add the bin/x.y/ directory to the PATH.
433 # NOTE! Once bootstrapped this is the only thing that is actually necessary.
435 PATH
="${KBUILD_BIN_PATH}${_PATH_SEP}$PATH"
436 test -n "$DBG_OPT" && echo "dbg: PATH=$PATH" 1>&${DBG_REDIR}
441 if test ! -d "${KBUILD_BIN_PATH}/"; then
442 echo "$0: warning: The bin directory for this platform doesn't exist. (${KBUILD_BIN_PATH}/)" 1>&${ERR_REDIR}
444 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
;
446 chmod a
+x
${KBUILD_BIN_PATH}/${prog} > /dev
/null
2>&1
447 if test ! -f "${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE}"; then
448 echo "$0: warning: The ${prog} program doesn't exist for this platform. (${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE})" 1>&${ERR_REDIR}
454 # The environment is in place, now take the requested action.
457 if test -n "${VAR_OPT}"; then
458 # Echo variable values or variable export statements.
459 for var in ${VAR_OPT};
476 val=$KBUILD_HOST_ARCH
485 val=$KBUILD_TARGET_ARCH
488 val=$KBUILD_TARGET_CPU
494 echo "$0: error
: Unknown variable
$var specified
in --var request.
" 1>&${ERR_REDIR}
500 if test -n "$EVAL_OPT"; then
501 echo "${EVAL_EXPORT} $var=$val"
503 if test -n "$VALUE_ONLY_OPT"; then
511 if test -n "$EVAL_OPT"; then
512 # Echo statements for the shell to evaluate.
513 test -n "$DBG_OPT" && echo "dbg
: echoing exported variables
" 1>&${DBG_REDIR}
514 echo "${EVAL_EXPORT} PATH
=${PATH}"
515 test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && echo "${EVAL_EXPORT} KBUILD_TYPE=${KBUILD_TYPE}"
516 if test -n "${FULL_OPT}"; then
517 echo "${EVAL_EXPORT} KBUILD_PATH
=${KBUILD_PATH}"
518 echo "${EVAL_EXPORT} KBUILD_HOST
=${KBUILD_HOST}"
519 echo "${EVAL_EXPORT} KBUILD_HOST_ARCH
=${KBUILD_HOST_ARCH}"
520 echo "${EVAL_EXPORT} KBUILD_HOST_CPU
=${KBUILD_HOST_CPU}"
521 echo "${EVAL_EXPORT} KBUILD_TARGET
=${KBUILD_TARGET}"
522 echo "${EVAL_EXPORT} KBUILD_TARGET_ARCH
=${KBUILD_TARGET_ARCH}"
523 echo "${EVAL_EXPORT} KBUILD_TARGET_CPU
=${KBUILD_TARGET_CPU}"
525 if test -n "${LEGACY_OPT}"; then
526 echo "${EVAL_EXPORT} PATH_KBUILD
=${KBUILD_PATH}"
527 echo "${EVAL_EXPORT} BUILD_TYPE
=${KBUILD_TYPE}"
528 echo "${EVAL_EXPORT} BUILD_PLATFORM
=${KBUILD_HOST}"
529 echo "${EVAL_EXPORT} BUILD_PLATFORM_ARCH
=${KBUILD_HOST_ARCH}"
530 echo "${EVAL_EXPORT} BUILD_PLATFORM_CPU
=${KBUILD_HOST_CPU}"
531 echo "${EVAL_EXPORT} BUILD_TARGET
=${KBUILD_TARGET}"
532 echo "${EVAL_EXPORT} BUILD_TARGET_ARCH
=${KBUILD_TARGET_ARCH}"
533 echo "${EVAL_EXPORT} BUILD_TARGET_CPU
=${KBUILD_TARGET_CPU}"
539 test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && export KBUILD_TYPE
540 if test -n "${FULL_OPT}"; then
543 export KBUILD_HOST_ARCH
544 export KBUILD_HOST_CPU
546 export KBUILD_TARGET_ARCH
547 export KBUILD_TARGET_CPU
549 if test -n "${LEGACY_OPT}"; then
550 export PATH_KBUILD=$KBUILD_PATH
551 export BUILD_TYPE=$KBUILD_TYPE
552 export BUILD_PLATFORM=$KBUILD_HOST
553 export BUILD_PLATFORM_ARCH=$KBUILD_HOST_ARCH
554 export BUILD_PLATFORM_CPU=$KBUILD_HOST_CPU
555 export BUILD_TARGET=$KBUILD_TARGET
556 export BUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH
557 export BUILD_TARGET_CPU=$KBUILD_TARGET_CPU
561 # Execute command or spawn shell.
562 if test $# -eq 0; then
563 test -z "${QUIET_OPT}" && echo "$0: info
: Spawning work shell...
" 1>&${ERR_REDIR}
564 if test "$TERM" != 'dumb' -a -n "$BASH"; then
565 export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
570 test -z "${QUIET_OPT}" && echo "$0: info
: Executing
command: $
*" 1>&${ERR_REDIR}
573 test -z "${QUIET_OPT}" -a "$MY_RC" -ne 0 && echo "$0: info
: rc
=$MY_RC: $
*" 1>&${ERR_REDIR}
577 test -n "$DBG_OPT" && echo "dbg
: finished
(rc
=$MY_RC)" 1>&${DBG_REDIR}