source: trunk/kBuild/env.sh@ 1510

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

Fixed hash bang line. Added an eval mode and shut up the debug info.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 8.5 KB
RevLine 
[1510]1#!/bin/sh
[224]2# $Id: env.sh 1510 2008-04-09 01:19:35Z bird $
3## @file
4#
5# Environment setup script.
6#
[1507]7# Copyright (c) 2005-2008 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#
[1510]30# Check if we're in eval mode or not.
31#
32ERR_REDIR=1
33DBG_REDIR=1
34EVAL_OPT=
35DBG_OPT=
36QUIET_OPT=
37if test "$1" = "--debug"; then
38 DBG_OPT="true"
39 shift
40fi
41if test "$1" = "--quiet"; then
42 QUIET_OPT="true"
43 shift
44fi
45if test "$1" = "--eval"; then
46 EVAL_OPT="true"
47 ERR_REDIR=2
48 DBG_REDIR=2
49 shift
50fi
51
52
53#
[992]54# Determin the kBuild path from the script location.
55#
[994]56if test -z "$PATH_KBUILD"; then
[557]57 PATH_KBUILD=`dirname "$0"`
58 PATH_KBUILD=`cd "$PATH_KBUILD" ; /bin/pwd`
[224]59fi
[994]60if test ! -f "$PATH_KBUILD/footer.kmk" -o ! -f "$PATH_KBUILD/header.kmk" -o ! -f "$PATH_KBUILD/rules.kmk"; then
[1510]61 echo "$0: error: PATH_KBUILD ($PATH_KBUILD) is not pointing to a popluated kBuild directory." 1>&${ERR_REDIR}
[224]62 sleep 1;
63 exit 1;
64fi
65export PATH_KBUILD
[1510]66test -n "$DBG_OPT" && echo "dbg: PATH_KBUILD=$PATH_KBUILD" 1>&${DBG_REDIR}
[224]67
[1076]68
[992]69#
70# Set default build type.
71#
[994]72if test -z "$BUILD_TYPE"; then
[718]73 BUILD_TYPE=release
[224]74fi
75export BUILD_TYPE
[1510]76test -n "$DBG_OPT" && echo "dbg: BUILD_TYPE=$BUILD_TYPE" 1>&${DBG_REDIR}
[224]77
[992]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#
[994]85if 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 *)
[1510]121 echo "$0: unknown os $BUILD_PLATFORM" 1>&${ERR_REDIR}
[994]122 sleep 1
123 exit 1
124 ;;
125 esac
126fi
127export BUILD_PLATFORM
[1510]128test -n "$DBG_OPT" && echo "dbg: BUILD_PLATFORM=$BUILD_PLATFORM" 1>&${DBG_REDIR}
[994]129
130if test -z "$BUILD_PLATFORM_ARCH"; then
[992]131 # Try deduce it from the cpu if given.
[994]132 if test -s "$BUILD_PLATFORM_CPU"; then
[992]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
[224]142fi
[994]143if test -z "$BUILD_PLATFORM_ARCH"; then
[1156]144 # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
[1488]145 if test "$BUILD_PLATFORM" = "solaris"; then
[1244]146 BUILD_PLATFORM_ARCH=`isainfo | cut -f 1 -d ' '`
147
[1156]148 else
149 BUILD_PLATFORM_ARCH=`uname -m`
150 fi
[992]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)
[224]156 BUILD_PLATFORM_ARCH='x86'
157 ;;
[992]158 sparc32|sparc)
159 BUILD_PLATFORM_ARCH='sparc32'
[299]160 ;;
[992]161 sparc64)
162 BUILD_PLATFORM_ARCH='sparc64'
163 ;;
164 s390)
165 BUILD_PLATFORM_ARCH='s390'
166 ;;
[1380]167 s390x)
168 BUILD_PLATFORM_ARCH='s390x'
169 ;;
[992]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 ;;
[1380]192 arm|armv4l|armv5tel)
[992]193 BUILD_PLATFORM_ARCH='arm'
194 ;;
195 alpha)
196 BUILD_PLATFORM_ARCH='alpha'
197 ;;
198
[1510]199 *) echo "$0: unknown cpu/arch - $BUILD_PLATFORM_ARCH" 1>&${ERR_REDIR}
[224]200 sleep 1
201 exit 1
202 ;;
203 esac
204
205fi
206export BUILD_PLATFORM_ARCH
[1510]207test -n "$DBG_OPT" && echo "dbg: BUILD_PLATFORM_ARCH=$BUILD_PLATFORM_ARCH" 1>&${DBG_REDIR}
[224]208
[994]209if test -z "$BUILD_PLATFORM_CPU"; then
[992]210 BUILD_PLATFORM_CPU="blend"
211fi
212export BUILD_PLATFORM_CPU
[1510]213test -n "$DBG_OPT" && echo "dbg: BUILD_PLATFORM_CPU=$BUILD_PLATFORM_CPU" 1>&${DBG_REDIR}
[224]214
[992]215#
216# The target platform.
217# Defaults to the host when not specified.
218#
[994]219if test -z "$BUILD_TARGET"; then
220 BUILD_TARGET="$BUILD_PLATFORM"
[224]221fi
[994]222export BUILD_TARGET
[1510]223test -n "$DBG_OPT" && echo "dbg: BUILD_TARGET=$BUILD_TARGET" 1>&${DBG_REDIR}
[224]224
[994]225if test -z "$BUILD_TARGET_ARCH"; then
[992]226 BUILD_TARGET_ARCH="$BUILD_PLATFORM_ARCH"
[224]227fi
228export BUILD_TARGET_ARCH
[1510]229test -n "$DBG_OPT" && echo "dbg: BUILD_TARGET_ARCH=$BUILD_TARGET_ARCH" 1>&${DBG_REDIR}
[224]230
[994]231if 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
[224]237fi
[994]238export BUILD_TARGET_CPU
[1510]239test -n "$DBG_OPT" && echo "dbg: BUILD_TARGET_CPU=$BUILD_TARGET_CPU" 1>&${DBG_REDIR}
[224]240
241
242# Determin executable extension and path separator.
243_SUFF_EXE=
244_PATH_SEP=":"
245case "$BUILD_PLATFORM" in
[992]246 os2|win|nt)
[224]247 _SUFF_EXE=".exe"
248 _PATH_SEP=";"
249 ;;
250esac
251
[1076]252
253#
254# Calc PATH_KBUILD_BIN (but don't export it).
255#
256if test -z "$PATH_KBUILD_BIN"; then
257 PATH_KBUILD_BIN="${PATH_KBUILD}/bin/${BUILD_PLATFORM}.${BUILD_PLATFORM_ARCH}"
258fi
[1510]259test -n "$DBG_OPT" && echo "dbg: PATH_KBUILD_BIN=${PATH_KBUILD_BIN} (not exported)" 1>&${DBG_REDIR}
[1076]260
[992]261# Make shell. OS/2 and DOS only?
[1510]262if test "$BUILD_PLATFORM" = "os2"; then
263 export MAKESHELL="${PATH_KBUILD_BIN}/kmk_ash${_SUFF_EXE}";
264fi
[224]265
[992]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#
[1510]270PATH="${PATH_KBUILD_BIN}${_PATH_SEP}$PATH"
[224]271export PATH
[1510]272test -n "$DBG_OPT" && echo "dbg: PATH=$PATH" 1>&${DBG_REDIR}
[224]273
274# Sanity and x bits.
[1076]275if test ! -d "${PATH_KBUILD_BIN}/"; then
[1510]276 echo "$0: warning: The bin directory for this platform doesn't exists. (${PATH_KBUILD_BIN}/)" 1>&${ERR_REDIR}
[224]277else
[731]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;
[224]279 do
[1076]280 chmod a+x ${PATH_KBUILD_BIN}/${prog} > /dev/null 2>&1
281 if test ! -f "${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE}"; then
[1510]282 echo "$0: warning: The ${prog} program doesn't exist for this platform. (${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE})" 1>&${ERR_REDIR}
[224]283 fi
284 done
285fi
286
287unset _SUFF_EXE
288unset _PATH_SEP
289
[1510]290if 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}
302else
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 $*
[224]313 fi
314fi
[731]315
Note: See TracBrowser for help on using the repository browser.