| 1 | #!/bin/sh
 | 
|---|
| 2 | # $Id: env.sh 3609 2024-09-12 20:36:11Z bird $
 | 
|---|
| 3 | ## @file
 | 
|---|
| 4 | # Environment setup script.
 | 
|---|
| 5 | #
 | 
|---|
| 6 | 
 | 
|---|
| 7 | #
 | 
|---|
| 8 | # Copyright (c) 2005-2010 knut st. osmundsen <bird-kBuild-spamx@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 | #
 | 
|---|
| 32 | ERR_REDIR=1
 | 
|---|
| 33 | DBG_REDIR=1
 | 
|---|
| 34 | EVAL_OPT=
 | 
|---|
| 35 | EVAL_EXPORT="export "
 | 
|---|
| 36 | DBG_OPT=
 | 
|---|
| 37 | QUIET_OPT=
 | 
|---|
| 38 | FULL_OPT=
 | 
|---|
| 39 | FULL_WITH_BIN_OPT=
 | 
|---|
| 40 | LEGACY_OPT=
 | 
|---|
| 41 | VAR_OPT=
 | 
|---|
| 42 | VALUE_ONLY_OPT=
 | 
|---|
| 43 | EXP_TYPE_OPT=
 | 
|---|
| 44 | while test $# -gt 0;
 | 
|---|
| 45 | do
 | 
|---|
| 46 |     case "$1" in
 | 
|---|
| 47 |         "--debug-script")
 | 
|---|
| 48 |             DBG_OPT="true"
 | 
|---|
| 49 |             ;;
 | 
|---|
| 50 |         "--no-debug-script")
 | 
|---|
| 51 |             DBG_OPT=
 | 
|---|
| 52 |             ;;
 | 
|---|
| 53 |         "--quiet")
 | 
|---|
| 54 |             QUIET_OPT="true"
 | 
|---|
| 55 |             ;;
 | 
|---|
| 56 |         "--verbose")
 | 
|---|
| 57 |             QUIET_OPT=
 | 
|---|
| 58 |             ;;
 | 
|---|
| 59 |         "--full")
 | 
|---|
| 60 |             FULL_OPT="true"
 | 
|---|
| 61 |             ;;
 | 
|---|
| 62 |         "--full-with-bin")
 | 
|---|
| 63 |             FULL_OPT="true"
 | 
|---|
| 64 |             FULL_WITH_BIN_OPT="true"
 | 
|---|
| 65 |             ;;
 | 
|---|
| 66 |         "--normal")
 | 
|---|
| 67 |             FULL_OPT=
 | 
|---|
| 68 |             ;;
 | 
|---|
| 69 |         "--legacy")
 | 
|---|
| 70 |             LEGACY_OPT="true"
 | 
|---|
| 71 |             ;;
 | 
|---|
| 72 |         "--no-legacy")
 | 
|---|
| 73 |             LEGACY_OPT=
 | 
|---|
| 74 |             ;;
 | 
|---|
| 75 |         "--eval")
 | 
|---|
| 76 |             EVAL_OPT="true"
 | 
|---|
| 77 |             ERR_REDIR=2
 | 
|---|
| 78 |             DBG_REDIR=2
 | 
|---|
| 79 |             ;;
 | 
|---|
| 80 |         "--set")
 | 
|---|
| 81 |             EVAL_OPT="true"
 | 
|---|
| 82 |             EVAL_EXPORT=""
 | 
|---|
| 83 |             ERR_REDIR=2
 | 
|---|
| 84 |             DBG_REDIR=2
 | 
|---|
| 85 |             ;;
 | 
|---|
| 86 |         "--var")
 | 
|---|
| 87 |             shift
 | 
|---|
| 88 |             VAR_OPT="${VAR_OPT} $1"
 | 
|---|
| 89 |             ERR_REDIR=2
 | 
|---|
| 90 |             DBG_REDIR=2
 | 
|---|
| 91 |             ;;
 | 
|---|
| 92 |         "--value-only")
 | 
|---|
| 93 |             VALUE_ONLY_OPT="true"
 | 
|---|
| 94 |             ;;
 | 
|---|
| 95 |         "--name-and-value")
 | 
|---|
| 96 |             VALUE_ONLY_OPT=
 | 
|---|
| 97 |             ;;
 | 
|---|
| 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 | 
 | 
|---|
| 114 |         "--help")
 | 
|---|
| 115 |             echo "kBuild Environment Setup Script, v0.2.0-pre"
 | 
|---|
| 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 ""
 | 
