[1510] | 1 | #!/bin/sh
|
---|
[224] | 2 | # $Id: env.sh 3099 2017-10-20 09:49:02Z bird $
|
---|
| 3 | ## @file
|
---|
| 4 | # Environment setup script.
|
---|
| 5 | #
|
---|
[1511] | 6 |
|
---|
| 7 | #
|
---|
[2413] | 8 | # Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@anduin.net>
|
---|
[224] | 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 | #
|
---|
[1067] | 27 | #set -x
|
---|
[224] | 28 |
|
---|
[992] | 29 | #
|
---|
[1510] | 30 | # Check if we're in eval mode or not.
|
---|
| 31 | #
|
---|
| 32 | ERR_REDIR=1
|
---|
| 33 | DBG_REDIR=1
|
---|
| 34 | EVAL_OPT=
|
---|
[1530] | 35 | EVAL_EXPORT="export "
|
---|
[1510] | 36 | DBG_OPT=
|
---|
| 37 | QUIET_OPT=
|
---|
[1512] | 38 | FULL_OPT=
|
---|
[2191] | 39 | FULL_WITH_BIN_OPT=
|
---|
[1570] | 40 | LEGACY_OPT=
|
---|
[1513] | 41 | VAR_OPT=
|
---|
[1517] | 42 | VALUE_ONLY_OPT=
|
---|
[1530] | 43 | EXP_TYPE_OPT=
|
---|
[1531] | 44 | while test $# -gt 0;
|
---|
[1512] | 45 | do
|
---|
| 46 | case "$1" in
|
---|
[1530] | 47 | "--debug-script")
|
---|
[1512] | 48 | DBG_OPT="true"
|
---|
| 49 | ;;
|
---|
[1530] | 50 | "--no-debug-script")
|
---|
[1517] | 51 | DBG_OPT=
|
---|
| 52 | ;;
|
---|
[1512] | 53 | "--quiet")
|
---|
| 54 | QUIET_OPT="true"
|
---|
| 55 | ;;
|
---|
[1517] | 56 | "--verbose")
|
---|
| 57 | QUIET_OPT=
|
---|
| 58 | ;;
|
---|
[1512] | 59 | "--full")
|
---|
| 60 | FULL_OPT="true"
|
---|
| 61 | ;;
|
---|
[2191] | 62 | "--full-with-bin")
|
---|
| 63 | FULL_OPT="true"
|
---|
| 64 | FULL_WITH_BIN_OPT="true"
|
---|
| 65 | ;;
|
---|
[1517] | 66 | "--normal")
|
---|
| 67 | FULL_OPT=
|
---|
| 68 | ;;
|
---|
| 69 | "--legacy")
|
---|
| 70 | LEGACY_OPT="true"
|
---|
| 71 | ;;
|
---|
| 72 | "--no-legacy")
|
---|
| 73 | LEGACY_OPT=
|
---|
| 74 | ;;
|
---|
[1512] | 75 | "--eval")
|
---|
| 76 | EVAL_OPT="true"
|
---|
| 77 | ERR_REDIR=2
|
---|
| 78 | DBG_REDIR=2
|
---|
| 79 | ;;
|
---|
[1530] | 80 | "--set")
|
---|
| 81 | EVAL_OPT="true"
|
---|
| 82 | EVAL_EXPORT=""
|
---|
| 83 | ERR_REDIR=2
|
---|
| 84 | DBG_REDIR=2
|
---|
| 85 | ;;
|
---|
[1513] | 86 | "--var")
|
---|
| 87 | shift
|
---|
| 88 | VAR_OPT="${VAR_OPT} $1"
|
---|
[1517] | 89 | ERR_REDIR=2
|
---|
| 90 | DBG_REDIR=2
|
---|
[1513] | 91 | ;;
|
---|
[1517] | 92 | "--value-only")
|
---|
| 93 | VALUE_ONLY_OPT="true"
|
---|
| 94 | ;;
|
---|
| 95 | "--name-and-value")
|
---|
| 96 | VALUE_ONLY_OPT=
|
---|
| 97 | ;;
|
---|
[1530] | 98 | "--release")
|
---|
| 99 | EXP_TYPE_OPT=1
|
---|
| 100 | KBUILD_TYPE=release
|
---|
| 101 | BUILD_TYPE=
|
---|
| 102 | ;;
|
---|
| 103 | "--debug")
|
---|
| 104 | EXP_TYPE_OPT=1
|
---|
| 105 | KBUILD_TYPE=debug
|
---|
| 106 | BUILD_TYPE=
|
---|
| 107 | ;;
|
---|
| 108 | "--profile")
|
---|
| 109 | EXP_TYPE_OPT=1
|
---|
| 110 | KBUILD_TYPE=profile
|
---|
| 111 | BUILD_TYPE=
|
---|
| 112 | ;;
|
---|
| 113 |
|
---|
[1512] | 114 | "--help")
|
---|
[2347] | 115 | echo "kBuild Environment Setup Script, v0.2.0-pre"
|
---|
[1517] | 116 | echo ""
|
---|
| 117 | echo "syntax: $0 [options] [command [args]]"
|
---|
| 118 | echo " or: $0 [options] --var <varname>"
|
---|
| 119 | echo " or: $0 [options] --eval"
|
---|
| 120 | echo " or: $0 [options] --eval --var <varname>"
|
---|
| 121 | echo ""
|
---|
[1570] | 122 | echo "The first form will execute the command, or if no command is given start"
|
---|
[1517] | 123 | echo "an interactive shell."
|
---|
| 124 | echo "The second form will print the specfified variable(s)."
|
---|
| 125 | echo "The third form will print all exported variables suitable for bourne shell"
|
---|
[2347] | 126 | echo "evaluation."
|
---|
[1517] | 127 | echo "The forth form will only print the specified variable(s)."
|
---|
| 128 | echo ""
|
---|
| 129 | echo "Options:"
|
---|
[1530] | 130 | echo " --debug, --release, --profile"
|
---|
| 131 | echo " Alternative way of specifying KBUILD_TYPE."
|
---|
| 132 | echo " --debug-script, --no-debug-script"
|
---|
| 133 | echo " Controls debug output. Default: --no-debug-script"
|
---|
[1517] | 134 | echo " --quiet, --verbose"
|
---|
| 135 | echo " Controls informational output. Default: --verbose"
|
---|
[2191] | 136 | echo " --full, --full-with-bin, --normal"
|
---|
[1517] | 137 | echo " Controls the variable set. Default: --normal"
|
---|
| 138 | echo " --legacy, --no-legacy"
|
---|
[1570] | 139 | echo " Include legacy variables in result. Default: --no-legacy"
|
---|
[1517] | 140 | echo " --value-only, --name-and-value"
|
---|
| 141 | echo " Controls what the result of a --var query. Default: --name-and-value"
|
---|
[1530] | 142 | echo " --set, --export"
|
---|
| 143 | echo " Whether --eval explicitly export the variables. --set is useful for"
|
---|
| 144 | echo " getting a list of environment vars for a commandline, while --eval"
|
---|
[2347] | 145 | echo ' is useful for eval `env.sh`. Default: --export'
|
---|
[1517] | 146 | echo ""
|
---|
[1512] | 147 | exit 1
|
---|
| 148 | ;;
|
---|
| 149 | *)
|
---|
| 150 | break
|
---|
| 151 | ;;
|
---|
| 152 | esac
|
---|
[1510] | 153 | shift
|
---|
[1512] | 154 | done
|
---|
[1510] | 155 |
|
---|
| 156 |
|
---|
| 157 | #
|
---|
[1517] | 158 | # Deal with legacy environment variables.
|
---|
[992] | 159 | #
|
---|
[1517] | 160 | if test -n "$PATH_KBUILD"; then
|
---|
| 161 | if test -n "$KBUILD_PATH" -a "$KBUILD_PATH" != "$PATH_KBUILD"; then
|
---|
| 162 | echo "$0: error: KBUILD_PATH ($KBUILD_PATH) and PATH_KBUILD ($PATH_KBUILD) disagree." 1>&${ERR_REDIR}
|
---|
| 163 | sleep 1
|
---|
| 164 | exit 1
|
---|
| 165 | fi
|
---|
| 166 | KBUILD_PATH=$PATH_KBUILD
|
---|
[224] | 167 | fi
|
---|
[1517] | 168 | if test -n "$PATH_KBUILD_BIN"; then
|
---|
| 169 | if test -n "$KBUILD_BIN_PATH" -a "$KBUILD_BIN_PATH" != "$PATH_KBUILD_BIN"; then
|
---|
| 170 | echo "$0: error: KBUILD_BIN_PATH ($KBUILD_BIN_PATH) and PATH_KBUILD_BIN ($PATH_KBUILD_BIN) disagree." 1>&${ERR_REDIR}
|
---|
| 171 | sleep 1
|
---|
| 172 | exit 1
|
---|
| 173 | fi
|
---|
| 174 | KBUILD_BIN_PATH=$PATH_KBUILD_BIN
|
---|
[224] | 175 | fi
|
---|
| 176 |
|
---|
[1517] | 177 | if test -n "$BUILD_TYPE"; then
|
---|
| 178 | if test -n "$KBUILD_TYPE" -a "$KBUILD_TYPE" != "$BUILD_TYPE"; then
|
---|
| 179 | echo "$0: error: KBUILD_TYPE ($KBUILD_TYPE) and BUILD_TYPE ($BUILD_TYPE) disagree." 1>&${ERR_REDIR}
|
---|
| 180 | sleep 1
|
---|
| 181 | exit 1
|
---|
| 182 | fi
|
---|
| 183 | KBUILD_TYPE=$BUILD_TYPE
|
---|
| 184 | fi
|
---|
[1076] | 185 |
|
---|
[1517] | 186 | if test -n "$BUILD_PLATFORM"; then
|
---|
| 187 | if test -n "$KBUILD_HOST" -a "$KBUILD_HOST" != "$BUILD_PLATFORM"; then
|
---|
| 188 | echo "$0: error: KBUILD_HOST ($KBUILD_HOST) and BUILD_PLATFORM ($BUILD_PLATFORM) disagree." 1>&${ERR_REDIR}
|
---|
| 189 | sleep 1
|
---|
| 190 | exit 1
|
---|
| 191 | fi
|
---|
| 192 | KBUILD_HOST=$BUILD_PLATFORM
|
---|
| 193 | fi
|
---|
| 194 | if test -n "$BUILD_PLATFORM_ARCH"; then
|
---|
| 195 | if test -n "$KBUILD_HOST_ARCH" -a "$KBUILD_HOST_ARCH" != "$BUILD_PLATFORM_ARCH"; then
|
---|
| 196 | echo "$0: error: KBUILD_HOST_ARCH ($KBUILD_HOST_ARCH) and BUILD_PLATFORM_ARCH ($BUILD_PLATFORM_ARCH) disagree." 1>&${ERR_REDIR}
|
---|
| 197 | sleep 1
|
---|
| 198 | exit 1
|
---|
| 199 | fi
|
---|
| 200 | KBUILD_HOST_ARCH=$BUILD_PLATFORM_ARCH
|
---|
| 201 | fi
|
---|
| 202 | if test -n "$BUILD_PLATFORM_CPU"; then
|
---|
| 203 | if test -n "$KBUILD_HOST_CPU" -a "$KBUILD_HOST_CPU" != "$BUILD_PLATFORM_CPU"; then
|
---|
| 204 | echo "$0: error: KBUILD_HOST_CPU ($KBUILD_HOST_CPU) and BUILD_PLATFORM_CPU ($BUILD_PLATFORM_CPU) disagree." 1>&${ERR_REDIR}
|
---|
| 205 | sleep 1
|
---|
| 206 | exit 1
|
---|
| 207 | fi
|
---|
| 208 | KBUILD_HOST_CPU=$BUILD_PLATFORM_CPU
|
---|
| 209 | fi
|
---|
| 210 |
|
---|
| 211 | if test -n "$BUILD_TARGET"; then
|
---|
| 212 | if test -n "$KBUILD_TARGET" -a "$KBUILD_TARGET" != "$BUILD_TARGET"; then
|
---|
| 213 | echo "$0: error: KBUILD_TARGET ($KBUILD_TARGET) and BUILD_TARGET ($BUILD_TARGET) disagree." 1>&${ERR_REDIR}
|
---|
| 214 | sleep 1
|
---|
| 215 | exit 1
|
---|
| 216 | fi
|
---|
| 217 | KBUILD_TARGET=$BUILD_TARGET
|
---|
| 218 | fi
|
---|
| 219 | if test -n "$BUILD_TARGET_ARCH"; then
|
---|
| 220 | if test -n "$KBUILD_TARGET_ARCH" -a "$KBUILD_TARGET_ARCH" != "$BUILD_TARGET_ARCH"; then
|
---|
| 221 | echo "$0: error: KBUILD_TARGET_ARCH ($KBUILD_TARGET_ARCH) and BUILD_TARGET_ARCH ($BUILD_TARGET_ARCH) disagree." 1>&${ERR_REDIR}
|
---|
| 222 | sleep 1
|
---|
| 223 | exit 1
|
---|
| 224 | fi
|
---|
| 225 | KBUILD_TARGET_ARCH=$BUILD_TARGET_ARCH
|
---|
| 226 | fi
|
---|
| 227 | if test -n "$BUILD_TARGET_CPU"; then
|
---|
| 228 | if test -n "$KBUILD_TARGET_CPU" -a "$KBUILD_TARGET_CPU" != "$BUILD_TARGET_CPU"; then
|
---|
| 229 | echo "$0: error: KBUILD_TARGET_CPU ($KBUILD_TARGET_CPU) and BUILD_TARGET_CPU ($BUILD_TARGET_CPU) disagree." 1>&${ERR_REDIR}
|
---|
| 230 | sleep 1
|
---|
| 231 | exit 1
|
---|
| 232 | fi
|
---|
| 233 | KBUILD_TARGET_CPU=$BUILD_TARGET_CPU
|
---|
| 234 | fi
|
---|
| 235 |
|
---|
| 236 |
|
---|
[992] | 237 | #
|
---|
| 238 | # Set default build type.
|
---|
| 239 | #
|
---|
[1517] | 240 | if test -z "$KBUILD_TYPE"; then
|
---|
| 241 | KBUILD_TYPE=release
|
---|
[224] | 242 | fi
|
---|
[1517] | 243 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TYPE=$KBUILD_TYPE" 1>&${DBG_REDIR}
|
---|
[224] | 244 |
|
---|
[992] | 245 | #
|
---|
| 246 | # Determin the host platform.
|
---|
| 247 | #
|
---|
| 248 | # The CPU isn't important, only the other two are. But, since the cpu,
|
---|
| 249 | # arch and platform (and build type) share a common key space, try make
|
---|
| 250 | # sure any new additions are unique. (See header.kmk, KBUILD_OSES/ARCHES.)
|
---|
| 251 | #
|
---|
[1517] | 252 | if test -z "$KBUILD_HOST"; then
|
---|
| 253 | KBUILD_HOST=`uname`
|
---|
| 254 | case "$KBUILD_HOST" in
|
---|
[1603] | 255 | Darwin|darwin)
|
---|
| 256 | KBUILD_HOST=darwin
|
---|
[994] | 257 | ;;
|
---|
| 258 |
|
---|
[1603] | 259 | DragonFly)
|
---|
| 260 | KBUILD_HOST=dragonfly
|
---|
[994] | 261 | ;;
|
---|
| 262 |
|
---|
| 263 | freebsd|FreeBSD|FREEBSD)
|
---|
[1517] | 264 | KBUILD_HOST=freebsd
|
---|
[994] | 265 | ;;
|
---|
| 266 |
|
---|
[3099] | 267 | GNU/kFreeBSD)
|
---|
| 268 | KBUILD_HOST=gnukfbsd
|
---|
| 269 | ;;
|
---|
| 270 |
|
---|
| 271 | GNU/kNetBSD|GNU/NetBSD)
|
---|
| 272 | KBUILD_HOST=gnuknbsd
|
---|
| 273 | ;;
|
---|
| 274 |
|
---|
[2546] | 275 | Haiku)
|
---|
| 276 | KBUILD_HOST=haiku
|
---|
| 277 | ;;
|
---|
| 278 |
|
---|
[1603] | 279 | linux|Linux|GNU/Linux|LINUX)
|
---|
| 280 | KBUILD_HOST=linux
|
---|
[994] | 281 | ;;
|
---|
| 282 |
|
---|
| 283 | netbsd|NetBSD|NETBSD)
|
---|
[1517] | 284 | KBUILD_HOST=netbsd
|
---|
[994] | 285 | ;;
|
---|
| 286 |
|
---|
[1603] | 287 | openbsd|OpenBSD|OPENBSD)
|
---|
| 288 | KBUILD_HOST=openbsd
|
---|
[994] | 289 | ;;
|
---|
| 290 |
|
---|
[1603] | 291 | os2|OS/2|OS2)
|
---|
| 292 | KBUILD_HOST=os2
|
---|
| 293 | ;;
|
---|
| 294 |
|
---|
[994] | 295 | SunOS)
|
---|
[1517] | 296 | KBUILD_HOST=solaris
|
---|
[994] | 297 | ;;
|
---|
| 298 |
|
---|
| 299 | WindowsNT|CYGWIN_NT-*)
|
---|
[1517] | 300 | KBUILD_HOST=win
|
---|
[994] | 301 | ;;
|
---|
| 302 |
|
---|
| 303 | *)
|
---|
[1517] | 304 | echo "$0: unknown os $KBUILD_HOST" 1>&${ERR_REDIR}
|
---|
[994] | 305 | sleep 1
|
---|
| 306 | exit 1
|
---|
| 307 | ;;
|
---|
| 308 | esac
|
---|
| 309 | fi
|
---|
[1517] | 310 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST=$KBUILD_HOST" 1>&${DBG_REDIR}
|
---|
[994] | 311 |
|
---|
[1517] | 312 | if test -z "$KBUILD_HOST_ARCH"; then
|
---|
[992] | 313 | # Try deduce it from the cpu if given.
|
---|
[1517] | 314 | if test -n "$KBUILD_HOST_CPU"; then
|
---|
| 315 | case "$KBUILD_HOST_CPU" in
|
---|
[992] | 316 | i[3456789]86)
|
---|
[1517] | 317 | KBUILD_HOST_ARCH='x86'
|
---|
[992] | 318 | ;;
|
---|
| 319 | k8|k8l|k9|k10)
|
---|
[1517] | 320 | KBUILD_HOST_ARCH='amd64'
|
---|
[992] | 321 | ;;
|
---|
| 322 | esac
|
---|
| 323 | fi
|
---|
[224] | 324 | fi
|
---|
[1517] | 325 | if test -z "$KBUILD_HOST_ARCH"; then
|
---|
[1156] | 326 | # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
|
---|
[1517] | 327 | if test "$KBUILD_HOST" = "solaris"; then
|
---|
| 328 | KBUILD_HOST_ARCH=`isainfo | cut -f 1 -d ' '`
|
---|
[1531] | 329 |
|
---|
[1156] | 330 | else
|
---|
[1517] | 331 | KBUILD_HOST_ARCH=`uname -m`
|
---|
[1156] | 332 | fi
|
---|
[1517] | 333 | case "$KBUILD_HOST_ARCH" in
|
---|
[992] | 334 | x86_64|AMD64|amd64|k8|k8l|k9|k10)
|
---|
[1517] | 335 | KBUILD_HOST_ARCH='amd64'
|
---|
[992] | 336 | ;;
|
---|
[2546] | 337 | x86|i86pc|ia32|i[3456789]86|BePC)
|
---|
[1517] | 338 | KBUILD_HOST_ARCH='x86'
|
---|
[224] | 339 | ;;
|
---|
[3062] | 340 | alpha)
|
---|
| 341 | KBUILD_HOST_ARCH='alpha'
|
---|
[299] | 342 | ;;
|
---|
[3062] | 343 | aarch32|arm|arm1|arm2|arm3|arm6|armv1|armv2|armv3*|armv4*|armv5*|armv6*|armv7*)
|
---|
| 344 | KBUILD_HOST_ARCH='arm32'
|
---|
[992] | 345 | ;;
|
---|
[3062] | 346 | aarch64*)
|
---|
| 347 | KBUILD_HOST_ARCH='arm64'
|
---|
[992] | 348 | ;;
|
---|
[3062] | 349 | hppa32|parisc32|parisc)
|
---|
| 350 | KBUILD_HOST_ARCH='hppa32'
|
---|
[1380] | 351 | ;;
|
---|
[3062] | 352 | hppa64|parisc64)
|
---|
| 353 | KBUILD_HOST_ARCH='hppa64'
|
---|
| 354 | ;;
|
---|
| 355 | ia64)
|
---|
| 356 | KBUILD_HOST_ARCH='ia64'
|
---|
| 357 | ;;
|
---|
[992] | 358 | ppc32|ppc|powerpc)
|
---|
[1517] | 359 | KBUILD_HOST_ARCH='ppc32'
|
---|
[992] | 360 | ;;
|
---|
[3062] | 361 | ppc64|ppc64le|powerpc64|powerpc64le)
|
---|
[1517] | 362 | KBUILD_HOST_ARCH='ppc64'
|
---|
[992] | 363 | ;;
|
---|
| 364 | mips32|mips)
|
---|
[1517] | 365 | KBUILD_HOST_ARCH='mips32'
|
---|
[992] | 366 | ;;
|
---|
| 367 | mips64)
|
---|
[1517] | 368 | KBUILD_HOST_ARCH='mips64'
|
---|
[992] | 369 | ;;
|
---|
[3062] | 370 | s390)
|
---|
| 371 | KBUILD_HOST_ARCH='s390'
|
---|
[992] | 372 | ;;
|
---|
[3062] | 373 | s390x)
|
---|
| 374 | KBUILD_HOST_ARCH='s390x'
|
---|
[992] | 375 | ;;
|
---|
[3062] | 376 | sh|sh2|sh2a|sh3|sh3|sh4|sh4a|sh4al|sh4al-dsp|shmedia)
|
---|
| 377 | KBUILD_HOST_ARCH='sh32'
|
---|
| 378 | ;;
|
---|
| 379 | sh64)
|
---|
| 380 | KBUILD_HOST_ARCH='sh64'
|
---|
| 381 | ;;
|
---|
| 382 | sparc32|sparc|sparcv8|sparcv7|sparcv8e)
|
---|
| 383 | KBUILD_HOST_ARCH='sparc32'
|
---|
[992] | 384 | ;;
|
---|
[3062] | 385 | sparc64|sparcv9)
|
---|
| 386 | KBUILD_HOST_ARCH='sparc64'
|
---|
[992] | 387 | ;;
|
---|
| 388 |
|
---|
[1517] | 389 | *) echo "$0: unknown cpu/arch - $KBUILD_HOST_ARCH" 1>&${ERR_REDIR}
|
---|
[224] | 390 | sleep 1
|
---|
| 391 | exit 1
|
---|
| 392 | ;;
|
---|
| 393 | esac
|
---|
| 394 |
|
---|
| 395 | fi
|
---|
[1517] | 396 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_ARCH=$KBUILD_HOST_ARCH" 1>&${DBG_REDIR}
|
---|
[224] | 397 |
|
---|
[1517] | 398 | if test -z "$KBUILD_HOST_CPU"; then
|
---|
| 399 | KBUILD_HOST_CPU="blend"
|
---|
[992] | 400 | fi
|
---|
[1517] | 401 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_CPU=$KBUILD_HOST_CPU" 1>&${DBG_REDIR}
|
---|
[224] | 402 |
|
---|
[992] | 403 | #
|
---|
| 404 | # The target platform.
|
---|
| 405 | # Defaults to the host when not specified.
|
---|
| 406 | #
|
---|
[1517] | 407 | if test -z "$KBUILD_TARGET"; then
|
---|
| 408 | KBUILD_TARGET="$KBUILD_HOST"
|
---|
[224] | 409 | fi
|
---|
[1517] | 410 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET=$KBUILD_TARGET" 1>&${DBG_REDIR}
|
---|
[224] | 411 |
|
---|
[1517] | 412 | if test -z "$KBUILD_TARGET_ARCH"; then
|
---|
| 413 | KBUILD_TARGET_ARCH="$KBUILD_HOST_ARCH"
|
---|
[224] | 414 | fi
|
---|
[1517] | 415 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH" 1>&${DBG_REDIR}
|
---|
[224] | 416 |
|
---|
[1517] | 417 | if test -z "$KBUILD_TARGET_CPU"; then
|
---|
| 418 | if test "$KBUILD_TARGET_ARCH" = "$KBUILD_HOST_ARCH"; then
|
---|
| 419 | KBUILD_TARGET_CPU="$KBUILD_HOST_CPU"
|
---|
[994] | 420 | else
|
---|
[1517] | 421 | KBUILD_TARGET_CPU="blend"
|
---|
[994] | 422 | fi
|
---|
[224] | 423 | fi
|
---|
[1517] | 424 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_CPU=$KBUILD_TARGET_CPU" 1>&${DBG_REDIR}
|
---|
[224] | 425 |
|
---|
[1517] | 426 | #
|
---|
[224] | 427 | # Determin executable extension and path separator.
|
---|
[1517] | 428 | #
|
---|
[224] | 429 | _SUFF_EXE=
|
---|
| 430 | _PATH_SEP=":"
|
---|
[1517] | 431 | case "$KBUILD_HOST" in
|
---|
[992] | 432 | os2|win|nt)
|
---|
[224] | 433 | _SUFF_EXE=".exe"
|
---|
| 434 | _PATH_SEP=";"
|
---|
| 435 | ;;
|
---|
| 436 | esac
|
---|
| 437 |
|
---|
[1076] | 438 | #
|
---|
[1517] | 439 | # Determin KBUILD_PATH from the script location and calc KBUILD_BIN_PATH from there.
|
---|
[1076] | 440 | #
|
---|
[1517] | 441 | if test -z "$KBUILD_PATH"; then
|
---|
| 442 | KBUILD_PATH=`dirname "$0"`
|
---|
| 443 | KBUILD_PATH=`cd "$KBUILD_PATH" ; /bin/pwd`
|
---|
[1076] | 444 | fi
|
---|
[1517] | 445 | if test ! -f "$KBUILD_PATH/footer.kmk" -o ! -f "$KBUILD_PATH/header.kmk" -o ! -f "$KBUILD_PATH/rules.kmk"; then
|
---|
| 446 | echo "$0: error: KBUILD_PATH ($KBUILD_PATH) is not pointing to a popluated kBuild directory." 1>&${ERR_REDIR}
|
---|
| 447 | sleep 1
|
---|
| 448 | exit 1
|
---|
| 449 | fi
|
---|
| 450 | test -n "$DBG_OPT" && echo "dbg: KBUILD_PATH=$KBUILD_PATH" 1>&${DBG_REDIR}
|
---|
[1076] | 451 |
|
---|
[1517] | 452 | if test -z "$KBUILD_BIN_PATH"; then
|
---|
| 453 | KBUILD_BIN_PATH="${KBUILD_PATH}/bin/${KBUILD_HOST}.${KBUILD_HOST_ARCH}"
|
---|
[1510] | 454 | fi
|
---|
[1517] | 455 | test -n "$DBG_OPT" && echo "dbg: KBUILD_BIN_PATH=${KBUILD_BIN_PATH}" 1>&${DBG_REDIR}
|
---|
[224] | 456 |
|
---|
[992] | 457 | #
|
---|
| 458 | # Add the bin/x.y/ directory to the PATH.
|
---|
| 459 | # NOTE! Once bootstrapped this is the only thing that is actually necessary.
|
---|
| 460 | #
|
---|
[1517] | 461 | PATH="${KBUILD_BIN_PATH}${_PATH_SEP}$PATH"
|
---|
[1510] | 462 | test -n "$DBG_OPT" && echo "dbg: PATH=$PATH" 1>&${DBG_REDIR}
|
---|
[224] | 463 |
|
---|
[1517] | 464 | #
|
---|
[224] | 465 | # Sanity and x bits.
|
---|
[1517] | 466 | #
|
---|
| 467 | if test ! -d "${KBUILD_BIN_PATH}/"; then
|
---|
[1531] | 468 | echo "$0: warning: The bin directory for this platform doesn't exist. (${KBUILD_BIN_PATH}/)" 1>&${ERR_REDIR}
|
---|
[224] | 469 | else
|
---|
[731] | 470 | 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;
|
---|
[224] | 471 | do
|
---|
[1517] | 472 | chmod a+x ${KBUILD_BIN_PATH}/${prog} > /dev/null 2>&1
|
---|
| 473 | if test ! -f "${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE}"; then
|
---|
| 474 | echo "$0: warning: The ${prog} program doesn't exist for this platform. (${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE})" 1>&${ERR_REDIR}
|
---|
[224] | 475 | fi
|
---|
| 476 | done
|
---|
| 477 | fi
|
---|
| 478 |
|
---|
[1517] | 479 | #
|
---|
| 480 | # The environment is in place, now take the requested action.
|
---|
| 481 | #
|
---|
[1542] | 482 | MY_RC=0
|
---|
[1513] | 483 | if test -n "${VAR_OPT}"; then
|
---|
| 484 | # Echo variable values or variable export statements.
|
---|
| 485 | for var in ${VAR_OPT};
|
---|
| 486 | do
|
---|
| 487 | val=
|
---|
[1531] | 488 | case "$var" in
|
---|
| 489 | PATH)
|
---|
| 490 | val=$PATH
|
---|
[1513] | 491 | ;;
|
---|
[1531] | 492 | KBUILD_PATH)
|
---|
| 493 | val=$KBUILD_PATH
|
---|
[1513] | 494 | ;;
|
---|
[1531] | 495 | KBUILD_BIN_PATH)
|
---|
[1517] | 496 | val=$KBUILD_BIN_PATH
|
---|
[1513] | 497 | ;;
|
---|
[1531] | 498 | KBUILD_HOST)
|
---|
| 499 | val=$KBUILD_HOST
|
---|
[1513] | 500 | ;;
|
---|
[1531] | 501 | KBUILD_HOST_ARCH)
|
---|
[1517] | 502 | val=$KBUILD_HOST_ARCH
|
---|
[1513] | 503 | ;;
|
---|
[1531] | 504 | KBUILD_HOST_CPU)
|
---|
[1517] | 505 | val=$KBUILD_HOST_CPU
|
---|
[1513] | 506 | ;;
|
---|
[1531] | 507 | KBUILD_TARGET)
|
---|
| 508 | val=$KBUILD_TARGET
|
---|
[1513] | 509 | ;;
|
---|
[1531] | 510 | KBUILD_TARGET_ARCH)
|
---|
[1517] | 511 | val=$KBUILD_TARGET_ARCH
|
---|
[1513] | 512 | ;;
|
---|
[1531] | 513 | KBUILD_TARGET_CPU)
|
---|
[1517] | 514 | val=$KBUILD_TARGET_CPU
|
---|
[1513] | 515 | ;;
|
---|
[1531] | 516 | KBUILD_TYPE)
|
---|
[1517] | 517 | val=$KBUILD_TYPE
|
---|
[1513] | 518 | ;;
|
---|
[1531] | 519 | *)
|
---|
[1513] | 520 | echo "$0: error: Unknown variable $var specified in --var request." 1>&${ERR_REDIR}
|
---|
| 521 | sleep 1
|
---|
| 522 | exit 1
|
---|
| 523 | ;;
|
---|
| 524 | esac
|
---|
[1512] | 525 |
|
---|
[1513] | 526 | if test -n "$EVAL_OPT"; then
|
---|
[1530] | 527 | echo "${EVAL_EXPORT} $var=$val"
|
---|
[1513] | 528 | else
|
---|
[1517] | 529 | if test -n "$VALUE_ONLY_OPT"; then
|
---|
| 530 | echo "$val"
|
---|
| 531 | else
|
---|
| 532 | echo "$var=$val"
|
---|
| 533 | fi
|
---|
[1510] | 534 | fi
|
---|
[1513] | 535 | done
|
---|
| 536 | else
|
---|
| 537 | if test -n "$EVAL_OPT"; then
|
---|
| 538 | # Echo statements for the shell to evaluate.
|
---|
| 539 | test -n "$DBG_OPT" && echo "dbg: echoing exported variables" 1>&${DBG_REDIR}
|
---|
[1530] | 540 | echo "${EVAL_EXPORT} PATH=${PATH}"
|
---|
| 541 | test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && echo "${EVAL_EXPORT} KBUILD_TYPE=${KBUILD_TYPE}"
|
---|
[1513] | 542 | if test -n "${FULL_OPT}"; then
|
---|
[1530] | 543 | echo "${EVAL_EXPORT} KBUILD_PATH=${KBUILD_PATH}"
|
---|
[2191] | 544 | if test -n "{FULL_WITH_BIN_OPT}"; then
|
---|
| 545 | echo "${EVAL_EXPORT} KBUILD_BIN_PATH=${KBUILD_BIN_PATH}"
|
---|
| 546 | fi
|
---|
[1530] | 547 | echo "${EVAL_EXPORT} KBUILD_HOST=${KBUILD_HOST}"
|
---|
| 548 | echo "${EVAL_EXPORT} KBUILD_HOST_ARCH=${KBUILD_HOST_ARCH}"
|
---|
| 549 | echo "${EVAL_EXPORT} KBUILD_HOST_CPU=${KBUILD_HOST_CPU}"
|
---|
| 550 | echo "${EVAL_EXPORT} KBUILD_TARGET=${KBUILD_TARGET}"
|
---|
| 551 | echo "${EVAL_EXPORT} KBUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}"
|
---|
| 552 | echo "${EVAL_EXPORT} KBUILD_TARGET_CPU=${KBUILD_TARGET_CPU}"
|
---|
[1517] | 553 |
|
---|
| 554 | if test -n "${LEGACY_OPT}"; then
|
---|
[1530] | 555 | echo "${EVAL_EXPORT} PATH_KBUILD=${KBUILD_PATH}"
|
---|
[2243] | 556 | if test -n "${FULL_WITH_BIN_OPT}"; then
|
---|
[2191] | 557 | echo "${EVAL_EXPORT} PATH_KBUILD_BIN=${KBUILD_PATH_BIN}"
|
---|
[2243] | 558 | fi
|
---|
[1530] | 559 | echo "${EVAL_EXPORT} BUILD_TYPE=${KBUILD_TYPE}"
|
---|
| 560 | echo "${EVAL_EXPORT} BUILD_PLATFORM=${KBUILD_HOST}"
|
---|
| 561 | echo "${EVAL_EXPORT} BUILD_PLATFORM_ARCH=${KBUILD_HOST_ARCH}"
|
---|
| 562 | echo "${EVAL_EXPORT} BUILD_PLATFORM_CPU=${KBUILD_HOST_CPU}"
|
---|
| 563 | echo "${EVAL_EXPORT} BUILD_TARGET=${KBUILD_TARGET}"
|
---|
| 564 | echo "${EVAL_EXPORT} BUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}"
|
---|
| 565 | echo "${EVAL_EXPORT} BUILD_TARGET_CPU=${KBUILD_TARGET_CPU}"
|
---|
[1517] | 566 | fi
|
---|
[1513] | 567 | fi
|
---|
[1510] | 568 | else
|
---|
[1513] | 569 | # Export variables.
|
---|
| 570 | export PATH
|
---|
[1530] | 571 | test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && export KBUILD_TYPE
|
---|
[1513] | 572 | if test -n "${FULL_OPT}"; then
|
---|
[1517] | 573 | export KBUILD_PATH
|
---|
[2191] | 574 | if test -n "${FULL_WITH_BIN_OPT}"; then
|
---|
| 575 | export KBUILD_BIN_PATH
|
---|
| 576 | fi
|
---|
[1517] | 577 | export KBUILD_HOST
|
---|
| 578 | export KBUILD_HOST_ARCH
|
---|
| 579 | export KBUILD_HOST_CPU
|
---|
| 580 | export KBUILD_TARGET
|
---|
| 581 | export KBUILD_TARGET_ARCH
|
---|
| 582 | export KBUILD_TARGET_CPU
|
---|
| 583 |
|
---|
| 584 | if test -n "${LEGACY_OPT}"; then
|
---|
| 585 | export PATH_KBUILD=$KBUILD_PATH
|
---|
[2191] | 586 | if test -n "${FULL_WITH_BIN_OPT}"; then
|
---|
| 587 | export PATH_KBUILD_BIN=$KBUILD_BIN_PATH
|
---|
| 588 | fi
|
---|
[1517] | 589 | export BUILD_TYPE=$KBUILD_TYPE
|
---|
| 590 | export BUILD_PLATFORM=$KBUILD_HOST
|
---|
| 591 | export BUILD_PLATFORM_ARCH=$KBUILD_HOST_ARCH
|
---|
| 592 | export BUILD_PLATFORM_CPU=$KBUILD_HOST_CPU
|
---|
| 593 | export BUILD_TARGET=$KBUILD_TARGET
|
---|
| 594 | export BUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH
|
---|
| 595 | export BUILD_TARGET_CPU=$KBUILD_TARGET_CPU
|
---|
| 596 | fi
|
---|
[1513] | 597 | fi
|
---|
[1531] | 598 |
|
---|
[1513] | 599 | # Execute command or spawn shell.
|
---|
| 600 | if test $# -eq 0; then
|
---|
| 601 | test -z "${QUIET_OPT}" && echo "$0: info: Spawning work shell..." 1>&${ERR_REDIR}
|
---|
| 602 | if test "$TERM" != 'dumb' -a -n "$BASH"; then
|
---|
| 603 | export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
|
---|
| 604 | fi
|
---|
| 605 | $SHELL -i
|
---|
[1542] | 606 | MY_RC=$?
|
---|
[1513] | 607 | else
|
---|
| 608 | test -z "${QUIET_OPT}" && echo "$0: info: Executing command: $*" 1>&${ERR_REDIR}
|
---|
| 609 | $*
|
---|
[1542] | 610 | MY_RC=$?
|
---|
| 611 | test -z "${QUIET_OPT}" -a "$MY_RC" -ne 0 && echo "$0: info: rc=$MY_RC: $*" 1>&${ERR_REDIR}
|
---|
[1513] | 612 | fi
|
---|
[224] | 613 | fi
|
---|
| 614 | fi
|
---|
[1542] | 615 | test -n "$DBG_OPT" && echo "dbg: finished (rc=$MY_RC)" 1>&${DBG_REDIR}
|
---|
| 616 | exit $MY_RC
|
---|
[731] | 617 |
|
---|