source: trunk/kBuild/env.sh@ 1512

Last change on this file since 1512 was 1512, checked in by bird, 17 years ago

Added a --full option and not exporting defaults.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 9.1 KB
RevLine 
[1510]1#!/bin/sh
[224]2# $Id: env.sh 1512 2008-04-09 01:36:57Z bird $
3## @file
4# Environment setup script.
5#
[1511]6
7#
[1507]8# Copyright (c) 2005-2008 knut st. osmundsen <bird-kBuild-spam@anduin.net>
[224]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#
[1510]30# Check if we're in eval mode or not.
31#
32ERR_REDIR=1
33DBG_REDIR=1
34EVAL_OPT=
35DBG_OPT=
36QUIET_OPT=
[1512]37FULL_OPT=
38while test $# -gt 0;
39do
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
[1510]63 shift
[1512]64done
[1510]65
66
67#
[992]68# Determin the kBuild path from the script location.
69#
[994]70if test -z "$PATH_KBUILD"; then
[557]71 PATH_KBUILD=`dirname "$0"`
72 PATH_KBUILD=`cd "$PATH_KBUILD" ; /bin/pwd`
[224]73fi
[994]74if test ! -f "$PATH_KBUILD/footer.kmk" -o ! -f "$PATH_KBUILD/header.kmk" -o ! -f "$PATH_KBUILD/rules.kmk"; then
[1510]75 echo "$0: error: PATH_KBUILD ($PATH_KBUILD) is not pointing to a popluated kBuild directory." 1>&${ERR_REDIR}
[224]76 sleep 1;
77 exit 1;
78fi
[1510]79test -n "$DBG_OPT" && echo "dbg: PATH_KBUILD=$PATH_KBUILD" 1>&${DBG_REDIR}
[224]80
[1076]81
[992]82#
83# Set default build type.
84#
[994]85if test -z "$BUILD_TYPE"; then
[718]86 BUILD_TYPE=release
[224]87fi
[1510]88test -n "$DBG_OPT" && echo "dbg: BUILD_TYPE=$BUILD_TYPE" 1>&${DBG_REDIR}
[224]89
[992]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#
[994]97if 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 *)
[1510]133 echo "$0: unknown os $BUILD_PLATFORM" 1>&${ERR_REDIR}
[994]134 sleep 1
135 exit 1
136 ;;
137 esac
138fi
[1510]139test -n "$DBG_OPT" && echo "dbg: BUILD_PLATFORM=$BUILD_PLATFORM" 1>&${DBG_REDIR}
[994]140
141if test -z "$BUILD_PLATFORM_ARCH"; then
[992]142 # Try deduce it from the cpu if given.
[994]143 if test -s "$BUILD_PLATFORM_CPU"; then
[992]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
[224]153fi
[994]154if test -z "$BUILD_PLATFORM_ARCH"; then
[1156]155 # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
[1488]156 if test "$BUILD_PLATFORM" = "solaris"; then
[1244]157 BUILD_PLATFORM_ARCH=`isainfo | cut -f 1 -d ' '`
158
[1156]159 else
160 BUILD_PLATFORM_ARCH=`uname -m`
161 fi
[992]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)
[224]167 BUILD_PLATFORM_ARCH='x86'
168 ;;
[992]169 sparc32|sparc)
170 BUILD_PLATFORM_ARCH='sparc32'
[299]171 ;;
[992]172 sparc64)
173 BUILD_PLATFORM_ARCH='sparc64'
174 ;;
175 s390)
176 BUILD_PLATFORM_ARCH='s390'
177 ;;
[1380]178 s390x)
179 BUILD_PLATFORM_ARCH='s390x'
180 ;;
[992]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 ;;
[1380]203 arm|armv4l|armv5tel)
[992]204 BUILD_PLATFORM_ARCH='arm'
205 ;;
206 alpha)
207 BUILD_PLATFORM_ARCH='alpha'
208 ;;
209
[1510]210 *) echo "$0: unknown cpu/arch - $BUILD_PLATFORM_ARCH" 1>&${ERR_REDIR}
[224]211 sleep 1
212 exit 1
213 ;;
214 esac
215
216fi
[1510]217test -n "$DBG_OPT" && echo "dbg: BUILD_PLATFORM_ARCH=$BUILD_PLATFORM_ARCH" 1>&${DBG_REDIR}
[224]218
[994]219if test -z "$BUILD_PLATFORM_CPU"; then
[992]220 BUILD_PLATFORM_CPU="blend"
221fi
[1510]222test -n "$DBG_OPT" && echo "dbg: BUILD_PLATFORM_CPU=$BUILD_PLATFORM_CPU" 1>&${DBG_REDIR}
[224]223
[992]224#
225# The target platform.
226# Defaults to the host when not specified.
227#
[994]228if test -z "$BUILD_TARGET"; then
229 BUILD_TARGET="$BUILD_PLATFORM"
[224]230fi
[1510]231test -n "$DBG_OPT" && echo "dbg: BUILD_TARGET=$BUILD_TARGET" 1>&${DBG_REDIR}
[224]232
[994]233if test -z "$BUILD_TARGET_ARCH"; then
[992]234 BUILD_TARGET_ARCH="$BUILD_PLATFORM_ARCH"
[224]235fi
[1510]236test -n "$DBG_OPT" && echo "dbg: BUILD_TARGET_ARCH=$BUILD_TARGET_ARCH" 1>&${DBG_REDIR}
[224]237
[994]238if 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
[224]244fi
[1510]245test -n "$DBG_OPT" && echo "dbg: BUILD_TARGET_CPU=$BUILD_TARGET_CPU" 1>&${DBG_REDIR}
[224]246
247
248# Determin executable extension and path separator.
249_SUFF_EXE=
250_PATH_SEP=":"
251case "$BUILD_PLATFORM" in
[992]252 os2|win|nt)
[224]253 _SUFF_EXE=".exe"
254 _PATH_SEP=";"
255 ;;
256esac
257
[1076]258
259#
260# Calc PATH_KBUILD_BIN (but don't export it).
261#
262if test -z "$PATH_KBUILD_BIN"; then
263 PATH_KBUILD_BIN="${PATH_KBUILD}/bin/${BUILD_PLATFORM}.${BUILD_PLATFORM_ARCH}"
264fi
[1510]265test -n "$DBG_OPT" && echo "dbg: PATH_KBUILD_BIN=${PATH_KBUILD_BIN} (not exported)" 1>&${DBG_REDIR}
[1076]266
[992]267# Make shell. OS/2 and DOS only?
[1510]268if test "$BUILD_PLATFORM" = "os2"; then
269 export MAKESHELL="${PATH_KBUILD_BIN}/kmk_ash${_SUFF_EXE}";
270fi
[224]271
[992]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#
[1510]276PATH="${PATH_KBUILD_BIN}${_PATH_SEP}$PATH"
277test -n "$DBG_OPT" && echo "dbg: PATH=$PATH" 1>&${DBG_REDIR}
[224]278
279# Sanity and x bits.
[1076]280if test ! -d "${PATH_KBUILD_BIN}/"; then
[1510]281 echo "$0: warning: The bin directory for this platform doesn't exists. (${PATH_KBUILD_BIN}/)" 1>&${ERR_REDIR}
[224]282else
[731]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;
[224]284 do
[1076]285 chmod a+x ${PATH_KBUILD_BIN}/${prog} > /dev/null 2>&1
286 if test ! -f "${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE}"; then
[1510]287 echo "$0: warning: The ${prog} program doesn't exist for this platform. (${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE})" 1>&${ERR_REDIR}
[224]288 fi
289 done
290fi
291
292unset _SUFF_EXE
293unset _PATH_SEP
294
[1510]295if test -n "$EVAL_OPT"; then
296 test -n "$DBG_OPT" && echo "dbg: echoing exported variables" 1>&${DBG_REDIR}
297 echo "export PATH=${PATH}"
[1512]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
[1510]308 test -n "$DBG_OPT" && echo "dbg: finished" 1>&${DBG_REDIR}
309else
[1512]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
[1510]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
[1512]330 test -z "${QUIET_OPT}" && echo "$0: info: Executing command: $*" 1>&${ERR_REDIR}
[1510]331 $*
[224]332 fi
333fi
[731]334
Note: See TracBrowser for help on using the repository browser.