|---|
| 122 |             echo "The first form will execute the command, or if no command is given start"
 | 
|---|
| 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"
 | 
|---|
| 126 |             echo "evaluation."
 | 
|---|
| 127 |             echo "The forth form will only print the specified variable(s)."
 | 
|---|
| 128 |             echo ""
 | 
|---|
| 129 |             echo "Options:"
 | 
|---|
| 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"
 | 
|---|
| 134 |             echo "  --quiet, --verbose"
 | 
|---|
| 135 |             echo "      Controls informational output. Default: --verbose"
 | 
|---|
| 136 |             echo "  --full, --full-with-bin, --normal"
 | 
|---|
| 137 |             echo "      Controls the variable set. Default: --normal"
 | 
|---|
| 138 |             echo "  --legacy, --no-legacy"
 | 
|---|
| 139 |             echo "      Include legacy variables in result. Default: --no-legacy"
 | 
|---|
| 140 |             echo "  --value-only, --name-and-value"
 | 
|---|
| 141 |             echo "      Controls what the result of a --var query. Default: --name-and-value"
 | 
|---|
| 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"
 | 
|---|
| 145 |             echo '      is useful for eval `env.sh`. Default: --export'
 | 
|---|
| 146 |             echo ""
 | 
|---|
| 147 |             exit 1
 | 
|---|
| 148 |             ;;
 | 
|---|
| 149 |         *)
 | 
|---|
| 150 |             break
 | 
|---|
| 151 |             ;;
 | 
|---|
| 152 |     esac
 | 
|---|
| 153 |     shift
 | 
|---|
| 154 | done
 | 
|---|
| 155 | 
 | 
|---|
| 156 | 
 | 
|---|
| 157 | #
 | 
|---|
| 158 | # Deal with legacy environment variables.
 | 
|---|
| 159 | #
 | 
|---|
| 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
 | 
|---|
| 167 | fi
 | 
|---|
| 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
 | 
|---|
| 175 | fi
 | 
|---|
| 176 | 
 | 
|---|
| 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
 | 
|---|
| 185 | 
 | 
|---|
| 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 | 
 | 
|---|
| 237 | #
 | 
|---|
| 238 | # Set default build type.
 | 
|---|
| 239 | #
 | 
|---|
| 240 | if test -z "$KBUILD_TYPE"; then
 | 
|---|
| 241 |     KBUILD_TYPE=release
 | 
|---|
| 242 | fi
 | 
|---|
| 243 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TYPE=$KBUILD_TYPE" 1>&${DBG_REDIR}
 | 
|---|
| 244 | 
 | 
|---|
| 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 | #
 | 
|---|
| 252 | if test -z "$KBUILD_HOST"; then
 | 
|---|
| 253 |     KBUILD_HOST=`uname`
 | 
|---|
| 254 |     case "$KBUILD_HOST" in
 | 
|---|
| 255 |         Darwin|darwin)
 | 
|---|
| 256 |             KBUILD_HOST=darwin
 | 
|---|
| 257 |             ;;
 | 
|---|
| 258 | 
 | 
|---|
| 259 |         DragonFly)
 | 
|---|
| 260 |             KBUILD_HOST=dragonfly
 | 
|---|
| 261 |             ;;
 | 
|---|
| 262 | 
 | 
|---|
| 263 |         freebsd|FreeBSD|FREEBSD)
 | 
|---|
| 264 |             KBUILD_HOST=freebsd
 | 
|---|
| 265 |             ;;
 | 
|---|
| 266 | 
 | 
|---|
| 267 |         GNU)
 | 
|---|
| 268 |             KBUILD_HOST=gnuhurd
 | 
|---|
| 269 |             ;;
 | 
|---|
| 270 | 
 | 
|---|
| 271 |         GNU/kFreeBSD)
 | 
|---|
| 272 |             KBUILD_HOST=gnukfbsd
 | 
|---|
| 273 |             ;;
 | 
|---|
| 274 | 
 | 
|---|
| 275 |         GNU/kNetBSD|GNU/NetBSD)
 | 
|---|
| 276 |             KBUILD_HOST=gnuknbsd
 | 
|---|
| 277 |             ;;
 | 
|---|
| 278 | 
 | 
|---|
| 279 |         Haiku)
 | 
|---|
| 280 |             KBUILD_HOST=haiku
 | 
|---|
| 281 |             ;;
 | 
|---|
| 282 | 
 | 
|---|
| 283 |         linux|Linux|GNU/Linux|LINUX)
 | 
|---|
| 284 |             KBUILD_HOST=linux
 | 
