-
Notifications
You must be signed in to change notification settings - Fork 4
/
configure
executable file
·260 lines (220 loc) · 4.33 KB
/
configure
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/bin/bash
if ROOT=$(pwd) && HOST_SYSTEM=$(uname -s) && HOST_ARCH=$(uname -p)
then
#
# Rewrite uname values to a pair from these sets
#
# HOST_SYSTEM := { MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Irix, Plan9 }
#
# HOST_ARCH := { 386, mips, power, sparc }
#
case ${HOST_SYSTEM} in
Windows*|CYGWIN*|MINGW*)
HOST_SYSTEM="Nt"
;;
Darwin)
HOST_SYSTEM="MacOSX"
;;
SunOS)
HOST_SYSTEM="Solaris"
;;
esac
if [ "unknown" = "${HOST_ARCH}" ]
then
HOST_ARCH=$(uname -m)
fi
case ${HOST_ARCH} in
ppc|powerpc)
HOST_ARCH="power"
;;
x86|x86_32|i386|i586|i686|486|586|686)
HOST_ARCH="386"
;;
x86_64)
HOST_ARCH="amd64"
;;
esac
#
# Initialize configuration
#
SYSHOST=${HOST_SYSTEM}
SYSTARG=${HOST_SYSTEM}
OBJTYPE=${HOST_ARCH}
#
# Optionally modify configuration
#
while [ -n "${1}" ]
do
case $1 in
*clean)
rm -f mkconfig env bin
#1>&2 echo ok
exit 0
;;
--host)
shift
HOST_SYSTEM=$1
shift
SYSHOST=${HOST_SYSTEM}
SYSTARG=${HOST_SYSTEM}
;;
--target)
shift
SYSTARG=$1
shift
;;
--object)
shift
OBJTYPE=$1
shift
;;
--help|-help|-h|-?)
cat<<EOF>&2
Configuration options (in order)
--host <Host system type> (eg, MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Plan9)
--target <Target system type> (eg, MacOSX, Linux, Nt, Solaris, FreeBSD, NetBSD, Irix, Plan9)
--object <Target object type> (eg, 386, mips, power, sparc)
Usage
Configuration options must be employed in the order shown above.
Running with no arguments should produce a valid result.
Please contribute to this project by ensuring that any found bugs
have been reported via
http://code.google.com/p/ken-cc/issues/list
for your configuration
HOST_SYSTEM=${HOST_SYSTEM}
HOST_ARCH=${HOST_ARCH}
Cleaning (or unconfiguring)
Run
./configure clean
or
./configure --clean
to remove the products of this script.
EOF
exit 1
;;
esac
done
#
# Host bin
#
BINDIR=${HOST_SYSTEM}/${HOST_ARCH}
#
# Target bin
#
OBJDIR=${SYSTARG}/${OBJTYPE}
#
# Sanity testing...
#
if [ -z "${SYSHOST}" ]||[ -z "${SYSTARG}" ]||[ -z "${OBJTYPE}" ]
then
cat<<EOF>&2
Input error
EOF
exit 1
elif [ ! -d "${BINDIR}" ]
then
cat<<EOF>&2
Host type selection error in one or both of
HOST_SYSTEM '${HOST_SYSTEM}'
HOST_ARCH '${HOST_ARCH}'
EOF
exit 1
elif [ ! -d "${OBJDIR}" ]
then
cat<<EOF>&2
Target type selection error in one or both of
TARGET '${SYSTARG}'
OBJECT '${OBJTYPE}'
EOF
exit 1
else
#
# Generate configuration
#
cat<<EOF>mkconfig
#
# Set the following 4 variables. The host system is the system where
# the software will be built; the target system is where it will run.
# They are almost always the same.
# On Nt systems, the ROOT path MUST be of the form 'drive:/path'
ROOT=${ROOT}
# build system OS type
SYSHOST=${SYSHOST}
# target system OS type
SYSTARG=${SYSTARG}
# target system object type
OBJTYPE=${OBJTYPE}
#
# no changes required beyond this point
#
OBJDIR=\$SYSTARG/\$OBJTYPE
<\$ROOT/mkfiles/mkhost-\$SYSHOST # variables appropriate for host system
<\$ROOT/mkfiles/mkfile-\$SYSTARG-\$OBJTYPE # variables used to build target object type
EOF
fi
#
# Report product
#
cat<<EOF
Successfully configured and wrote 'mkconfig'
EOF
#
# Configure host binaries into 'env' path
#
if [ -e bin ]
then
rm -f bin
fi
if ln -s ${BINDIR}/bin bin
then
cat<<EOF
Successfully configured host path '$(pwd)/bin'
EOF
else
cat<<EOF>&2
Error linking host path 'ln -s ${BINDIR}/bin bin'
EOF
exit 1
fi
#
# Configure 'env' script
#
ewd=$(pwd)
ebp=${ewd}/bin
cat<<EOF>env
#
# Generated by ${ewd}/configure. See ./configure --help.
#
# Usage
# Run
# . ./env
# or
# source ./env
#
# in this directory
# to initialize this development environment
#
PATH=${ebp}:\$(echo \${PATH} | sed 's%${ebp}:%%g; s%:${ebp}%%g')
#
# Convenience for running commands outside 'mk'...
#
ROOT=${ROOT}
#
# Conveniences for sourcing and targeting commands as in 'mk'...
#
SYSTARG=${SYSTARG}
OBJTYPE=${OBJTYPE}
OBJDIR=\${SYSTARG}/\${OBJTYPE}
EOF
cat<<EOF>&2
Employ command ". ./env" in this directory to initialize usage,
or PREPEND "$(pwd)/bin" to your PATH.
EOF
exit 0
else
cat<<EOF>&2
Error running commands 'pwd' or 'uname'.
Unable to configure.
EOF
exit 1
fi