source: trunk/kBuild/env.sh@ 993

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

typo.

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