|---|
| 285 |             ;;
 | 
|---|
| 286 | 
 | 
|---|
| 287 |         netbsd|NetBSD|NETBSD)
 | 
|---|
| 288 |             KBUILD_HOST=netbsd
 | 
|---|
| 289 |             ;;
 | 
|---|
| 290 | 
 | 
|---|
| 291 |         openbsd|OpenBSD|OPENBSD)
 | 
|---|
| 292 |             KBUILD_HOST=openbsd
 | 
|---|
| 293 |             ;;
 | 
|---|
| 294 | 
 | 
|---|
| 295 |         os2|OS/2|OS2)
 | 
|---|
| 296 |             KBUILD_HOST=os2
 | 
|---|
| 297 |             ;;
 | 
|---|
| 298 | 
 | 
|---|
| 299 |         SunOS)
 | 
|---|
| 300 |             KBUILD_HOST=solaris
 | 
|---|
| 301 |             ;;
 | 
|---|
| 302 | 
 | 
|---|
| 303 |         WindowsNT|CYGWIN_NT-*)
 | 
|---|
| 304 |             KBUILD_HOST=win
 | 
|---|
| 305 |             ;;
 | 
|---|
| 306 | 
 | 
|---|
| 307 |         *)
 | 
|---|
| 308 |             echo "$0: unknown os $KBUILD_HOST" 1>&${ERR_REDIR}
 | 
|---|
| 309 |             sleep 1
 | 
|---|
| 310 |             exit 1
 | 
|---|
| 311 |             ;;
 | 
|---|
| 312 |     esac
 | 
|---|
| 313 | fi
 | 
|---|
| 314 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST=$KBUILD_HOST" 1>&${DBG_REDIR}
 | 
|---|
| 315 | 
 | 
|---|
| 316 | if test -z "$KBUILD_HOST_ARCH"; then
 | 
|---|
| 317 |     # Try deduce it from the cpu if given.
 | 
|---|
| 318 |     if test -n "$KBUILD_HOST_CPU"; then
 | 
|---|
| 319 |         case "$KBUILD_HOST_CPU" in
 | 
|---|
| 320 |             i[3456789]86)
 | 
|---|
| 321 |                 KBUILD_HOST_ARCH='x86'
 | 
|---|
| 322 |                 ;;
 | 
|---|
| 323 |             k8|k8l|k9|k10)
 | 
|---|
| 324 |                 KBUILD_HOST_ARCH='amd64'
 | 
|---|
| 325 |                 ;;
 | 
|---|
| 326 |         esac
 | 
|---|
| 327 |     fi
 | 
|---|
| 328 | fi
 | 
|---|
| 329 | if test -z "$KBUILD_HOST_ARCH"; then
 | 
|---|
| 330 |     # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
 | 
|---|
| 331 |     if test "$KBUILD_HOST" = "solaris"; then
 | 
|---|
| 332 |         KBUILD_HOST_ARCH=`isainfo | cut -f 1 -d ' '`
 | 
|---|
| 333 | 
 | 
|---|
| 334 |     else
 | 
|---|
| 335 |         KBUILD_HOST_ARCH=`uname -m`
 | 
|---|
| 336 |     fi
 | 
|---|
| 337 |     case "$KBUILD_HOST_ARCH" in
 | 
|---|
| 338 |         x86_64|AMD64|amd64|k8|k8l|k9|k10)
 | 
|---|
| 339 |             KBUILD_HOST_ARCH='amd64'
 | 
|---|
| 340 |             # Try detect debian x32.
 | 
|---|
| 341 |             if test "$KBUILD_HOST" = "linux"; then 
 | 
|---|
| 342 |                 if test -z "${DEB_HOST_ARCH}"; then
 | 
|---|
| 343 |                     DEB_HOST_ARCH=`dpkg-architecture -qDEB_HOST_ARCH 2> /dev/null`;
 | 
|---|
| 344 |                     if test -z "${DEB_HOST_ARCH}"; then
 | 
|---|
| 345 |                         DEB_HOST_ARCH=`dpkg --print-architecture 2> /dev/null`;
 | 
|---|
| 346 |                     fi
 | 
|---|
| 347 |                 fi
 | 
|---|
| 348 |                 case "${DEB_HOST_ARCH}" in
 | 
|---|
| 349 |                     "x32")
 | 
|---|
| 350 |                         KBUILD_HOST_ARCH=x32
 | 
|---|
| 351 |                         ;;
 | 
|---|
| 352 |                     "") case "`uname -v`" in
 | 
