scoutos / prex-0.9.0 / configure @ dbe4fa43
History | View | Annotate | Download (6.3 KB)
1 |
#! /bin/sh |
---|---|
2 |
# |
3 |
# Prex configure script |
4 |
# |
5 |
# Required host commands: echo, pwd, expr, uname, tr, cat, cp |
6 |
# |
7 |
|
8 |
usage() |
9 |
{ |
10 |
if [ -n "$*" ]; then |
11 |
echo "configure: $*" |
12 |
fi |
13 |
echo |
14 |
echo "Usage: configure [options]" |
15 |
echo "Options:" |
16 |
echo " --help print this message" |
17 |
echo " --target=TARGET use TARGET for target system" |
18 |
echo " --profile=PROFILE use PROFILE for target profile" |
19 |
echo " --cross-prefix=PREFIX use PREFIX for compile tools" |
20 |
echo " --cc=CC use CC as C compiler" |
21 |
echo " --no-debug disable all debug features" |
22 |
|
23 |
exit 1 |
24 |
} |
25 |
|
26 |
quit() |
27 |
{ |
28 |
echo "Error: $1" |
29 |
exit 1 |
30 |
} |
31 |
|
32 |
setdefaults() |
33 |
{ |
34 |
target="" |
35 |
profile="" |
36 |
prefix="" |
37 |
srcdir=`pwd` |
38 |
|
39 |
# Use GNU tools as default toolchain |
40 |
cc="gcc" |
41 |
cpp="cpp" |
42 |
as="as" |
43 |
ld="ld" |
44 |
ar="ar" |
45 |
objcopy="objcopy" |
46 |
objdump="objdump" |
47 |
strip="strip" |
48 |
} |
49 |
|
50 |
checkpath() |
51 |
{ |
52 |
# Input files |
53 |
CONFIG_IN=$srcdir/conf/$arch/$platform$profile |
54 |
SECURITY_IN=$srcdir/conf/etc/security |
55 |
|
56 |
# Output files |
57 |
CONFIG_MK=$srcdir/conf/config.mk |
58 |
CONFIG_H=$srcdir/conf/config.h |
59 |
CONFIG_LD=$srcdir/conf/config.ld |
60 |
DRVTAB_H=$srcdir/conf/drvtab.h |
61 |
DRVTAB_TMP=$srcdir/conf/drvtab.tmp |
62 |
CAPTAB_H=$srcdir/conf/captab.h |
63 |
|
64 |
if [ ! -f $CONFIG_IN ]; then |
65 |
quit "Can not find $CONFIG_IN for '$target' target" |
66 |
fi |
67 |
} |
68 |
|
69 |
parseargs() |
70 |
{ |
71 |
while [ -n "$1" ]; do |
72 |
case $1 in |
73 |
--*=*) |
74 |
option=`expr "x$1" : 'x\([^=]*\)='` |
75 |
optarg=`expr "x$1" : 'x[^=]*=\(.*\)'` |
76 |
;; |
77 |
--*) |
78 |
option=$1 |
79 |
;; |
80 |
*) |
81 |
usage "unrecognized option $1" |
82 |
;; |
83 |
esac |
84 |
|
85 |
case $option in |
86 |
--help) |
87 |
usage |
88 |
;; |
89 |
--target) |
90 |
target=$optarg |
91 |
;; |
92 |
--profile) |
93 |
profile="-$optarg" |
94 |
;; |
95 |
--cross-prefix) |
96 |
prefix=$optarg |
97 |
;; |
98 |
--cc) |
99 |
cc=$optarg |
100 |
;; |
101 |
--no-debug) |
102 |
nodebug=1 |
103 |
;; |
104 |
*) |
105 |
usage "Unrecognized option $1" |
106 |
;; |
107 |
esac |
108 |
shift |
109 |
done |
110 |
} |
111 |
|
112 |
gettarget() |
113 |
{ |
114 |
if [ -z "$target" ]; then |
115 |
echo "Warning: '--target' option was not specified" |
116 |
echo "The target system was set to 'x86-pc'" |
117 |
target="x86-pc" |
118 |
fi |
119 |
|
120 |
arch=`expr "x$target" : 'x\([^=]*\)-'` |
121 |
platform=`expr "x$target" : 'x[^=]*-\(.*\)'` |
122 |
|
123 |
case "$arch" in |
124 |
x86|arm|ppc|sh|mips) |
125 |
;; |
126 |
*) |
127 |
quit "Unkown target architecture: $arch" |
128 |
;; |
129 |
esac |
130 |
} |
131 |
|
132 |
gethost() |
133 |
{ |
134 |
# 'uname' command may be unavailable under Windows. |
135 |
# So, we check MACHTYPE variable for cygwin/mingw at first. |
136 |
case "$MACHTYPE" in |
137 |
*-cygwin) |
138 |
hostname="CYGWIN" |
139 |
;; |
140 |
*-msys) |
141 |
hostname="MINGW" |
142 |
;; |
143 |
*) |
144 |
hostname=`uname -s` |
145 |
;; |
146 |
esac |
147 |
} |
148 |
|
149 |
# Set the gcc option only when it's supported. |
150 |
setgccoption() |
151 |
{ |
152 |
echo "checking $1" |
153 |
if ${prefix}${cc} $1 -S -xc /dev/null -o /dev/null > /dev/null 2>&1; then |
154 |
echo "GCCFLAGS+= $1" >> $CONFIG_MK |
155 |
fi |
156 |
} |
157 |
|
158 |
checktools() |
159 |
{ |
160 |
# |
161 |
# Check compiler version |
162 |
# |
163 |
case "$cc" in |
164 |
*gcc*) |
165 |
setgccoption "-fno-stack-protector" |
166 |
;; |
167 |
esac |
168 |
} |
169 |
|
170 |
settools() |
171 |
{ |
172 |
# |
173 |
# Set host specific tool settings |
174 |
# |
175 |
case "$hostname" in |
176 |
*BSD) |
177 |
;; |
178 |
SunOS) |
179 |
# Solaris |
180 |
as="gas" |
181 |
ld="gld" |
182 |
ar="gar" |
183 |
strip="gstrip" |
184 |
objcopy="gobjcopy" |
185 |
objdump="gobjdump" |
186 |
;; |
187 |
CYGWIN*|MINGW*) |
188 |
case "$arch" in |
189 |
x86) |
190 |
prefix="i386-elf-" |
191 |
;; |
192 |
ppc) |
193 |
prefix="powerpc-elf-" |
194 |
;; |
195 |
*) |
196 |
prefix="$arch-elf-" |
197 |
;; |
198 |
esac |
199 |
;; |
200 |
esac |
201 |
|
202 |
# |
203 |
# Set tools |
204 |
# |
205 |
case "$cc" in |
206 |
*gcc*) |
207 |
cc_type="_GNUC_" |
208 |
;; |
209 |
pcc) |
210 |
cc_type="_PCC_" |
211 |
;; |
212 |
suncc) |
213 |
cc_type="_SUNPRO_C_" |
214 |
cc="suncc" |
215 |
;; |
216 |
*) |
217 |
quit "Unkown compiler: $cc" |
218 |
;; |
219 |
esac |
220 |
} |
221 |
|
222 |
options() |
223 |
{ |
224 |
param=`expr "x$1" : 'x\([^= ]*\)'` |
225 |
value=`expr "x$1" : 'x[^=]*=\([A-Za-z0-9\.]*\)'` |
226 |
|
227 |
if [ "x$value" = x ] ; then |
228 |
echo "CONFIG_${param}=y" |
229 |
echo "CONFIG_${param}=y" >> $CONFIG_MK |
230 |
echo "#define CONFIG_${param} y" >> $CONFIG_H |
231 |
else |
232 |
echo "CONFIG_${param}=${value}" |
233 |
echo "CONFIG_${param}=${value}" >> $CONFIG_MK |
234 |
echo "#define CONFIG_${param} ${value}" >> $CONFIG_H |
235 |
fi |
236 |
} |
237 |
|
238 |
device() |
239 |
{ |
240 |
param=`echo $1 | tr '[a-z]' '[A-Z]'` |
241 |
|
242 |
echo "CONFIG_${param}=y" |
243 |
echo "CONFIG_${param}=y" >> $CONFIG_MK |
244 |
echo "#define CONFIG_${param} y" >> $CONFIG_H |
245 |
|
246 |
echo "extern struct driver $1_driver;" >> $DRVTAB_H |
247 |
echo " &$1_driver," >> $DRVTAB_TMP |
248 |
} |
249 |
|
250 |
capability() |
251 |
{ |
252 |
{ |
253 |
echo "{" |
254 |
echo " \"$1\"," |
255 |
shift 1 |
256 |
while [ "$1" != "" ] ; do |
257 |
if [ "$2" != "" ] ; then |
258 |
echo " $1 |" |
259 |
else |
260 |
echo " $1" |
261 |
fi |
262 |
shift 1 |
263 |
done |
264 |
echo "}," |
265 |
} >> $CAPTAB_H |
266 |
} |
267 |
|
268 |
memory() |
269 |
{ |
270 |
echo "CONFIG_$1=$2" |
271 |
echo "CONFIG_$1=$2" >> $CONFIG_MK |
272 |
echo "CONFIG_$1 = $2 ;" >> $CONFIG_LD |
273 |
echo "#define CONFIG_$1 $2" >> $CONFIG_H |
274 |
} |
275 |
|
276 |
command() |
277 |
{ |
278 |
param=`echo $1 | tr '[a-z]' '[A-Z]'` |
279 |
|
280 |
echo "CONFIG_CMD_${param}=y" |
281 |
echo "CONFIG_CMD_${param}=y" >> $CONFIG_MK |
282 |
echo "#define CONFIG_CMD_${param} y" >> $CONFIG_H |
283 |
} |
284 |
|
285 |
parseconfig() |
286 |
{ |
287 |
while read line; do |
288 |
read cmd rest <<-END_OF_COMMAND |
289 |
$line |
290 |
END_OF_COMMAND |
291 |
|
292 |
case "$cmd" in |
293 |
options) |
294 |
options $rest |
295 |
;; |
296 |
device) |
297 |
device $rest |
298 |
;; |
299 |
capability) |
300 |
capability $rest |
301 |
;; |
302 |
makeoptions) |
303 |
echo "$rest" |
304 |
echo "$rest" >> $CONFIG_MK |
305 |
;; |
306 |
memory) |
307 |
memory $rest |
308 |
;; |
309 |
command) |
310 |
command $rest |
311 |
;; |
312 |
esac |
313 |
done < $1 |
314 |
} |
315 |
|
316 |
main() |
317 |
{ |
318 |
[ -d conf ] || |
319 |
quit "configure must be run from the top source level" |
320 |
|
321 |
# |
322 |
# Process input arguments |
323 |
# |
324 |
setdefaults |
325 |
parseargs "$@" |
326 |
gettarget |
327 |
checkpath |
328 |
gethost |
329 |
settools |
330 |
|
331 |
echo "#" > $CONFIG_MK |
332 |
echo "# Automatically generated file. Don't edit" >> $CONFIG_MK |
333 |
echo "#" >> $CONFIG_MK |
334 |
echo "_CONFIG_MK_=1" >> $CONFIG_MK |
335 |
|
336 |
echo "/*" > $CONFIG_H |
337 |
echo " * Automatically generated file. Don't edit" >> $CONFIG_H |
338 |
echo " */" >> $CONFIG_H |
339 |
|
340 |
cp $CONFIG_H $CONFIG_LD |
341 |
cp $CONFIG_H $DRVTAB_H |
342 |
cp $CONFIG_H $CAPTAB_H |
343 |
|
344 |
echo "" > $DRVTAB_TMP |
345 |
echo "struct driver *driver_table[] = {" >> $DRVTAB_TMP |
346 |
|
347 |
|
348 |
echo "" >> $CAPTAB_H |
349 |
echo "const struct cap_map cap_table[] = {" >> $CAPTAB_H |
350 |
|
351 |
# |
352 |
# Setup build settings |
353 |
# |
354 |
{ |
355 |
echo "ARCH=${arch}" |
356 |
echo "PLATFORM=${platform}" |
357 |
echo "PROFILE=${platform}${profile}" |
358 |
if [ -n "${nodebug}" ]; then |
359 |
echo "NDEBUG=1" |
360 |
fi |
361 |
echo "${cc_type}=1" |
362 |
echo "CC=${prefix}${cc}" |
363 |
echo "CPP=${prefix}${cpp}" |
364 |
echo "AS=${prefix}${as}" |
365 |
echo "LD=${prefix}${ld}" |
366 |
echo "AR=${prefix}${ar}" |
367 |
echo "OBJCOPY=${prefix}${objcopy}" |
368 |
echo "OBJDUMP=${prefix}${objdump}" |
369 |
echo "STRIP=${prefix}${strip}" |
370 |
|
371 |
} >> $CONFIG_MK |
372 |
|
373 |
# |
374 |
# Adjust tool options |
375 |
# |
376 |
checktools |
377 |
|
378 |
# |
379 |
# Generate configuration parameters |
380 |
# |
381 |
echo "checking configuration files..." |
382 |
echo "#define CONFIG_MACHINE ${target}" >> $CONFIG_H |
383 |
echo "#define CONFIG_PROFILE ${profile}" >> $CONFIG_H |
384 |
|
385 |
parseconfig $CONFIG_IN |
386 |
parseconfig $SECURITY_IN |
387 |
|
388 |
cat $DRVTAB_TMP >> $DRVTAB_H |
389 |
echo "};" >> $DRVTAB_H |
390 |
rm -f $DRVTAB_TMP |
391 |
|
392 |
echo "{ NULL, 0 }" >> $CAPTAB_H |
393 |
echo "};" >> $CAPTAB_H |
394 |
|
395 |
echo |
396 |
echo "Prex is now hopefully configured for your setup." |
397 |
echo "Now you must run a make." |
398 |
} |
399 |
|
400 |
main "$@" |