source: trunk/kBuild/env.sh@ 1176

Last change on this file since 1176 was 1156, checked in by bird, 18 years ago

isainfo on solaris, uname doesn't tell the truth.

  • Property svn:eol-style set to LF
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 7.0 KB
Line 
1#!/bin/bash
2# $Id: env.sh 1156 2007-09-29 00:58:41Z bird $
3## @file
4#
5# Environment setup script.
6#
7# Copyright (c) 2005-2007 knut st. osmundsen <bird-kBuild-spam@anduin.net>
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#
27#set -x
28
29#
30# Determin the kBuild path from the script location.
31#
32if test -z "$PATH_KBUILD"; then
33 PATH_KBUILD=`dirname "$0"`
34 PATH_KBUILD=`cd "$PATH_KBUILD" ; /bin/pwd`
35fi
36if test ! -f "$PATH_KBUILD/footer.kmk" -o ! -f "$PATH_KBUILD/header.kmk" -o ! -f "$PATH_KBUILD/rules.kmk"; then
37 echo "$0: error: PATH_KBUILD ($PATH_KBUILD) is not pointing to a popluated kBuild directory.";
38 sleep 1;
39 exit 1;
40fi
41export PATH_KBUILD
42echo "dbg: PATH_KBUILD=$PATH_KBUILD"
43
44
45#
46# Set default build type.
47#
48if test -z "$BUILD_TYPE"; then
49 BUILD_TYPE=release
50fi
51export BUILD_TYPE
52echo "dbg: BUILD_TYPE=$BUILD_TYPE"
53
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#
61if 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
102fi
103export BUILD_PLATFORM
104echo "dbg: BUILD_PLATFORM=$BUILD_PLATFORM"
105
106if test -z "$BUILD_PLATFORM_ARCH"; then
107 # Try deduce it from the cpu if given.
108 if test -s "$BUILD_PLATFORM_CPU"; then
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
118fi
119if test -z "$BUILD_PLATFORM_ARCH"; then
120 # Use uname -m or isainfo (lots of guesses here, please help clean this up...)
121 if test "$BUILD_PLATFORM" == "solaris"; then
122 BUILD_PLATFORM_ARCH=`isainfo`
123 else
124 BUILD_PLATFORM_ARCH=`uname -m`
125 fi
126 case "$BUILD_PLATFORM_ARCH" in
127 x86_64|AMD64|amd64|k8|k8l|k9|k10)
128 BUILD_PLATFORM_ARCH='amd64'
129 ;;
130 x86|i86pc|ia32|i[3456789]86)
131 BUILD_PLATFORM_ARCH='x86'
132 ;;
133 sparc32|sparc)
134 BUILD_PLATFORM_ARCH='sparc32'
135 ;;
136 sparc64)
137 BUILD_PLATFORM_ARCH='sparc64'
138 ;;
139 s390)
140 ## @todo: 31-bit vs 64-bit on the mainframe?
141 BUILD_PLATFORM_ARCH='s390'
142 ;;
143 ppc32|ppc|powerpc)
144 BUILD_PLATFORM_ARCH='ppc32'
145 ;;
146 ppc64|powerpc64)
147 BUILD_PLATFORM_ARCH='ppc64'
148 ;;
149 mips32|mips)
150 BUILD_PLATFORM_ARCH='mips32'
151 ;;
152 mips64)
153 BUILD_PLATFORM_ARCH='mips64'
154 ;;
155 ia64)
156 BUILD_PLATFORM_ARCH='ia64'
157 ;;
158 #hppa32|hppa|parisc32|parisc)?
159 hppa32|parisc32)
160 BUILD_PLATFORM_ARCH='hppa32'
161 ;;
162 hppa64|parisc64)
163 BUILD_PLATFORM_ARCH='hppa64'
164 ;;
165 arm|armv4l)
166 BUILD_PLATFORM_ARCH='arm'
167 ;;
168 alpha)
169 BUILD_PLATFORM_ARCH='alpha'
170 ;;
171
172 *) echo "$0: unknown cpu/arch - $BUILD_PLATFORM_ARCH"
173 sleep 1
174 exit 1
175 ;;
176 esac
177
178fi
179export BUILD_PLATFORM_ARCH
180echo "dbg: BUILD_PLATFORM_ARCH=$BUILD_PLATFORM_ARCH"
181
182if test -z "$BUILD_PLATFORM_CPU"; then
183 BUILD_PLATFORM_CPU="blend"
184fi
185export BUILD_PLATFORM_CPU
186echo "dbg: BUILD_PLATFORM_CPU=$BUILD_PLATFORM_CPU"
187
188#
189# The target platform.
190# Defaults to the host when not specified.
191#
192if test -z "$BUILD_TARGET"; then
193 BUILD_TARGET="$BUILD_PLATFORM"
194fi
195export BUILD_TARGET
196echo "dbg: BUILD_TARGET=$BUILD_TARGET"
197
198if test -z "$BUILD_TARGET_ARCH"; then
199 BUILD_TARGET_ARCH="$BUILD_PLATFORM_ARCH"
200fi
201export BUILD_TARGET_ARCH
202echo "dbg: BUILD_TARGET_ARCH=$BUILD_TARGET_ARCH"
203
204if test -z "$BUILD_TARGET_CPU"; then
205 if test "$BUILD_TARGET_ARCH" = "$BUILD_PLATFORM_ARCH"; then
206 BUILD_TARGET_CPU="$BUILD_PLATFORM_CPU"
207 else
208 BUILD_TARGET_CPU="blend"
209 fi
210fi
211export BUILD_TARGET_CPU
212echo "dbg: BUILD_TARGET_CPU=$BUILD_TARGET_CPU"
213
214
215# Determin executable extension and path separator.
216_SUFF_EXE=
217_PATH_SEP=":"
218case "$BUILD_PLATFORM" in
219 os2|win|nt)
220 _SUFF_EXE=".exe"
221 _PATH_SEP=";"
222 ;;
223esac
224
225
226#
227# Calc PATH_KBUILD_BIN (but don't export it).
228#
229if test -z "$PATH_KBUILD_BIN"; then
230 PATH_KBUILD_BIN="${PATH_KBUILD}/bin/${BUILD_PLATFORM}.${BUILD_PLATFORM_ARCH}"
231fi
232echo "dbg: PATH_KBUILD_BIN=${PATH_KBUILD_BIN} (not exported)"
233
234# Make shell. OS/2 and DOS only?
235export MAKESHELL="${PATH_KBUILD_BIN}/kmk_ash${_SUFF_EXE}";
236
237#
238# Add the bin/x.y/ directory to the PATH.
239# NOTE! Once bootstrapped this is the only thing that is actually necessary.
240#
241PATH="${PATH_KBUILD_BIN}/${_PATH_SEP}$PATH"
242export PATH
243echo "dbg: PATH=$PATH"
244
245# Sanity and x bits.
246if test ! -d "${PATH_KBUILD_BIN}/"; then
247 echo "$0: warning: The bin directory for this platform doesn't exists. (${PATH_KBUILD_BIN}/)"
248else
249 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;
250 do
251 chmod a+x ${PATH_KBUILD_BIN}/${prog} > /dev/null 2>&1
252 if test ! -f "${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE}"; then
253 echo "$0: warning: The ${prog} program doesn't exist for this platform. (${PATH_KBUILD_BIN}/${prog}${_SUFF_EXE})"
254 fi
255 done
256fi
257
258unset _SUFF_EXE
259unset _PATH_SEP
260
261# Execute command or spawn shell.
262if test $# -eq 0; then
263 echo "$0: info: Spawning work shell..."
264 if test "$TERM" != 'dumb' -a -n "$BASH"; then
265 export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
266 fi
267 $SHELL -i
268else
269 echo "$0: info: Executing command: $*"
270 $*
271fi
272
Note: See TracBrowser for help on using the repository browser.