|---|
| 353 |                             *Debian*+x32+*) KBUILD_HOST_ARCH=x32 ;;
 | 
|---|
| 354 |                         esac
 | 
|---|
| 355 |                         ;;
 | 
|---|
| 356 |                 esac
 | 
|---|
| 357 |             fi
 | 
|---|
| 358 |             ;;
 | 
|---|
| 359 |         x86|i86pc|ia32|i[3456789]86|BePC|i[3456789]86-AT[3456789]86)
 | 
|---|
| 360 |             KBUILD_HOST_ARCH='x86'
 | 
|---|
| 361 |             ;;
 | 
|---|
| 362 |         alpha)
 | 
|---|
| 363 |             KBUILD_HOST_ARCH='alpha'
 | 
|---|
| 364 |             ;;
 | 
|---|
| 365 |         aarch32|arm|arm1|arm2|arm3|arm6|armv1|armv2|armv3*|armv4*|armv5*|armv6*|armv7*|armv8*)
 | 
|---|
| 366 |             KBUILD_HOST_ARCH='arm32'
 | 
|---|
| 367 |             ;;
 | 
|---|
| 368 |         aarch64*|arm64) # (Apple M1 is arm64.)
 | 
|---|
| 369 |             KBUILD_HOST_ARCH='arm64'
 | 
|---|
| 370 |             ;;
 | 
|---|
| 371 |         hppa32|parisc32|parisc)
 | 
|---|
| 372 |             KBUILD_HOST_ARCH='hppa32'
 | 
|---|
| 373 |             ;;
 | 
|---|
| 374 |         hppa64|parisc64)
 | 
|---|
| 375 |             KBUILD_HOST_ARCH='hppa64'
 | 
|---|
| 376 |             ;;
 | 
|---|
| 377 |         ia64)
 | 
|---|
| 378 |             KBUILD_HOST_ARCH='ia64'
 | 
|---|
| 379 |             ;;
 | 
|---|
| 380 |         loongarch64)
 | 
|---|
| 381 |             KBUILD_HOST_ARCH='loongarch64'
 | 
|---|
| 382 |             ;;
 | 
|---|
| 383 |         m68k)
 | 
|---|
| 384 |             KBUILD_HOST_ARCH='m68k'
 | 
|---|
| 385 |             ;;
 | 
|---|
| 386 |         mips32|mips)
 | 
|---|
| 387 |             KBUILD_HOST_ARCH='mips32'
 | 
|---|
| 388 |             ;;
 | 
|---|
| 389 |         mips64)
 | 
|---|
| 390 |             KBUILD_HOST_ARCH='mips64'
 | 
|---|
| 391 |             ;;
 | 
|---|
| 392 |         ppc32|ppc|powerpc)
 | 
|---|
| 393 |             KBUILD_HOST_ARCH='ppc32'
 | 
|---|
| 394 |             ;;
 | 
|---|
| 395 |         ppc64|ppc64le|powerpc64|powerpc64le)
 | 
|---|
| 396 |             KBUILD_HOST_ARCH='ppc64'
 | 
|---|
| 397 |             ;;
 | 
|---|
| 398 |         riscv64*)
 | 
|---|
| 399 |             KBUILD_HOST_ARCH='riscv64'
 | 
|---|
| 400 |             ;;
 | 
|---|
| 401 |         riscv32*|riscv)
 | 
|---|
| 402 |             KBUILD_HOST_ARCH='riscv32'
 | 
|---|
| 403 |             ;;
 | 
|---|
| 404 |         s390)
 | 
|---|
| 405 |             KBUILD_HOST_ARCH='s390'
 | 
|---|
| 406 |             ;;
 | 
|---|
| 407 |         s390x)
 | 
|---|
| 408 |             KBUILD_HOST_ARCH='s390x'
 | 
|---|
| 409 |             ;;
 | 
|---|
| 410 |         sh|sh2|sh2a|sh3|sh3|sh4|sh4a|sh4al|sh4al-dsp|shmedia)
 | 
|---|
| 411 |             KBUILD_HOST_ARCH='sh32'
 | 
|---|
| 412 |             ;;
 | 
|---|
| 413 |         sh64)
 | 
|---|
| 414 |             KBUILD_HOST_ARCH='sh64'
 | 
|---|
| 415 |             ;;
 | 
|---|
| 416 |         sparc32|sparc|sparcv8|sparcv7|sparcv8e)
 | 
|---|
| 417 |             KBUILD_HOST_ARCH='sparc32'
 | 
|---|
| 418 |             ;;
 | 
