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