source: trunk/kBuild/env.sh@ 857

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

Solaris port.

  • Property svn:eol-style set to native
  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.2 KB
Line 
1#!/bin/bash
2# $Id: env.sh 811 2007-01-29 06:20:50Z 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# kBuild path.
30if [ -z "$PATH_KBUILD" ]; then
31 PATH_KBUILD=`dirname "$0"`
32 PATH_KBUILD=`cd "$PATH_KBUILD" ; /bin/pwd`
33fi
34if [ ! -f "$PATH_KBUILD/footer.kmk" -o ! -f "$PATH_KBUILD/header.kmk" -o ! -f "$PATH_KBUILD/rules.kmk" ]; then
35 echo "$0: error: PATH_KBUILD ($PATH_KBUILD) is not pointing to a popluated kBuild directory.";
36 sleep 1;
37 exit 1;
38fi
39export PATH_KBUILD
40echo "dbg: PATH_KBUILD=$PATH_KBUILD"
41
42# Type.
43if [ -z "$BUILD_TYPE" ]; then
44 BUILD_TYPE=release
45fi
46export BUILD_TYPE
47echo "dbg: BUILD_TYPE=$BUILD_TYPE"
48
49
50# Host platform.
51if [ -z "$BUILD_PLATFORM_CPU" ]; then
52 BUILD_PLATFORM_CPU=`uname -m`
53 case "$BUILD_PLATFORM_CPU" in
54 x86_64|AMD64|amd64)
55 BUILD_PLATFORM_CPU='k8'
56 ;;
57 esac
58fi
59export BUILD_PLATFORM_CPU
60echo "dbg: BUILD_PLATFORM_CPU=$BUILD_PLATFORM_CPU"
61
62if [ -z "$BUILD_PLATFORM_ARCH" ]; then
63 case "$BUILD_PLATFORM_CPU" in
64 i[3456789]86|i86pc)
65 BUILD_PLATFORM_ARCH='x86'
66 ;;
67 k8|k8l|k9|k10)
68 BUILD_PLATFORM_ARCH='amd64'
69 ;;
70 *) echo "$0: unknown cpu/arch - $BUILD_PLATFORM_CPU"
71 sleep 1
72 exit 1
73 ;;
74 esac
75
76fi
77export BUILD_PLATFORM_ARCH
78echo "dbg: BUILD_PLATFORM_ARCH=$BUILD_PLATFORM_ARCH"
79
80
81if [ -z "$BUILD_PLATFORM" ]; then
82 BUILD_PLATFORM=`uname`
83 case "$BUILD_PLATFORM" in
84 linux|Linux|GNU/Linux|LINUX)
85 BUILD_PLATFORM=linux
86 ;;
87
88 os2|OS/2|OS2)
89 BUILD_PLATFORM=os2
90 ;;
91
92 freebsd|FreeBSD|FREEBSD)
93 BUILD_PLATFORM=freebsd
94 ;;
95
96 openbsd|OpenBSD|OPENBSD)
97 BUILD_PLATFORM=openbsd
98 ;;
99
100 netbsd|NetBSD|NETBSD)
101 BUILD_PLATFORM=netbsd
102 ;;
103
104 Darwin|darwin)
105 BUILD_PLATFORM=darwin
106 ;;
107
108 SunOS)
109 BUILD_PLATFORM=solaris
110 ;;
111
112 WindowsNT|CYGWIN_NT-*)
113 BUILD_PLATFORM=win
114 ;;
115
116 *)
117 echo "$0: unknown os $BUILD_PLATFORM"
118 sleep 1
119 exit 1
120 ;;
121 esac
122fi
123export BUILD_PLATFORM
124echo "dbg: BUILD_PLATFORM=$BUILD_PLATFORM"
125
126
127# Target platform.
128if [ -z "$BUILD_TARGET_CPU" ]; then
129 BUILD_TARGET_CPU=$BUILD_PLATFORM_CPU
130fi
131export BUILD_TARGET_CPU
132echo "dbg: BUILD_TARGET_CPU=$BUILD_TARGET_CPU"
133
134if [ -z "$BUILD_TARGET_ARCH" ]; then
135 case "$BUILD_TARGET_CPU" in
136 i[3456789]86|i86pc)
137 BUILD_TARGET_ARCH='x86'
138 ;;
139 k8|k8l|k9|k10)
140 BUILD_TARGET_ARCH='amd64'
141 ;;
142 *) echo "$0: unknown cpu/arch - $BUILD_TARGET_CPU"
143 sleep 1
144 exit 1
145 ;;
146 esac
147
148fi
149export BUILD_TARGET_ARCH
150echo "dbg: BUILD_TARGET_ARCH=$BUILD_TARGET_ARCH"
151
152if [ -z "$BUILD_TARGET" ]; then
153 BUILD_TARGET=$BUILD_PLATFORM
154fi
155export BUILD_TARGET
156echo "dbg: BUILD_TARGET=$BUILD_TARGET"
157
158
159# Determin executable extension and path separator.
160_SUFF_EXE=
161_PATH_SEP=":"
162case "$BUILD_PLATFORM" in
163 os2|win|win32|win64|nt|winnt|win2k|winxp)
164 _SUFF_EXE=".exe"
165 _PATH_SEP=";"
166 ;;
167esac
168
169# Make shell
170export MAKESHELL="$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/kmk_ash${_SUFF_EXE}";
171
172# The PATH.
173PATH="$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${_PATH_SEP}$PATH"
174export PATH
175echo "dbg: PATH=$PATH"
176
177# Sanity and x bits.
178if [ ! -d "$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/" ]; then
179 echo "$0: warning: The bin directory for this platform doesn't exists. ($PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/)"
180else
181 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;
182 do
183 chmod a+x $PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${prog} > /dev/null 2>&1
184 if [ ! -f "$PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${prog}${_SUFF_EXE}" ]; then
185 echo "$0: warning: The ${prog} program doesn't exist for this platform. ($PATH_KBUILD/bin/$BUILD_PLATFORM.$BUILD_PLATFORM_ARCH/${prog}${_SUFF_EXE})"
186 fi
187 done
188fi
189
190unset _SUFF_EXE
191unset _PATH_SEP
192
193# Execute command or spawn shell.
194if [ $# -eq 0 ]; then
195 echo "$0: info: Spawning work shell..."
196 if [ "$TERM" != 'dumb' ] && [ -n "$BASH" ]; then
197 export PS1='\[\033[01;32m\]\u@\h \[\033[01;34m\]\W \$ \[\033[00m\]'
198 fi
199 $SHELL -i
200else
201 echo "$0: info: Executing command: $*"
202 $*
203fi
204
Note: See TracBrowser for help on using the repository browser.