|---|
| 419 |         sparc64|sparcv9)
 | 
|---|
| 420 |             KBUILD_HOST_ARCH='sparc64'
 | 
|---|
| 421 |             ;;
 | 
|---|
| 422 | 
 | 
|---|
| 423 |         *)  echo "$0: unknown cpu/arch - $KBUILD_HOST_ARCH" 1>&${ERR_REDIR}
 | 
|---|
| 424 |             sleep 1
 | 
|---|
| 425 |             exit 1
 | 
|---|
| 426 |             ;;
 | 
|---|
| 427 |     esac
 | 
|---|
| 428 | 
 | 
|---|
| 429 | fi
 | 
|---|
| 430 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_ARCH=$KBUILD_HOST_ARCH" 1>&${DBG_REDIR}
 | 
|---|
| 431 | 
 | 
|---|
| 432 | if test -z "$KBUILD_HOST_CPU"; then
 | 
|---|
| 433 |     KBUILD_HOST_CPU="blend"
 | 
|---|
| 434 | fi
 | 
|---|
| 435 | test -n "$DBG_OPT" && echo "dbg: KBUILD_HOST_CPU=$KBUILD_HOST_CPU" 1>&${DBG_REDIR}
 | 
|---|
| 436 | 
 | 
|---|
| 437 | #
 | 
|---|
| 438 | # The target platform.
 | 
|---|
| 439 | # Defaults to the host when not specified.
 | 
|---|
| 440 | #
 | 
|---|
| 441 | if test -z "$KBUILD_TARGET"; then
 | 
|---|
| 442 |     KBUILD_TARGET="$KBUILD_HOST"
 | 
|---|
| 443 | fi
 | 
|---|
| 444 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET=$KBUILD_TARGET" 1>&${DBG_REDIR}
 | 
|---|
| 445 | 
 | 
|---|
| 446 | if test -z "$KBUILD_TARGET_ARCH"; then
 | 
|---|
| 447 |     KBUILD_TARGET_ARCH="$KBUILD_HOST_ARCH"
 | 
|---|
| 448 | fi
 | 
|---|
| 449 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH" 1>&${DBG_REDIR}
 | 
|---|
| 450 | 
 | 
|---|
| 451 | if test -z "$KBUILD_TARGET_CPU"; then
 | 
|---|
| 452 |     if test "$KBUILD_TARGET_ARCH" = "$KBUILD_HOST_ARCH"; then
 | 
|---|
| 453 |         KBUILD_TARGET_CPU="$KBUILD_HOST_CPU"
 | 
|---|
| 454 |     else
 | 
|---|
| 455 |         KBUILD_TARGET_CPU="blend"
 | 
|---|
| 456 |     fi
 | 
|---|
| 457 | fi
 | 
|---|
| 458 | test -n "$DBG_OPT" && echo "dbg: KBUILD_TARGET_CPU=$KBUILD_TARGET_CPU" 1>&${DBG_REDIR}
 | 
|---|
| 459 | 
 | 
|---|
| 460 | #
 | 
|---|
| 461 | # Determin executable extension and path separator.
 | 
|---|
| 462 | #
 | 
|---|
| 463 | _SUFF_EXE=
 | 
|---|
| 464 | _PATH_SEP=":"
 | 
|---|
| 465 | case "$KBUILD_HOST" in
 | 
|---|
| 466 |     os2|win|nt)
 | 
|---|
| 467 |         _SUFF_EXE=".exe"
 | 
|---|
| 468 |         _PATH_SEP=";"
 | 
|---|
| 469 |         ;;
 | 
|---|
| 470 | esac
 | 
|---|
| 471 | 
 | 
|---|
| 472 | #
 | 
|---|
| 473 | # Determin KBUILD_PATH from the script location and calc KBUILD_BIN_PATH from there.
 | 
|---|
| 474 | #
 | 
|---|
| 475 | if test -z "$KBUILD_PATH"; then
 | 
|---|
| 476 |     KBUILD_PATH=`dirname "$0"`
 | 
|---|
| 477 |     KBUILD_PATH=`cd "$KBUILD_PATH" ; /bin/pwd`
 | 
|---|
| 478 | fi
 | 
|---|
| 479 | if test ! -f "$KBUILD_PATH/footer.kmk" -o ! -f "$KBUILD_PATH/header.kmk" -o ! -f "$KBUILD_PATH/rules.kmk"; then
 | 
|---|
| 480 |     echo "$0: error: KBUILD_PATH ($KBUILD_PATH) is not pointing to a popluated kBuild directory." 1>&${ERR_REDIR}
 | 
