| [1510] | 1 | #!/bin/sh | 
|---|
| [224] | 2 | # $Id: env.sh 1571 2008-04-24 23:25:26Z bird $ | 
|---|
|  | 3 | ## @file | 
|---|
|  | 4 | # Environment setup script. | 
|---|
|  | 5 | # | 
|---|
| [1511] | 6 |  | 
|---|
|  | 7 | # | 
|---|
| [1507] | 8 | # Copyright (c) 2005-2008 knut st. osmundsen <bird-kBuild-spam@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= | 
|---|
| [1570] | 39 | LEGACY_OPT= | 
|---|
| [1513] | 40 | VAR_OPT= | 
|---|
| [1517] | 41 | VALUE_ONLY_OPT= | 
|---|
| [1530] | 42 | EXP_TYPE_OPT= | 
|---|
| [1531] | 43 | while test $# -gt 0; | 
|---|
| [1512] | 44 | do | 
|---|
|  | 45 | case "$1" in | 
|---|
| [1530] | 46 | "--debug-script") | 
|---|
| [1512] | 47 | DBG_OPT="true" | 
|---|
|  | 48 | ;; | 
|---|
| [1530] | 49 | "--no-debug-script") | 
|---|
| [1517] | 50 | DBG_OPT= | 
|---|
|  | 51 | ;; | 
|---|
| [1512] | 52 | "--quiet") | 
|---|
|  | 53 | QUIET_OPT="true" | 
|---|
|  | 54 | ;; | 
|---|
| [1517] | 55 | "--verbose") | 
|---|
|  | 56 | QUIET_OPT= | 
|---|
|  | 57 | ;; | 
|---|
| [1512] | 58 | "--full") | 
|---|
|  | 59 | FULL_OPT="true" | 
|---|
|  | 60 | ;; | 
|---|
| [1517] | 61 | "--normal") | 
|---|
|  | 62 | FULL_OPT= | 
|---|
|  | 63 | ;; | 
|---|
|  | 64 | "--legacy") | 
|---|
|  | 65 | LEGACY_OPT="true" | 
|---|
|  | 66 | ;; | 
|---|
|  | 67 | "--no-legacy") | 
|---|
|  | 68 | LEGACY_OPT= | 
|---|
|  | 69 | ;; | 
|---|
| [1512] | 70 | "--eval") | 
|---|
|  | 71 | EVAL_OPT="true" | 
|---|
|  | 72 | ERR_REDIR=2 | 
|---|
|  | 73 | DBG_REDIR=2 | 
|---|
|  | 74 | ;; | 
|---|
| [1530] | 75 | "--set") | 
|---|
|  | 76 | EVAL_OPT="true" | 
|---|
|  | 77 | EVAL_EXPORT="" | 
|---|
|  | 78 | ERR_REDIR=2 | 
|---|
|  | 79 | DBG_REDIR=2 | 
|---|
|  | 80 | ;; | 
|---|
| [1513] | 81 | "--var") | 
|---|
|  | 82 | shift | 
|---|
|  | 83 | VAR_OPT="${VAR_OPT} $1" | 
|---|
| [1517] | 84 | ERR_REDIR=2 | 
|---|
|  | 85 | DBG_REDIR=2 | 
|---|
| [1513] | 86 | ;; | 
|---|
| [1517] | 87 | "--value-only") | 
|---|
|  | 88 | VALUE_ONLY_OPT="true" | 
|---|
|  | 89 | ;; | 
|---|
|  | 90 | "--name-and-value") | 
|---|
|  | 91 | VALUE_ONLY_OPT= | 
|---|
|  | 92 | ;; | 
|---|
| [1530] | 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 |  | 
|---|
| [1512] | 109 | "--help") | 
|---|
| [1517] | 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 "" | 
|---|
| [1570] | 117 | echo "The first form will execute the command, or if no command is given start" | 
|---|
| [1517] | 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:" | 
|---|
| [1530] | 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" | 
|---|
| [1517] | 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" | 
|---|
| [1570] | 134 | echo "      Include legacy variables in result. Default: --no-legacy" | 
|---|
| [1517] | 135 | echo "  --value-only, --name-and-value" | 
|---|
|  | 136 | echo "      Controls what the result of a --var query. Default: --name-and-value" | 
|---|
| [1530] | 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" | 
|---|
| [1517] | 141 | echo "" | 
|---|
| [1512] | 142 | exit 1 | 
|---|
|  | 143 | ;; | 
|---|
|  | 144 | *) | 
|---|
|  | 145 | break | 
|---|
|  | 146 | ;; | 
|---|
|  | 147 | esac | 
|---|
| [1510] | 148 | shift | 
|---|
| [1512] | 149 | done | 
|---|
| [1510] | 150 |  | 
|---|
|  | 151 |  | 
|---|
|  | 152 | # | 
|---|
| [1517] | 153 | # Deal with legacy environment variables. | 
|---|
| [992] | 154 | # | 
|---|
| [1517] | 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} | 
|---|
|  | 158 | sleep 1 | 
|---|
|  | 159 | exit 1 | 
|---|
|  | 160 | fi | 
|---|
|  | 161 | KBUILD_PATH=$PATH_KBUILD | 
|---|
| [224] | 162 | fi | 
|---|
| [1517] | 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} | 
|---|
|  | 166 | sleep 1 | 
|---|
|  | 167 | exit 1 | 
|---|
|  | 168 | fi | 
|---|
|  | 169 | KBUILD_BIN_PATH=$PATH_KBUILD_BIN | 
|---|
| [224] | 170 | fi | 
|---|
|  | 171 |  | 
|---|
| [1517] | 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} | 
|---|
|  | 175 | sleep 1 | 
|---|
|  | 176 | exit 1 | 
|---|
|  | 177 | fi | 
|---|
|  | 178 | KBUILD_TYPE=$BUILD_TYPE | 
|---|
|  | 179 | fi | 
|---|
| [1076] | 180 |  | 
|---|
| [1517] | 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} | 
|---|
|  | 184 | sleep 1 | 
|---|
|  | 185 | exit 1 | 
|---|
|  | 186 | fi | 
|---|
|  | 187 | KBUILD_HOST=$BUILD_PLATFORM | 
|---|
|  | 188 | fi | 
|---|
|  | 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} | 
|---|
|  | 192 | sleep 1 | 
|---|
|  | 193 | exit 1 | 
|---|
|  | 194 | fi | 
|---|
|  | 195 | KBUILD_HOST_ARCH=$BUILD_PLATFORM_ARCH | 
|---|
|  | 196 | fi | 
|---|
|  | 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} | 
|---|
|  | 200 | sleep 1 | 
|---|
|  | 201 | exit 1 | 
|---|
|  | 202 | fi | 
|---|
|  | 203 | KBUILD_HOST_CPU=$BUILD_PLATFORM_CPU | 
|---|
|  | 204 | fi | 
|---|
|  | 205 |  | 
|---|
|  | 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} | 
|---|
|  | 209 | sleep 1 | 
|---|
|  | 210 | exit 1 | 
|---|
|  | 211 | fi | 
|---|
|  | 212 | KBUILD_TARGET=$BUILD_TARGET | 
|---|
|  | 213 | fi | 
|---|
|  | 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} | 
|---|
|  | 217 | sleep 1 | 
|---|
|  | 218 | exit 1 | 
|---|
|  | 219 | fi | 
|---|
|  | 220 | KBUILD_TARGET_ARCH=$BUILD_TARGET_ARCH | 
|---|
|  | 221 | fi | 
|---|
|  | 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} | 
|---|
|  | 225 | sleep 1 | 
|---|
|  | 226 | exit 1 | 
|---|
|  | 227 | fi | 
|---|
|  | 228 | KBUILD_TARGET_CPU=$BUILD_TARGET_CPU | 
|---|
|  | 229 | fi | 
|---|
|  | 230 |  | 
|---|
|  | 231 |  | 
|---|
| [992] | 232 | # | 
|---|
|  | 233 | # Set default build type. | 
|---|
|  | 234 | # | 
|---|
| [1517] | 235 | if test -z "$KBUILD_TYPE"; then | 
|---|
|  | 236 | KBUILD_TYPE=release | 
|---|
| [224] | 237 | fi | 
|---|
| [1517] | 238 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TYPE=$KBUILD_TYPE" 1>&${DBG_REDIR} | 
|---|
| [224] | 239 |  | 
|---|
| [992] | 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 | # | 
|---|
| [1517] | 247 | if test -z "$KBUILD_HOST"; then | 
|---|
|  | 248 | KBUILD_HOST=`uname` | 
|---|
|  | 249 | case "$KBUILD_HOST" in | 
|---|
| [994] | 250 | linux|Linux|GNU/Linux|LINUX) | 
|---|
| [1517] | 251 | KBUILD_HOST=linux | 
|---|
| [994] | 252 | ;; | 
|---|
|  | 253 |  | 
|---|
|  | 254 | os2|OS/2|OS2) | 
|---|
| [1517] | 255 | KBUILD_HOST=os2 | 
|---|
| [994] | 256 | ;; | 
|---|
|  | 257 |  | 
|---|
|  | 258 | freebsd|FreeBSD|FREEBSD) | 
|---|
| [1517] | 259 | KBUILD_HOST=freebsd | 
|---|
| [994] | 260 | ;; | 
|---|
|  | 261 |  | 
|---|
|  | 262 | openbsd|OpenBSD|OPENBSD) | 
|---|
| [1517] | 263 | KBUILD_HOST=openbsd | 
|---|
| [994] | 264 | ;; | 
|---|
|  | 265 |  | 
|---|
|  | 266 | netbsd|NetBSD|NETBSD) | 
|---|
| [1517] | 267 | KBUILD_HOST=netbsd | 
|---|
| [994] | 268 | ;; | 
|---|
|  | 269 |  | 
|---|
|  | 270 | Darwin|darwin) | 
|---|
| [1517] | 271 | KBUILD_HOST=darwin | 
|---|
| [994] | 272 | ;; | 
|---|
|  | 273 |  | 
|---|
|  | 274 | SunOS) | 
|---|
| [1517] | 275 | KBUILD_HOST=solaris | 
|---|
| [994] | 276 | ;; | 
|---|
|  | 277 |  | 
|---|
|  | 278 | WindowsNT|CYGWIN_NT-*) | 
|---|
| [1517] | 279 | KBUILD_HOST=win | 
|---|
| [994] | 280 | ;; | 
|---|
|  | 281 |  | 
|---|
|  | 282 | *) | 
|---|
| [1517] | 283 | echo "$0: unknown os $KBUILD_HOST" 1>&${ERR_REDIR} | 
|---|
| [994] | 284 | sleep 1 | 
|---|
|  | 285 | exit 1 | 
|---|
|  | 286 | ;; | 
|---|
|  | 287 | esac | 
|---|
|  | 288 | fi | 
|---|
| [1517] | 289 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST=$KBUILD_HOST" 1>&${DBG_REDIR} | 
|---|
| [994] | 290 |  | 
|---|
| [1517] | 291 | if test -z "$KBUILD_HOST_ARCH"; then | 
|---|
| [992] | 292 | # Try deduce it from the cpu if given. | 
|---|
| [1517] | 293 | if test -n "$KBUILD_HOST_CPU"; then | 
|---|
|  | 294 | case "$KBUILD_HOST_CPU" in | 
|---|
| [992] | 295 | i[3456789]86) | 
|---|
| [1517] | 296 | KBUILD_HOST_ARCH='x86' | 
|---|
| [992] | 297 | ;; | 
|---|
|  | 298 | k8|k8l|k9|k10) | 
|---|
| [1517] | 299 | KBUILD_HOST_ARCH='amd64' | 
|---|
| [992] | 300 | ;; | 
|---|
|  | 301 | esac | 
|---|
|  | 302 | fi | 
|---|
| [224] | 303 | fi | 
|---|
| [1517] | 304 | if test -z "$KBUILD_HOST_ARCH"; then | 
|---|
| [1156] | 305 | # Use uname -m or isainfo (lots of guesses here, please help clean this up...) | 
|---|
| [1517] | 306 | if test "$KBUILD_HOST" = "solaris"; then | 
|---|
|  | 307 | KBUILD_HOST_ARCH=`isainfo | cut -f 1 -d ' '` | 
|---|
| [1531] | 308 |  | 
|---|
| [1156] | 309 | else | 
|---|
| [1517] | 310 | KBUILD_HOST_ARCH=`uname -m` | 
|---|
| [1156] | 311 | fi | 
|---|
| [1517] | 312 | case "$KBUILD_HOST_ARCH" in | 
|---|
| [992] | 313 | x86_64|AMD64|amd64|k8|k8l|k9|k10) | 
|---|
| [1517] | 314 | KBUILD_HOST_ARCH='amd64' | 
|---|
| [992] | 315 | ;; | 
|---|
|  | 316 | x86|i86pc|ia32|i[3456789]86) | 
|---|
| [1517] | 317 | KBUILD_HOST_ARCH='x86' | 
|---|
| [224] | 318 | ;; | 
|---|
| [992] | 319 | sparc32|sparc) | 
|---|
| [1517] | 320 | KBUILD_HOST_ARCH='sparc32' | 
|---|
| [299] | 321 | ;; | 
|---|
| [992] | 322 | sparc64) | 
|---|
| [1517] | 323 | KBUILD_HOST_ARCH='sparc64' | 
|---|
| [992] | 324 | ;; | 
|---|
|  | 325 | s390) | 
|---|
| [1517] | 326 | KBUILD_HOST_ARCH='s390' | 
|---|
| [992] | 327 | ;; | 
|---|
| [1380] | 328 | s390x) | 
|---|
| [1517] | 329 | KBUILD_HOST_ARCH='s390x' | 
|---|
| [1380] | 330 | ;; | 
|---|
| [992] | 331 | ppc32|ppc|powerpc) | 
|---|
| [1517] | 332 | KBUILD_HOST_ARCH='ppc32' | 
|---|
| [992] | 333 | ;; | 
|---|
|  | 334 | ppc64|powerpc64) | 
|---|
| [1517] | 335 | KBUILD_HOST_ARCH='ppc64' | 
|---|
| [992] | 336 | ;; | 
|---|
|  | 337 | mips32|mips) | 
|---|
| [1517] | 338 | KBUILD_HOST_ARCH='mips32' | 
|---|
| [992] | 339 | ;; | 
|---|
|  | 340 | mips64) | 
|---|
| [1517] | 341 | KBUILD_HOST_ARCH='mips64' | 
|---|
| [992] | 342 | ;; | 
|---|
|  | 343 | ia64) | 
|---|
| [1517] | 344 | KBUILD_HOST_ARCH='ia64' | 
|---|
| [992] | 345 | ;; | 
|---|
|  | 346 | #hppa32|hppa|parisc32|parisc)? | 
|---|
|  | 347 | hppa32|parisc32) | 
|---|
| [1517] | 348 | KBUILD_HOST_ARCH='hppa32' | 
|---|
| [992] | 349 | ;; | 
|---|
|  | 350 | hppa64|parisc64) | 
|---|
| [1517] | 351 | KBUILD_HOST_ARCH='hppa64' | 
|---|
| [992] | 352 | ;; | 
|---|
| [1380] | 353 | arm|armv4l|armv5tel) | 
|---|
| [1517] | 354 | KBUILD_HOST_ARCH='arm' | 
|---|
| [992] | 355 | ;; | 
|---|
|  | 356 | alpha) | 
|---|
| [1517] | 357 | KBUILD_HOST_ARCH='alpha' | 
|---|
| [992] | 358 | ;; | 
|---|
|  | 359 |  | 
|---|
| [1517] | 360 | *)  echo "$0: unknown cpu/arch - $KBUILD_HOST_ARCH" 1>&${ERR_REDIR} | 
|---|
| [224] | 361 | sleep 1 | 
|---|
|  | 362 | exit 1 | 
|---|
|  | 363 | ;; | 
|---|
|  | 364 | esac | 
|---|
|  | 365 |  | 
|---|
|  | 366 | fi | 
|---|
| [1517] | 367 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_ARCH=$KBUILD_HOST_ARCH" 1>&${DBG_REDIR} | 
|---|
| [224] | 368 |  | 
|---|
| [1517] | 369 | if test -z "$KBUILD_HOST_CPU"; then | 
|---|
|  | 370 | KBUILD_HOST_CPU="blend" | 
|---|
| [992] | 371 | fi | 
|---|
| [1517] | 372 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_CPU=$KBUILD_HOST_CPU" 1>&${DBG_REDIR} | 
|---|
| [224] | 373 |  | 
|---|
| [992] | 374 | # | 
|---|
|  | 375 | # The target platform. | 
|---|
|  | 376 | # Defaults to the host when not specified. | 
|---|
|  | 377 | # | 
|---|
| [1517] | 378 | if test -z "$KBUILD_TARGET"; then | 
|---|
|  | 379 | KBUILD_TARGET="$KBUILD_HOST" | 
|---|
| [224] | 380 | fi | 
|---|
| [1517] | 381 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET=$KBUILD_TARGET" 1>&${DBG_REDIR} | 
|---|
| [224] | 382 |  | 
|---|
| [1517] | 383 | if test -z "$KBUILD_TARGET_ARCH"; then | 
|---|
|  | 384 | KBUILD_TARGET_ARCH="$KBUILD_HOST_ARCH" | 
|---|
| [224] | 385 | fi | 
|---|
| [1517] | 386 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH" 1>&${DBG_REDIR} | 
|---|
| [224] | 387 |  | 
|---|
| [1517] | 388 | if test -z "$KBUILD_TARGET_CPU"; then | 
|---|
|  | 389 | if test "$KBUILD_TARGET_ARCH" = "$KBUILD_HOST_ARCH"; then | 
|---|
|  | 390 | KBUILD_TARGET_CPU="$KBUILD_HOST_CPU" | 
|---|
| [994] | 391 | else | 
|---|
| [1517] | 392 | KBUILD_TARGET_CPU="blend" | 
|---|
| [994] | 393 | fi | 
|---|
| [224] | 394 | fi | 
|---|
| [1517] | 395 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_CPU=$KBUILD_TARGET_CPU" 1>&${DBG_REDIR} | 
|---|
| [224] | 396 |  | 
|---|
| [1517] | 397 | # | 
|---|
| [224] | 398 | # Determin executable extension and path separator. | 
|---|
| [1517] | 399 | # | 
|---|
| [224] | 400 | _SUFF_EXE= | 
|---|
|  | 401 | _PATH_SEP=":" | 
|---|
| [1517] | 402 | case "$KBUILD_HOST" in | 
|---|
| [992] | 403 | os2|win|nt) | 
|---|
| [224] | 404 | _SUFF_EXE=".exe" | 
|---|
|  | 405 | _PATH_SEP=";" | 
|---|
|  | 406 | ;; | 
|---|
|  | 407 | esac | 
|---|
|  | 408 |  | 
|---|
| [1076] | 409 | # | 
|---|
| [1517] | 410 | # Determin KBUILD_PATH from the script location and calc KBUILD_BIN_PATH from there. | 
|---|
| [1076] | 411 | # | 
|---|
| [1517] | 412 | if test -z "$KBUILD_PATH"; then | 
|---|
|  | 413 | KBUILD_PATH=`dirname "$0"` | 
|---|
|  | 414 | KBUILD_PATH=`cd "$KBUILD_PATH" ; /bin/pwd` | 
|---|
| [1076] | 415 | fi | 
|---|
| [1517] | 416 | if test ! -f "$KBUILD_PATH/footer.kmk" -o ! -f "$KBUILD_PATH/header.kmk" -o ! -f "$KBUILD_PATH/rules.kmk"; then | 
|---|
|  | 417 | echo "$0: error: KBUILD_PATH ($KBUILD_PATH) is not pointing to a popluated kBuild directory." 1>&${ERR_REDIR} | 
|---|
|  | 418 | sleep 1 | 
|---|
|  | 419 | exit 1 | 
|---|
|  | 420 | fi | 
|---|
|  | 421 | test -n "$DBG_OPT" && echo "dbg: KBUILD_PATH=$KBUILD_PATH" 1>&${DBG_REDIR} | 
|---|
| [1076] | 422 |  | 
|---|
| [1517] | 423 | if test -z "$KBUILD_BIN_PATH"; then | 
|---|
|  | 424 | KBUILD_BIN_PATH="${KBUILD_PATH}/bin/${KBUILD_HOST}.${KBUILD_HOST_ARCH}" | 
|---|
| [1510] | 425 | fi | 
|---|
| [1517] | 426 | test -n "$DBG_OPT" && echo "dbg: KBUILD_BIN_PATH=${KBUILD_BIN_PATH}" 1>&${DBG_REDIR} | 
|---|
| [224] | 427 |  | 
|---|
| [992] | 428 | # | 
|---|
|  | 429 | # Add the bin/x.y/ directory to the PATH. | 
|---|
|  | 430 | # NOTE! Once bootstrapped this is the only thing that is actually necessary. | 
|---|
|  | 431 | # | 
|---|
| [1517] | 432 | PATH="${KBUILD_BIN_PATH}${_PATH_SEP}$PATH" | 
|---|
| [1510] | 433 | test -n "$DBG_OPT" && echo "dbg: PATH=$PATH" 1>&${DBG_REDIR} | 
|---|
| [224] | 434 |  | 
|---|
| [1517] | 435 | # | 
|---|
| [224] | 436 | # Sanity and x bits. | 
|---|
| [1517] | 437 | # | 
|---|
|  | 438 | if test ! -d "${KBUILD_BIN_PATH}/"; then | 
|---|
| [1531] | 439 | echo "$0: warning: The bin directory for this platform doesn't exist. (${KBUILD_BIN_PATH}/)" 1>&${ERR_REDIR} | 
|---|
| [224] | 440 | else | 
|---|
| [731] | 441 | 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] | 442 | do | 
|---|
| [1517] | 443 | chmod a+x ${KBUILD_BIN_PATH}/${prog} > /dev/null 2>&1 | 
|---|
|  | 444 | if test ! -f "${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE}"; then | 
|---|
|  | 445 | echo "$0: warning: The ${prog} program doesn't exist for this platform. (${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE})" 1>&${ERR_REDIR} | 
|---|
| [224] | 446 | fi | 
|---|
|  | 447 | done | 
|---|
|  | 448 | fi | 
|---|
|  | 449 |  | 
|---|
| [1517] | 450 | # | 
|---|
|  | 451 | # The environment is in place, now take the requested action. | 
|---|
|  | 452 | # | 
|---|
| [1542] | 453 | MY_RC=0 | 
|---|
| [1513] | 454 | if test -n "${VAR_OPT}"; then | 
|---|
|  | 455 | # Echo variable values or variable export statements. | 
|---|
|  | 456 | for var in ${VAR_OPT}; | 
|---|
|  | 457 | do | 
|---|
|  | 458 | val= | 
|---|
| [1531] | 459 | case "$var" in | 
|---|
|  | 460 | PATH) | 
|---|
|  | 461 | val=$PATH | 
|---|
| [1513] | 462 | ;; | 
|---|
| [1531] | 463 | KBUILD_PATH) | 
|---|
|  | 464 | val=$KBUILD_PATH | 
|---|
| [1513] | 465 | ;; | 
|---|
| [1531] | 466 | KBUILD_BIN_PATH) | 
|---|
| [1517] | 467 | val=$KBUILD_BIN_PATH | 
|---|
| [1513] | 468 | ;; | 
|---|
| [1531] | 469 | KBUILD_HOST) | 
|---|
|  | 470 | val=$KBUILD_HOST | 
|---|
| [1513] | 471 | ;; | 
|---|
| [1531] | 472 | KBUILD_HOST_ARCH) | 
|---|
| [1517] | 473 | val=$KBUILD_HOST_ARCH | 
|---|
| [1513] | 474 | ;; | 
|---|
| [1531] | 475 | KBUILD_HOST_CPU) | 
|---|
| [1517] | 476 | val=$KBUILD_HOST_CPU | 
|---|
| [1513] | 477 | ;; | 
|---|
| [1531] | 478 | KBUILD_TARGET) | 
|---|
|  | 479 | val=$KBUILD_TARGET | 
|---|
| [1513] | 480 | ;; | 
|---|
| [1531] | 481 | KBUILD_TARGET_ARCH) | 
|---|
| [1517] | 482 | val=$KBUILD_TARGET_ARCH | 
|---|
| [1513] | 483 | ;; | 
|---|
| [1531] | 484 | KBUILD_TARGET_CPU) | 
|---|
| [1517] | 485 | val=$KBUILD_TARGET_CPU | 
|---|
| [1513] | 486 | ;; | 
|---|
| [1531] | 487 | KBUILD_TYPE) | 
|---|
| [1517] | 488 | val=$KBUILD_TYPE | 
|---|
| [1513] | 489 | ;; | 
|---|
| [1531] | 490 | *) | 
|---|
| [1513] | 491 | echo "$0: error: Unknown variable $var specified in --var request." 1>&${ERR_REDIR} | 
|---|
|  | 492 | sleep 1 | 
|---|
|  | 493 | exit 1 | 
|---|
|  | 494 | ;; | 
|---|
|  | 495 | esac | 
|---|
| [1512] | 496 |  | 
|---|
| [1513] | 497 | if test -n "$EVAL_OPT"; then | 
|---|
| [1530] | 498 | echo "${EVAL_EXPORT} $var=$val" | 
|---|
| [1513] | 499 | else | 
|---|
| [1517] | 500 | if test -n "$VALUE_ONLY_OPT"; then | 
|---|
|  | 501 | echo "$val" | 
|---|
|  | 502 | else | 
|---|
|  | 503 | echo "$var=$val" | 
|---|
|  | 504 | fi | 
|---|
| [1510] | 505 | fi | 
|---|
| [1513] | 506 | done | 
|---|
|  | 507 | else | 
|---|
|  | 508 | if test -n "$EVAL_OPT"; then | 
|---|
|  | 509 | # Echo statements for the shell to evaluate. | 
|---|
|  | 510 | test -n "$DBG_OPT" && echo "dbg: echoing exported variables" 1>&${DBG_REDIR} | 
|---|
| [1530] | 511 | echo "${EVAL_EXPORT} PATH=${PATH}" | 
|---|
|  | 512 | test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && echo "${EVAL_EXPORT} KBUILD_TYPE=${KBUILD_TYPE}" | 
|---|
| [1513] | 513 | if test -n "${FULL_OPT}"; then | 
|---|
| [1530] | 514 | echo "${EVAL_EXPORT} KBUILD_PATH=${KBUILD_PATH}" | 
|---|
|  | 515 | echo "${EVAL_EXPORT} KBUILD_HOST=${KBUILD_HOST}" | 
|---|
|  | 516 | echo "${EVAL_EXPORT} KBUILD_HOST_ARCH=${KBUILD_HOST_ARCH}" | 
|---|
|  | 517 | echo "${EVAL_EXPORT} KBUILD_HOST_CPU=${KBUILD_HOST_CPU}" | 
|---|
|  | 518 | echo "${EVAL_EXPORT} KBUILD_TARGET=${KBUILD_TARGET}" | 
|---|
|  | 519 | echo "${EVAL_EXPORT} KBUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}" | 
|---|
|  | 520 | echo "${EVAL_EXPORT} KBUILD_TARGET_CPU=${KBUILD_TARGET_CPU}" | 
|---|
| [1517] | 521 |  | 
|---|
|  | 522 | if test -n "${LEGACY_OPT}"; then | 
|---|
| [1530] | 523 | echo "${EVAL_EXPORT} PATH_KBUILD=${KBUILD_PATH}" | 
|---|
|  | 524 | echo "${EVAL_EXPORT} BUILD_TYPE=${KBUILD_TYPE}" | 
|---|
|  | 525 | echo "${EVAL_EXPORT} BUILD_PLATFORM=${KBUILD_HOST}" | 
|---|
|  | 526 | echo "${EVAL_EXPORT} BUILD_PLATFORM_ARCH=${KBUILD_HOST_ARCH}" | 
|---|
|  | 527 | echo "${EVAL_EXPORT} BUILD_PLATFORM_CPU=${KBUILD_HOST_CPU}" | 
|---|
|  | 528 | echo "${EVAL_EXPORT} BUILD_TARGET=${KBUILD_TARGET}" | 
|---|
|  | 529 | echo "${EVAL_EXPORT} BUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}" | 
|---|
|  | 530 | echo "${EVAL_EXPORT} BUILD_TARGET_CPU=${KBUILD_TARGET_CPU}" | 
|---|
| [1517] | 531 | fi | 
|---|
| [1513] | 532 | fi | 
|---|
| [1510] | 533 | else | 
|---|
| [1513] | 534 | # Export variables. | 
|---|
|  | 535 | export PATH | 
|---|
| [1530] | 536 | test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && export KBUILD_TYPE | 
|---|
| [1513] | 537 | if test -n "${FULL_OPT}"; then | 
|---|
| [1517] | 538 | export KBUILD_PATH | 
|---|
|  | 539 | export KBUILD_HOST | 
|---|
|  | 540 | export KBUILD_HOST_ARCH | 
|---|
|  | 541 | export KBUILD_HOST_CPU | 
|---|
|  | 542 | export KBUILD_TARGET | 
|---|
|  | 543 | export KBUILD_TARGET_ARCH | 
|---|
|  | 544 | export KBUILD_TARGET_CPU | 
|---|
|  | 545 |  | 
|---|
|  | 546 | if test -n "${LEGACY_OPT}"; then | 
|---|
|  | 547 | export PATH_KBUILD=$KBUILD_PATH | 
|---|
|  | 548 | export BUILD_TYPE=$KBUILD_TYPE | 
|---|
|  | 549 | export BUILD_PLATFORM=$KBUILD_HOST | 
|---|
|  | 550 | export BUILD_PLATFORM_ARCH=$KBUILD_HOST_ARCH | 
|---|
|  | 551 | export BUILD_PLATFORM_CPU=$KBUILD_HOST_CPU | 
|---|
|  | 552 | export BUILD_TARGET=$KBUILD_TARGET | 
|---|
|  | 553 | export BUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH | 
|---|
|  | 554 | export BUILD_TARGET_CPU=$KBUILD_TARGET_CPU | 
|---|
|  | 555 | fi | 
|---|
| [1513] | 556 | fi | 
|---|
| [1531] | 557 |  | 
|---|
| [1513] | 558 | # Execute command or spawn shell. | 
|---|
|  | 559 | if test $# -eq 0; then | 
|---|
|  | 560 | test -z "${QUIET_OPT}" && echo "$0: info: Spawning work shell..." 1>&${ERR_REDIR} | 
|---|
|  | 561 | if test "$TERM" != 'dumb'  -a  -n "$BASH"; then | 
|---|
|  | 562 | export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]' | 
|---|
|  | 563 | fi | 
|---|
|  | 564 | $SHELL -i | 
|---|
| [1542] | 565 | MY_RC=$? | 
|---|
| [1513] | 566 | else | 
|---|
|  | 567 | test -z "${QUIET_OPT}" && echo "$0: info: Executing command: $*" 1>&${ERR_REDIR} | 
|---|
|  | 568 | $* | 
|---|
| [1542] | 569 | MY_RC=$? | 
|---|
|  | 570 | test -z "${QUIET_OPT}" -a "$MY_RC" -ne 0 && echo "$0: info: rc=$MY_RC: $*" 1>&${ERR_REDIR} | 
|---|
| [1513] | 571 | fi | 
|---|
| [224] | 572 | fi | 
|---|
|  | 573 | fi | 
|---|
| [1542] | 574 | test -n "$DBG_OPT" && echo "dbg: finished (rc=$MY_RC)" 1>&${DBG_REDIR} | 
|---|
|  | 575 | exit $MY_RC | 
|---|
| [731] | 576 |  | 
|---|