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