|---|
| 481 |     sleep 1
 | 
|---|
| 482 |     exit 1
 | 
|---|
| 483 | fi
 | 
|---|
| 484 | test -n "$DBG_OPT" && echo "dbg: KBUILD_PATH=$KBUILD_PATH" 1>&${DBG_REDIR}
 | 
|---|
| 485 | 
 | 
|---|
| 486 | if test -z "$KBUILD_BIN_PATH"; then
 | 
|---|
| 487 |     KBUILD_BIN_PATH="${KBUILD_PATH}/bin/${KBUILD_HOST}.${KBUILD_HOST_ARCH}"
 | 
|---|
| 488 | fi
 | 
|---|
| 489 | test -n "$DBG_OPT" && echo "dbg: KBUILD_BIN_PATH=${KBUILD_BIN_PATH}" 1>&${DBG_REDIR}
 | 
|---|
| 490 | 
 | 
|---|
| 491 | #
 | 
|---|
| 492 | # Add the bin/x.y/ directory to the PATH.
 | 
|---|
| 493 | # NOTE! Once bootstrapped this is the only thing that is actually necessary.
 | 
|---|
| 494 | #
 | 
|---|
| 495 | PATH="${KBUILD_BIN_PATH}${_PATH_SEP}$PATH"
 | 
|---|
| 496 | test -n "$DBG_OPT" && echo "dbg: PATH=$PATH" 1>&${DBG_REDIR}
 | 
|---|
| 497 | 
 | 
|---|
| 498 | #
 | 
|---|
| 499 | # Sanity and x bits.
 | 
|---|
| 500 | #
 | 
|---|
| 501 | if test ! -d "${KBUILD_BIN_PATH}/"; then
 | 
|---|
| 502 |     echo "$0: warning: The bin directory for this platform doesn't exist. (${KBUILD_BIN_PATH}/)" 1>&${ERR_REDIR}
 | 
|---|
| 503 | else
 | 
|---|
| 504 |     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;
 | 
|---|
| 505 |     do
 | 
|---|
| 506 |         chmod a+x ${KBUILD_BIN_PATH}/${prog} > /dev/null 2>&1
 | 
|---|
| 507 |         if test ! -f "${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE}"; then
 | 
|---|
| 508 |             echo "$0: warning: The ${prog} program doesn't exist for this platform. (${KBUILD_BIN_PATH}/${prog}${_SUFF_EXE})" 1>&${ERR_REDIR}
 | 
|---|
| 509 |         fi
 | 
|---|
| 510 |     done
 | 
|---|
| 511 | fi
 | 
|---|
| 512 | 
 | 
|---|
| 513 | #
 | 
|---|
| 514 | # The environment is in place, now take the requested action.
 | 
|---|
| 515 | #
 | 
|---|
| 516 | MY_RC=0
 | 
|---|
| 517 | if test -n "${VAR_OPT}"; then
 | 
|---|
| 518 |     # Echo variable values or variable export statements.
 | 
|---|
| 519 |     for var in ${VAR_OPT};
 | 
|---|
| 520 |     do
 | 
|---|
| 521 |         val=
 | 
|---|
| 522 |         case "$var" in
 | 
|---|
| 523 |             PATH)
 | 
|---|
| 524 |                 val=$PATH
 | 
|---|
| 525 |                 ;;
 | 
|---|
| 526 |             KBUILD_PATH)
 | 
|---|
| 527 |                 val=$KBUILD_PATH
 | 
|---|
| 528 |                 ;;
 | 
|---|
| 529 |             KBUILD_BIN_PATH)
 | 
|---|
| 530 |                 val=$KBUILD_BIN_PATH
 | 
|---|
| 531 |                 ;;
 | 
|---|
| 532 |             KBUILD_HOST)
 | 
|---|
| 533 |                 val=$KBUILD_HOST
 | 
|---|
| 534 |                 ;;
 | 
|---|
| 535 |             KBUILD_HOST_ARCH)
 | 
|---|
| 536 |                 val=$KBUILD_HOST_ARCH
 | 
|---|
| 537 |                 ;;
 | 
|---|
| 538 |             KBUILD_HOST_CPU)
 | 
|---|
| 539 |                 val=$KBUILD_HOST_CPU
 | 
|---|
| 540 |                 ;;
 | 
|---|
| 541 |             KBUILD_TARGET)
 | 
|---|
| 542 |                 val=$KBUILD_TARGET
 | 
|---|
| 543 |                 ;;
 | 
|---|
| 544 |             KBUILD_TARGET_ARCH)
 | 
