[224] | 1 | #!/bin/bash
|
---|
[1488] | 2 | #!/bin/sh should work fine too, just needs testing.
|
---|
[224] | 3 | # $Id: env.sh 1488 2008-04-04 02:36:46Z bird $
|
---|
| 4 | ## @file
|
---|
| 5 | #
|
---|
| 6 | # Environment setup script.
|
---|
| 7 | #
|
---|
[782] | 8 | # Copyright (c) 2005-2007 knut st. osmundsen <bird-kBuild-spam@anduin.net>
|
---|
[224] | 9 | #
|
---|
| 10 | #
|
---|
| 11 | # This file is part of kBuild.
|
---|
| 12 | #
|
---|
| 13 | # kBuild is free software; you can redistribute it and/or modify
|
---|
| 14 | # it under the terms of the GNU General Public License as published by
|
---|
| 15 | # the Free Software Foundation; either version 2 of the License, or
|
---|
| 16 | # (at your option) any later version.
|
---|
| 17 | #
|
---|
| 18 | # kBuild is distributed in the hope that it will be useful,
|
---|
| 19 | # but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 20 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 21 | # GNU General Public License for more details.
|
---|
| 22 | #
|
---|
| 23 | # You should have received a copy of the GNU General Public License
|
---|
| 24 | # along with kBuild; if not, write to the Free Software
|
---|
| 25 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 26 | #
|
---|
| 27 | #
|
---|
[1067] | 28 | #set -x
|
---|
[224] | 29 |
|
---|
[992] | 30 | #
|
---|
| 31 | # Determin the kBuild path from the script location.
|
---|
| 32 | #
|
---|
[994] | 33 | if test -z "$PATH_KBUILD"; then
|
---|
[557] | 34 | PATH_KBUILD=`dirname "$0"`
|
---|
| 35 | PATH_KBUILD=`cd "$PATH_KBUILD" ; /bin/pwd`
|
---|
[224] | 36 | fi
|
---|
[994] | 37 | if test ! -f "$PATH_KBUILD/footer.kmk" -o ! -f "$PATH_KBUILD/header.kmk" -o ! -f "$PATH_KBUILD/rules.kmk"; then
|
---|
[224] | 38 | echo "$0: error: PATH_KBUILD ($PATH_KBUILD) is not pointing to a popluated kBuild directory.";
|
---|
| 39 | sleep 1;
|
---|
| 40 | exit 1;
|
---|
| 41 | fi
|
---|
| 42 | export PATH_KBUILD
|
---|
| 43 | echo "dbg: PATH_KBUILD=$PATH_KBUILD"
|
---|
| 44 |
|
---|
[1076] | 45 |
|
---|
[992] | 46 | #
|
---|
| 47 | # Set default build type.
|
---|
| 48 | #
|
---|
[994] | 49 | if test -z "$BUILD_TYPE"; then
|
---|
[718] | 50 | BUILD_TYPE=release
|
---|
[224] | 51 | fi
|
---|
| 52 | export BUILD_TYPE
|
---|
| 53 | echo "dbg: BUILD_TYPE=$BUILD_TYPE"
|
---|
| 54 |
|
---|
[992] | 55 | #
|
---|
| 56 | # Determin the host platform.
|
---|
| 57 | #
|
---|
| 58 | # The CPU isn't important, only the other two are. But, since the cpu,
|
---|
| 59 | # arch and platform (and build type) share a common key space, try make
|
---|
| 60 | # sure any new additions are unique. (See header.kmk, KBUILD_OSES/ARCHES.)
|
---|
| 61 | #
|
---|
[994] | 62 | if test -z "$BUILD_PLATFORM"; then
|
---|
| 63 | BUILD_PLATFORM=`uname`
|
---|
| 64 | case "$BUILD_PLATFORM" in
|
---|
| 65 | linux|Linux|GNU/Linux|LINUX)
|
---|
| 66 | BUILD_PLATFORM=linux
|
---|
| 67 | ;;
|
---|
| 68 |
|
---|
| 69 | os2|OS/2|OS2)
|
---|
| 70 | BUILD_PLATFORM=os2
|
---|
| 71 | ;;
|
---|
| 72 |
|
---|
| 73 | freebsd|FreeBSD|FREEBSD)
|
---|
| 74 | BUILD_PLATFORM=freebsd
|
---|
| 75 | ;;
|
---|
| 76 |
|
---|
| 77 | openbsd|OpenBSD|OPENBSD)
|
---|
| 78 | BUILD_PLATFORM=openbsd
|
---|
| 79 | ;;
|
---|
| 80 |
|
---|
| 81 | netbsd|NetBSD|NETBSD)
|
---|
| 82 | BUILD_PLATFORM=netbsd
|
---|
| 83 | ;;
|
---|
| 84 |
|
---|
| 85 | Darwin|darwin)
|
---|
| 86 | BUILD_PLATFORM=darwin
|
---|
| 87 | ;;
|
---|
| 88 |
|
---|
| 89 | SunOS)
|
---|
| 90 | BUILD_PLATFORM=solaris
|
---|
| 91 | ;;
|
---|
| 92 |
|
---|
| 93 | WindowsNT|CYGWIN_NT-*)
|
---|
| 94 | BUILD_PLATFORM=win
|
---|
| 95 | ;;
|
---|
| 96 |
|
---|
| 97 | *)
|
---|
| 98 | echo "$0: unknown os $BUILD_PLATFORM"
|
---|
| 99 | sleep 1
|
---|
| 100 | exit 1
|
---|
| 101 | ;;
|
---|
| 102 | esac
|
---|
| 103 | fi
|
---|
| 104 | export BUILD_PLATFORM
|
---|
| 105 | echo "dbg: BUILD_PLATFORM=$BUILD_PLATFORM"
|
---|
| 106 |
|
---|
| 107 | if test -z "$BUILD_PLATFORM_ARCH"; then
|
---|
[992] | 108 | # Try deduce it from the cpu if given.
|
---|
[994] | 109 | if test -s "$BUILD_PLATFORM_CPU"; then
|
---|
[992] | 110 | case "$BUILD_PLATFORM_CPU" in
|
---|
| 111 | i[3456789]86)
|
---|
| 112 | BUILD_PLATFORM_ARCH='x86'
|
---|
| 113 | ;;
|
---|
| 114 | k8|k8l|k9|k10)
|
---|
| 115 | BUILD_PLATFORM_ARCH='amd64'
|
---|
| 116 | ;;
|
---|
| 117 | esac
|
---|
| 118 | fi
|
---|
[224] | 119 | fi
|
---|
[994] | 120 | if test -z "$BUILD_PLATFORM_ARCH"; then
|
---|
[1156] | 121 | # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
|
---|
[1488] | 122 | if test "$BUILD_PLATFORM" = "solaris"; then
|
---|
[1244] | 123 | BUILD_PLATFORM_ARCH=`isainfo | cut -f 1 -d ' '`
|
---|
| 124 |
|
---|
[1156] | 125 | else
|
---|
| 126 | BUILD_PLATFORM_ARCH=`uname -m`
|
---|
| 127 | fi
|
---|
[992] | 128 | case "$BUILD_PLATFORM_ARCH" in
|
---|
| 129 | x86_64|AMD64|amd64|k8|k8l|k9|k10)
|
---|
| 130 | BUILD_PLATFORM_ARCH='amd64'
|
---|
| 131 | ;;
|
---|
| 132 | x86|i86pc|ia32|i[3456789]86)
|
---|
[224] | 133 | BUILD_PLATFORM_ARCH='x86'
|
---|
| 134 | ;;
|
---|
[992] | 135 | sparc32|sparc)
|
---|
| 136 | BUILD_PLATFORM_ARCH='sparc32'
|
---|
[299] | 137 | ;;
|
---|
[992] | 138 | sparc64)
|
---|
| 139 | BUILD_PLATFORM_ARCH='sparc64'
|
---|
| 140 | ;;
|
---|
| 141 | s390)
|
---|
| 142 | BUILD_PLATFORM_ARCH='s390'
|
---|
| 143 | ;;
|
---|
[1380] | 144 | s390x)
|
---|
| 145 | BUILD_PLATFORM_ARCH='s390x'
|
---|
| 146 | ;;
|
---|
[992] | 147 | ppc32|ppc|powerpc)
|
---|
| 148 | BUILD_PLATFORM_ARCH='ppc32'
|
---|
| 149 | ;;
|
---|
| 150 | ppc64|powerpc64)
|
---|
| 151 | BUILD_PLATFORM_ARCH='ppc64'
|
---|
| 152 | ;;
|
---|
| 153 | mips32|mips)
|
---|
| 154 | BUILD_PLATFORM_ARCH='mips32'
|
---|
| 155 | ;;
|
---|
| 156 | mips64)
|
---|
| 157 | BUILD_PLATFORM_ARCH='mips64'
|
---|
| 158 | ;;
|
---|
| 159 | ia64)
|
---|
| 160 | BUILD_PLATFORM_ARCH='ia64'
|
---|
| 161 | ;;
|
---|
| 162 | #hppa32|hppa|parisc32|parisc)?
|
---|
| 163 | hppa32|parisc32)
|
---|
| 164 | BUILD_PLATFORM_ARCH='hppa32'
|
---|
| 165 | ;;
|
---|
| 166 | hppa64|parisc64)
|
---|
| 167 | BUILD_PLATFORM_ARCH='hppa64'
|
---|
| 168 | ;;
|
---|
[1380] | 169 | arm|armv4l|armv5tel)
|
---|
[992] | 170 | BUILD_PLATFORM_ARCH='arm'
|
---|
| 171 | ;;
|
---|
| 172 | alpha)
|
---|
| 173 | BUILD_PLATFORM_ARCH='alpha'
|
---|
| 174 | ;;
|
---|
| 175 |
|
---|
[1142] | 176 | *) echo "$0: unknown cpu/arch - $BUILD_PLATFORM_ARCH"
|
---|
[224] | 177 | sleep 1
|
---|
| 178 | exit 1
|
---|
| 179 | ;;
|
---|
| 180 | esac
|
---|
| 181 |
|
---|
| 182 | fi
|
---|
| 183 | export BUILD_PLATFORM_ARCH
|
---|
| 184 | echo "dbg: BUILD_PLATFORM_ARCH=$BUILD_PLATFORM_ARCH"
|
---|
| 185 |
|
---|
[994] | 186 | if test -z "$BUILD_PLATFORM_CPU"; then
|
---|
[992] | 187 | BUILD_PLATFORM_CPU="blend"
|
---|
| 188 | fi
|
---|
| 189 | export BUILD_PLATFORM_CPU
|
---|
| 190 | echo "dbg: BUILD_PLATFORM_CPU=$BUILD_PLATFORM_CPU"
|
---|
[224] | 191 |
|
---|
[992] | 192 | #
|
---|
| 193 | # The target platform.
|
---|
| 194 | # Defaults to the host when not specified.
|
---|
| 195 | #
|
---|
[994] | 196 | if test -z "$BUILD_TARGET"; then
|
---|
| 197 | BUILD_TARGET="$BUILD_PLATFORM"
|
---|
[224] | 198 | fi
|
---|
[994] | 199 | export BUILD_TARGET
|
---|
| 200 | echo "dbg: BUILD_TARGET=$BUILD_TARGET"
|
---|
[224] | 201 |
|
---|
[994] | 202 | if test -z "$BUILD_TARGET_ARCH"; then
|
---|
[992] | 203 | BUILD_TARGET_ARCH="$BUILD_PLATFORM_ARCH"
|
---|
[224] | 204 | fi
|
---|
| 205 | export BUILD_TARGET_ARCH
|
---|
| 206 | echo "dbg: BUILD_TARGET_ARCH=$BUILD_TARGET_ARCH"
|
---|
| 207 |
|
---|
[994] | 208 | if test -z "$BUILD_TARGET_CPU"; then
|
---|
| 209 | if test "$BUILD_TARGET_ARCH" = "$BUILD_PLATFORM_ARCH"; then
|
---|
| 210 | BUILD_TARGET_CPU="$BUILD_PLATFORM_CPU"
|
---|
| 211 | else
|
---|
| 212 | BUILD_TARGET_CPU="blend"
|
---|
| 213 | fi
|
---|
[224] | 214 | fi
|
---|
[994] | 215 | export BUILD_TARGET_CPU
|
---|
| 216 | echo "dbg: BUILD_TARGET_CPU=$BUILD_TARGET_CPU"
|
---|
[224] | 217 |
|
---|
| 218 |
|
---|
| 219 | # Determin executable extension and path separator.
|
---|
| 220 | _SUFF_EXE=
|
---|
| 221 | _PATH_SEP=":"
|
---|
| 222 | case "$BUILD_PLATFORM" in
|
---|
[992] | 223 | os2|win|nt)
|
---|
[224] | 224 | _SUFF_EXE=".exe"
|
---|
| 225 | _PATH_SEP=";"
|
---|
| 226 | ;;
|
---|
| 227 | esac
|
---|
| 228 |
|
---|
[1076] | 229 |
|
---|
| 230 | #
|
---|
| 231 | # Calc PATH_KBUILD_BIN (but don't export it).
|
---|
| 232 | #
|
---|
| 233 | if test -z "$PATH_KBUILD_BIN"; then
|
---|
| 234 | PATH_KBUILD_BIN="${PATH_KBUILD}/bin/${BUILD_PLATFORM}.${BUILD_PLATFORM_ARCH}"
|
---|
| 235 | fi
|
---|
| 236 | echo "dbg: PATH_KBUILD_BIN=${PATH_KBUILD_BIN} (not exported)"
|
---|
| 237 |
|
---|
[992] | 238 | # Make shell. OS/2 and DOS only?
|
---|
[1076] | 239 | export MAKESHELL="${PATH_KBUILD_BIN}/kmk_ash${_SUFF_EXE}";
|
---|
[224] | 240 |
|
---|
[992] | 241 | #
|
---|
| 242 | # Add the bin/x.y/ directory to the PATH.
|
---|
| 243 | # NOTE! Once bootstrapped this is the only thing that is actually necessary.
|
---|
| 244 | #
|
---|
[1076] | 245 | PATH="${PATH_KBUILD_BIN}/${_PATH_SEP}$PATH"
|
---|
[224] | 246 | export PATH
|
---|
| 247 | echo "dbg: PATH=$PATH"
|
---|
| 248 |
|
---|
| 249 | # Sanity and x bits.
|
---|
[1076] | 250 | if test ! -d "${PATH_KBUILD_BIN}/"; then
|
---|
| 251 | echo "$0: warning: The bin directory for this platform doesn't exists. (${PATH_KBUILD_BIN}/)"
|
---|
[224] | 252 | else
|
---|
[731] | 253 | 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] | 254 | do
|
---|
[1076] | 255 | chmod a+x ${PATH_KBUILD_BIN}/${prog} > /dev/null 2>&1
|
---|
| 256 | if test ! -f "${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE}"; then
|
---|
| 257 | echo "$0: warning: The ${prog} program doesn't exist for this platform. (${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE})"
|
---|
[224] | 258 | fi
|
---|
| 259 | done
|
---|
| 260 | fi
|
---|
| 261 |
|
---|
| 262 | unset _SUFF_EXE
|
---|
| 263 | unset _PATH_SEP
|
---|
| 264 |
|
---|
| 265 | # Execute command or spawn shell.
|
---|
[994] | 266 | if test $# -eq 0; then
|
---|
[224] | 267 | echo "$0: info: Spawning work shell..."
|
---|
[994] | 268 | if test "$TERM" != 'dumb' -a -n "$BASH"; then
|
---|
[224] | 269 | export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
|
---|
| 270 | fi
|
---|
| 271 | $SHELL -i
|
---|
| 272 | else
|
---|
| 273 | echo "$0: info: Executing command: $*"
|
---|
| 274 | $*
|
---|
| 275 | fi
|
---|
[731] | 276 |
|
---|