forked from LemonBoy/PrexDS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
configure
executable file
·400 lines (354 loc) · 6.3 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
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
#! /bin/sh
#
# Prex configure script
#
# Required host commands: echo, pwd, expr, uname, tr, cat, cp
#
usage()
{
if [ -n "$*" ]; then
echo "configure: $*"
fi
echo
echo "Usage: configure [options]"
echo "Options:"
echo " --help print this message"
echo " --target=TARGET use TARGET for target system"
echo " --profile=PROFILE use PROFILE for target profile"
echo " --cross-prefix=PREFIX use PREFIX for compile tools"
echo " --cc=CC use CC as C compiler"
echo " --no-debug disable all debug features"
exit 1
}
quit()
{
echo "Error: $1"
exit 1
}
setdefaults()
{
target=""
profile=""
prefix=""
srcdir=`pwd`
# Use GNU tools as default toolchain
cc="gcc"
cpp="cpp"
as="as"
ld="ld"
ar="ar"
objcopy="objcopy"
objdump="objdump"
strip="strip"
}
checkpath()
{
# Input files
CONFIG_IN=$srcdir/conf/$arch/$platform$profile
SECURITY_IN=$srcdir/conf/etc/security
# Output files
CONFIG_MK=$srcdir/conf/config.mk
CONFIG_H=$srcdir/conf/config.h
CONFIG_LD=$srcdir/conf/config.ld
DRVTAB_H=$srcdir/conf/drvtab.h
DRVTAB_TMP=$srcdir/conf/drvtab.tmp
CAPTAB_H=$srcdir/conf/captab.h
if [ ! -f $CONFIG_IN ]; then
quit "Can not find $CONFIG_IN for '$target' target"
fi
}
parseargs()
{
while [ -n "$1" ]; do
case $1 in
--*=*)
option=`expr "x$1" : 'x\([^=]*\)='`
optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
;;
--*)
option=$1
;;
*)
usage "unrecognized option $1"
;;
esac
case $option in
--help)
usage
;;
--target)
target=$optarg
;;
--profile)
profile="-$optarg"
;;
--cross-prefix)
prefix=$optarg
;;
--cc)
cc=$optarg
;;
--no-debug)
nodebug=1
;;
*)
usage "Unrecognized option $1"
;;
esac
shift
done
}
gettarget()
{
if [ -z "$target" ]; then
echo "Warning: '--target' option was not specified"
echo "The target system was set to 'x86-pc'"
target="x86-pc"
fi
arch=`expr "x$target" : 'x\([^=]*\)-'`
platform=`expr "x$target" : 'x[^=]*-\(.*\)'`
case "$arch" in
x86|arm|ppc|sh|mips)
;;
*)
quit "Unkown target architecture: $arch"
;;
esac
}
gethost()
{
# 'uname' command may be unavailable under Windows.
# So, we check MACHTYPE variable for cygwin/mingw at first.
case "$MACHTYPE" in
*-cygwin)
hostname="CYGWIN"
;;
*-msys)
hostname="MINGW"
;;
*)
hostname=`uname -s`
;;
esac
}
# Set the gcc option only when it's supported.
setgccoption()
{
echo "checking $1"
if ${prefix}${cc} $1 -S -xc /dev/null -o /dev/null > /dev/null 2>&1; then
echo "GCCFLAGS+= $1" >> $CONFIG_MK
fi
}
checktools()
{
#
# Check compiler version
#
case "$cc" in
*gcc*)
setgccoption "-fno-stack-protector"
;;
esac
}
settools()
{
#
# Set host specific tool settings
#
case "$hostname" in
*BSD)
;;
SunOS)
# Solaris
as="gas"
ld="gld"
ar="gar"
strip="gstrip"
objcopy="gobjcopy"
objdump="gobjdump"
;;
CYGWIN*|MINGW*)
case "$arch" in
x86)
prefix="i386-elf-"
;;
ppc)
prefix="powerpc-elf-"
;;
*)
prefix="$arch-elf-"
;;
esac
;;
esac
#
# Set tools
#
case "$cc" in
*gcc*)
cc_type="_GNUC_"
;;
pcc)
cc_type="_PCC_"
;;
suncc)
cc_type="_SUNPRO_C_"
cc="suncc"
;;
*)
quit "Unkown compiler: $cc"
;;
esac
}
options()
{
param=`expr "x$1" : 'x\([^= ]*\)'`
value=`expr "x$1" : 'x[^=]*=\([A-Za-z0-9\.]*\)'`
if [ "x$value" = x ] ; then
echo "CONFIG_${param}=y"
echo "CONFIG_${param}=y" >> $CONFIG_MK
echo "#define CONFIG_${param} y" >> $CONFIG_H
else
echo "CONFIG_${param}=${value}"
echo "CONFIG_${param}=${value}" >> $CONFIG_MK
echo "#define CONFIG_${param} ${value}" >> $CONFIG_H
fi
}
device()
{
param=`echo $1 | tr '[a-z]' '[A-Z]'`
echo "CONFIG_${param}=y"
echo "CONFIG_${param}=y" >> $CONFIG_MK
echo "#define CONFIG_${param} y" >> $CONFIG_H
echo "extern struct driver $1_driver;" >> $DRVTAB_H
echo " &$1_driver," >> $DRVTAB_TMP
}
capability()
{
{
echo "{"
echo " \"$1\","
shift 1
while [ "$1" != "" ] ; do
if [ "$2" != "" ] ; then
echo " $1 |"
else
echo " $1"
fi
shift 1
done
echo "},"
} >> $CAPTAB_H
}
memory()
{
echo "CONFIG_$1=$2"
echo "CONFIG_$1=$2" >> $CONFIG_MK
echo "CONFIG_$1 = $2 ;" >> $CONFIG_LD
echo "#define CONFIG_$1 $2" >> $CONFIG_H
}
command()
{
param=`echo $1 | tr '[a-z]' '[A-Z]'`
echo "CONFIG_CMD_${param}=y"
echo "CONFIG_CMD_${param}=y" >> $CONFIG_MK
echo "#define CONFIG_CMD_${param} y" >> $CONFIG_H
}
parseconfig()
{
while read line; do
read cmd rest <<-END_OF_COMMAND
$line
END_OF_COMMAND
case "$cmd" in
options)
options $rest
;;
device)
device $rest
;;
capability)
capability $rest
;;
makeoptions)
echo "$rest"
echo "$rest" >> $CONFIG_MK
;;
memory)
memory $rest
;;
command)
command $rest
;;
esac
done < $1
}
main()
{
[ -d conf ] ||
quit "configure must be run from the top source level"
#
# Process input arguments
#
setdefaults
parseargs "$@"
gettarget
checkpath
gethost
settools
echo "#" > $CONFIG_MK
echo "# Automatically generated file. Don't edit" >> $CONFIG_MK
echo "#" >> $CONFIG_MK
echo "_CONFIG_MK_=1" >> $CONFIG_MK
echo "/*" > $CONFIG_H
echo " * Automatically generated file. Don't edit" >> $CONFIG_H
echo " */" >> $CONFIG_H
cp $CONFIG_H $CONFIG_LD
cp $CONFIG_H $DRVTAB_H
cp $CONFIG_H $CAPTAB_H
echo "" > $DRVTAB_TMP
echo "struct driver *driver_table[] = {" >> $DRVTAB_TMP
echo "" >> $CAPTAB_H
echo "const struct cap_map cap_table[] = {" >> $CAPTAB_H
#
# Setup build settings
#
{
echo "ARCH=${arch}"
echo "PLATFORM=${platform}"
echo "PROFILE=${platform}${profile}"
if [ -n "${nodebug}" ]; then
echo "NDEBUG=1"
fi
echo "${cc_type}=1"
echo "CC=${prefix}${cc}"
echo "CPP=${prefix}${cpp}"
echo "AS=${prefix}${as}"
echo "LD=${prefix}${ld}"
echo "AR=${prefix}${ar}"
echo "OBJCOPY=${prefix}${objcopy}"
echo "OBJDUMP=${prefix}${objdump}"
echo "STRIP=${prefix}${strip}"
} >> $CONFIG_MK
#
# Adjust tool options
#
checktools
#
# Generate configuration parameters
#
echo "checking configuration files..."
echo "#define CONFIG_MACHINE ${target}" >> $CONFIG_H
echo "#define CONFIG_PROFILE ${profile}" >> $CONFIG_H
parseconfig $CONFIG_IN
parseconfig $SECURITY_IN
cat $DRVTAB_TMP >> $DRVTAB_H
echo "};" >> $DRVTAB_H
rm -f $DRVTAB_TMP
echo "{ NULL, 0 }" >> $CAPTAB_H
echo "};" >> $CAPTAB_H
echo
echo "Prex is now hopefully configured for your setup."
echo "Now you must run a make."
}
main "$@"