|---|
| 545 |                 val=$KBUILD_TARGET_ARCH
 | 
|---|
| 546 |                 ;;
 | 
|---|
| 547 |             KBUILD_TARGET_CPU)
 | 
|---|
| 548 |                 val=$KBUILD_TARGET_CPU
 | 
|---|
| 549 |                 ;;
 | 
|---|
| 550 |             KBUILD_TYPE)
 | 
|---|
| 551 |                 val=$KBUILD_TYPE
 | 
|---|
| 552 |                 ;;
 | 
|---|
| 553 |             *)
 | 
|---|
| 554 |                 echo "$0: error: Unknown variable $var specified in --var request." 1>&${ERR_REDIR}
 | 
|---|
| 555 |                 sleep 1
 | 
|---|
| 556 |                 exit 1
 | 
|---|
| 557 |                 ;;
 | 
|---|
| 558 |         esac
 | 
|---|
| 559 | 
 | 
|---|
| 560 |         if test -n "$EVAL_OPT"; then
 | 
|---|
| 561 |             echo "${EVAL_EXPORT} $var=$val"
 | 
|---|
| 562 |         else
 | 
|---|
| 563 |             if test -n "$VALUE_ONLY_OPT"; then
 | 
|---|
| 564 |                 echo "$val"
 | 
|---|
| 565 |             else
 | 
|---|
| 566 |                 echo "$var=$val"
 | 
|---|
| 567 |             fi
 | 
|---|
| 568 |         fi
 | 
|---|
| 569 |     done
 | 
|---|
| 570 | else
 | 
|---|
| 571 |     if test -n "$EVAL_OPT"; then
 | 
|---|
| 572 |         # Echo statements for the shell to evaluate.
 | 
|---|
| 573 |         test -n "$DBG_OPT" && echo "dbg: echoing exported variables" 1>&${DBG_REDIR}
 | 
|---|
| 574 |         echo "${EVAL_EXPORT} PATH=${PATH}"
 | 
|---|
| 575 |         test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && echo "${EVAL_EXPORT} KBUILD_TYPE=${KBUILD_TYPE}"
 | 
|---|
| 576 |         if test -n "${FULL_OPT}"; then
 | 
|---|
| 577 |             echo "${EVAL_EXPORT} KBUILD_PATH=${KBUILD_PATH}"
 | 
|---|
| 578 |             if test -n "{FULL_WITH_BIN_OPT}"; then
 | 
|---|
| 579 |                 echo "${EVAL_EXPORT} KBUILD_BIN_PATH=${KBUILD_BIN_PATH}"
 | 
|---|
| 580 |             fi
 | 
|---|
| 581 |             echo "${EVAL_EXPORT} KBUILD_HOST=${KBUILD_HOST}"
 | 
|---|
| 582 |             echo "${EVAL_EXPORT} KBUILD_HOST_ARCH=${KBUILD_HOST_ARCH}"
 | 
|---|
| 583 |             echo "${EVAL_EXPORT} KBUILD_HOST_CPU=${KBUILD_HOST_CPU}"
 | 
|---|
| 584 |             echo "${EVAL_EXPORT} KBUILD_TARGET=${KBUILD_TARGET}"
 | 
|---|
| 585 |             echo "${EVAL_EXPORT} KBUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}"
 | 
|---|
| 586 |             echo "${EVAL_EXPORT} KBUILD_TARGET_CPU=${KBUILD_TARGET_CPU}"
 | 
|---|
| 587 | 
 | 
|---|
| 588 |             if test -n "${LEGACY_OPT}"; then
 | 
|---|
| 589 |                 echo "${EVAL_EXPORT} PATH_KBUILD=${KBUILD_PATH}"
 | 
|---|
| 590 |                 if test -n "${FULL_WITH_BIN_OPT}"; then
 | 
|---|
| 591 |                     echo "${EVAL_EXPORT} PATH_KBUILD_BIN=${KBUILD_PATH_BIN}"
 | 
|---|
| 592 |                 fi
 | 
|---|
| 593 |                 echo "${EVAL_EXPORT} BUILD_TYPE=${KBUILD_TYPE}"
 | 
|---|
| 594 |                 echo "${EVAL_EXPORT} BUILD_PLATFORM=${KBUILD_HOST}"
 | 
|---|
| 595 |                 echo "${EVAL_EXPORT} BUILD_PLATFORM_ARCH=${KBUILD_HOST_ARCH}"
 | 
|---|
| 596 |                 echo "${EVAL_EXPORT} BUILD_PLATFORM_CPU=${KBUILD_HOST_CPU}"
 | 
