source: trunk/kBuild/env.sh@ 1006

Last change on this file since 1006 was 994, checked in by bird, 18 years ago

logical order. use test. Made the CPU defaults consistent.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1#!/bin/bash
2# $Id: env.sh 994 2007-05-29 20:00:08Z 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# Set default build type.
46#
47if test -z "$BUILD_TYPE"; then
48 BUILD_TYPE=release
49fi
50export BUILD_TYPE
51echo "dbg: BUILD_TYPE=$BUILD_TYPE"
52
53#
54# Determin the host platform.
55#
56# The CPU isn't important, only the other two are. But, since the cpu,
57# arch and platform (and build type) share a common key space, try make
58# sure any new additions are unique. (See header.kmk, KBUILD_OSES/ARCHES.)
59#
60if test -z "$BUILD_PLATFORM"; then
61 BUILD_PLATFORM=`uname`
62 case "$BUILD_PLATFORM" in
63 linux|Linux|GNU/Linux|LINUX)
64 BUILD_PLATFORM=linux
65 ;;
66
67 os2|OS/2|OS2)
68 BUILD_PLATFORM=os2
69 ;;
70
71 freebsd|FreeBSD|FREEBSD)
72 BUILD_PLATFORM=freebsd
73 ;;
74
75 openbsd|OpenBSD|OPENBSD)
76 BUILD_PLATFORM=openbsd
77 ;;
78
79 netbsd|NetBSD|NETBSD)
80 BUILD_PLATFORM=netbsd
81 ;;
82
83 Darwin|darwin)
84 BUILD_PLATFORM=darwin
85 ;;
86
87 SunOS)
88 BUILD_PLATFORM=solaris
89 ;;
90
91 WindowsNT|CYGWIN_NT-*)
92 BUILD_PLATFORM=win
93 ;;
94
95 *)
96 echo "$0: unknown os $BUILD_PLATFORM"
97 sleep 1
98 exit 1
99 ;;
100 esac
101fi
102export BUILD_PLATFORM
103echo "dbg: BUILD_PLATFORM=$BUILD_PLATFORM"
104
105if test -z "$BUILD_PLATFORM_ARCH"; then
106 # Try deduce it from the cpu if given.
107 if test -s "$BUILD_PLATFORM_CPU"; then
108 case "$BUILD_PLATFORM_CPU" in
109 i[3456789]86)
110 BUILD_PLATFORM_ARCH='x86'
111 ;;
112 k8|k8l|k9|k10)
113 BUILD_PLATFORM_ARCH='amd64'
114 ;;
115 esac
116 fi
117fi
118if test -z "$BUILD_PLATFORM_ARCH"; then
119 # Use uname (lots of guesses here, please help clean this up...)
120 BUILD_PLATFORM_ARCH=`uname -m`
121 case "$BUILD_PLATFORM_ARCH" in
122 x86_64|AMD64|amd64|k8|k8l|k9|k10)
123 BUILD_PLATFORM_ARCH='amd64'
124 ;;
125 x86|i86pc|ia32|i[3456789]86)
126 BUILD_PLATFORM_ARCH='x86'
127 ;;
128 sparc32|sparc)
129 BUILD_PLATFORM_ARCH='sparc32'
130 ;;
131 sparc64)
132 BUILD_PLATFORM_ARCH='sparc64'
133 ;;
134 s390)
135 ## @todo: 31-bit vs 64-bit on the mainframe?
136 BUILD_PLATFORM_ARCH='s390'
137 ;;
138 ppc32|ppc|powerpc)
139 BUILD_PLATFORM_ARCH='ppc32'
140 ;;
141 ppc64|powerpc64)
142 BUILD_PLATFORM_ARCH='ppc64'
143 ;;
144 mips32|mips)
145 BUILD_PLATFORM_ARCH='mips32'
146 ;;
147 mips64)
148 BUILD_PLATFORM_ARCH='mips64'
149 ;;
150 ia64)
151 BUILD_PLATFORM_ARCH='ia64'
152 ;;
153 #hppa32|hppa|parisc32|parisc)?
154 hppa32|parisc32)
155 BUILD_PLATFORM_ARCH='hppa32'
156 ;;
157 hppa64|parisc64)
158 BUILD_PLATFORM_ARCH='hppa64'
159 ;;
160 arm)
161 BUILD_PLATFORM_ARCH='arm'
162 ;;
163 alpha)
164 BUILD_PLATFORM_ARCH='alpha'
165 ;;
166
167 *) echo "$0: unknown cpu/arch - $BUILD_PLATFORM_CPU"
168 sleep 1
169 exit 1
170 ;;
171 esac
172
173fi
174export BUILD_PLATFORM_ARCH
175echo "dbg: BUILD_PLATFORM_ARCH=$BUILD_PLATFORM_ARCH"
176
177if test -z "$BUILD_PLATFORM_CPU"; then
178 BUILD_PLATFORM_CPU="blend"
179fi
180export BUILD_PLATFORM_CPU
181echo "dbg: BUILD_PLATFORM_CPU=$BUILD_PLATFORM_CPU"
182
183#
184# The target platform.
185# Defaults to the host when not specified.
186#
187if test -z "$BUILD_TARGET"; then
188 BUILD_TARGET="$BUILD_PLATFORM"
189fi
190export BUILD_TARGET
191echo "dbg: BUILD_TARGET=$BUILD_TARGET"
192
193if test -z "$BUILD_TARGET_ARCH"; then
194 BUILD_TARGET_ARCH="$BUILD_PLATFORM_ARCH"
195fi
196export BUILD_TARGET_ARCH
197echo "dbg: BUILD_TARGET_ARCH=$BUILD_TARGET_ARCH"
198
199if test -z "$BUILD_TARGET_CPU"; then
200 if test "$BUILD_TARGET_ARCH" = "$BUILD_PLATFORM_ARCH"; then
201 BUILD_TARGET_CPU="$BUILD_PLATFORM_CPU"
202 else
203 BUILD_TARGET_CPU="blend"
204 fi
205fi
206export BUILD_TARGET_CPU
207echo "dbg: BUILD_TARGET_CPU=$BUILD_TARGET_CPU"
208
209
210# Determin executable extension and path separator.
211_SUFF_EXE=
212_PATH_SEP=":"
213case "$BUILD_PLATFORM" in
214 os2|win|nt)
215 _SUFF_EXE=".exe"
216 _PATH_SEP=";"
217 ;;
218esac
219
220# Make shell. OS/2 and DOS only?
221export MAKESHELL="$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/kmk_ash${_SUFF_EXE}";
222
223#
224# Add the bin/x.y/ directory to the PATH.
225# NOTE! Once bootstrapped this is the only thing that is actually necessary.
226#
227PATH="$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${_PATH_SEP}$PATH"
228export PATH
229echo "dbg: PATH=$PATH"
230
231# Sanity and x bits.
232if test ! -d "$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/"; then
233 echo "$0: warning: The bin directory for this platform doesn't exists. ($PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/)"
234else
235 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;
236 do
237 chmod a+x $PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${prog} > /dev/null 2>&1
238 if test ! -f "$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${prog}${_SUFF_EXE}"; then
239 echo "$0: warning: The ${prog} program doesn't exist for this platform. ($PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${prog}${_SUFF_EXE})"
240 fi
241 done
242fi
243
244unset _SUFF_EXE
245unset _PATH_SEP
246
247# Execute command or spawn shell.
248if test $# -eq 0; then
249 echo "$0: info: Spawning work shell..."
250 if test "$TERM" != 'dumb' -a -n "$BASH"; then
251 export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
252 fi
253 $SHELL -i
254else
255 echo "$0: info: Executing command: $*"
256 $*
257fi
258
Note: See TracBrowser for help on using the repository browser.