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