|---|
| 597 |                 echo "${EVAL_EXPORT} BUILD_TARGET=${KBUILD_TARGET}"
 | 
|---|
| 598 |                 echo "${EVAL_EXPORT} BUILD_TARGET_ARCH=${KBUILD_TARGET_ARCH}"
 | 
|---|
| 599 |                 echo "${EVAL_EXPORT} BUILD_TARGET_CPU=${KBUILD_TARGET_CPU}"
 | 
|---|
| 600 |             fi
 | 
|---|
| 601 |         fi
 | 
|---|
| 602 |     else
 | 
|---|
| 603 |         # Export variables.
 | 
|---|
| 604 |         export PATH
 | 
|---|
| 605 |         test -n "${FULL_OPT}" -o "${EXP_TYPE_OPT}" && export KBUILD_TYPE
 | 
|---|
| 606 |         if test -n "${FULL_OPT}"; then
 | 
|---|
| 607 |             export KBUILD_PATH
 | 
|---|
| 608 |             if test -n "${FULL_WITH_BIN_OPT}"; then
 | 
|---|
| 609 |                 export KBUILD_BIN_PATH
 | 
|---|
| 610 |             fi
 | 
|---|
| 611 |             export KBUILD_HOST
 | 
|---|
| 612 |             export KBUILD_HOST_ARCH
 | 
|---|
| 613 |             export KBUILD_HOST_CPU
 | 
|---|
| 614 |             export KBUILD_TARGET
 | 
|---|
| 615 |             export KBUILD_TARGET_ARCH
 | 
|---|
| 616 |             export KBUILD_TARGET_CPU
 | 
|---|
| 617 | 
 | 
|---|
| 618 |             if test -n "${LEGACY_OPT}"; then
 | 
|---|
| 619 |                 export PATH_KBUILD=$KBUILD_PATH
 | 
|---|
| 620 |                 if test -n "${FULL_WITH_BIN_OPT}"; then
 | 
|---|
| 621 |                     export PATH_KBUILD_BIN=$KBUILD_BIN_PATH
 | 
|---|
| 622 |                 fi
 | 
|---|
| 623 |                 export BUILD_TYPE=$KBUILD_TYPE
 | 
|---|
| 624 |                 export BUILD_PLATFORM=$KBUILD_HOST
 | 
|---|
| 625 |                 export BUILD_PLATFORM_ARCH=$KBUILD_HOST_ARCH
 | 
|---|
| 626 |                 export BUILD_PLATFORM_CPU=$KBUILD_HOST_CPU
 | 
|---|
| 627 |                 export BUILD_TARGET=$KBUILD_TARGET
 | 
|---|
| 628 |                 export BUILD_TARGET_ARCH=$KBUILD_TARGET_ARCH
 | 
|---|
| 629 |                 export BUILD_TARGET_CPU=$KBUILD_TARGET_CPU
 | 
|---|
| 630 |             fi
 | 
|---|
| 631 |         fi
 | 
|---|
| 632 | 
 | 
|---|
| 633 |         # Execute command or spawn shell.
 | 
|---|
| 634 |         if test $# -eq 0; then
 | 
|---|
| 635 |             test -z "${QUIET_OPT}" && echo "$0: info: Spawning work shell..." 1>&${ERR_REDIR}
 | 
|---|
| 636 |             if test "$TERM" != 'dumb'  -a  -n "$BASH"; then
 | 
|---|
| 637 |                 export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
 | 
|---|
| 638 |             fi
 | 
|---|
| 639 |             $SHELL -i
 | 
|---|
| 640 |             MY_RC=$?
 | 
|---|
| 641 |         else
 | 
|---|
| 642 |             test -z "${QUIET_OPT}" && echo "$0: info: Executing command: $*" 1>&${ERR_REDIR}
 | 
|---|
| 643 |             $*
 | 
|---|
| 644 |             MY_RC=$?
 | 
|---|
| 645 |             test -z "${QUIET_OPT}" -a "$MY_RC" -ne 0 && echo "$0: info: rc=$MY_RC: $*" 1>&${ERR_REDIR}
 | 
|---|
| 646 |         fi
 | 
|---|
| 647 |     fi
 | 
|---|
| 648 | fi
 | 
|---|
| 649 | test -n "$DBG_OPT" && echo "dbg: finished (rc=$MY_RC)" 1>&${DBG_REDIR}
 | 
|---|
| 650 | exit $MY_RC
 | 
|---|
| 651 | 
 | 
|---|