d4d62665 |
1 | #!/bin/sh |
2 | # some elements originated from qemu configure |
3 | set -e |
4 | |
75a30842 |
5 | TMPC="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.c" |
6 | TMPO="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.o" |
7 | TMPB="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}" |
d4d62665 |
8 | trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM |
9 | rm -f config.log |
10 | |
11 | compile_object() |
12 | { |
13 | c="$CC $CFLAGS -c $TMPC -o $TMPO $@" |
14 | echo $c >> config.log |
15 | $c >> config.log 2>&1 |
16 | } |
17 | |
18 | compile_binary() |
19 | { |
75a30842 |
20 | c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $@" |
d4d62665 |
21 | echo $c >> config.log |
22 | $c >> config.log 2>&1 |
23 | } |
24 | |
25 | check_define() |
26 | { |
27 | $CC -E -dD $CFLAGS pico/arm_features.h | grep -q $1 || return 1 |
28 | return 0 |
29 | } |
30 | |
31 | # setting options to "yes" or "no" will make that choice default, |
32 | # "" means "autodetect". |
33 | |
75a30842 |
34 | platform_list="generic pandora gp2x" |
d4d62665 |
35 | platform="generic" |
36 | sound_driver_list="oss alsa sdl" |
37 | sound_drivers="" |
38 | have_armv5="" |
39 | have_armv6="" |
40 | have_armv7="" |
41 | have_arm_neon="" |
fc11dd05 |
42 | have_libavcodec="" |
d4d62665 |
43 | need_sdl="no" |
44 | need_xlib="no" |
45 | # these are for known platforms |
46 | optimize_cortexa8="no" |
47 | optimize_arm926ej="no" |
75a30842 |
48 | optimize_arm920="no" |
d4d62665 |
49 | |
50 | # hardcoded stuff |
51 | CC="${CC-${CROSS_COMPILE}gcc}" |
52 | CXX="${CXX-${CROSS_COMPILE}g++}" |
53 | AS="${AS-${CROSS_COMPILE}as}" |
54 | MAIN_LDLIBS="$LDLIBS -lm" |
55 | config_mak="config.mak" |
56 | |
57 | fail() |
58 | { |
59 | echo "$@" |
60 | exit 1 |
61 | } |
62 | |
63 | # call during arg parsing, so that cmd line can override platform defaults |
64 | set_platform() |
65 | { |
66 | platform=$1 |
67 | case "$platform" in |
68 | generic) |
69 | ;; |
70 | pandora) |
71 | sound_drivers="oss alsa" |
72 | optimize_cortexa8="yes" |
73 | have_arm_neon="yes" |
74 | ;; |
75a30842 |
75 | gp2x) |
76 | sound_drivers="oss" |
77 | optimize_arm920="yes" |
78 | CFLAGS="$CFLAGS -D__GP2X__" |
79 | if [ "$CROSS_COMPILE" = "arm-linux-" ]; then |
80 | # still using static, dynamic linking slows Wiz 1-10% |
81 | # also libm on F100 is not compatible |
82 | MAIN_LDLIBS="$MAIN_LDLIBS -static" |
83 | fi |
84 | ;; |
d4d62665 |
85 | *) |
86 | fail "unsupported platform: $platform" |
87 | ;; |
88 | esac |
89 | } |
90 | |
91 | for opt do |
92 | optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true |
93 | case "$opt" in |
94 | --help|-h) show_help="yes" |
95 | ;; |
96 | --platform=*) set_platform "$optarg" |
97 | ;; |
98 | --sound-drivers=*) sound_drivers="$optarg" |
99 | ;; |
d4d62665 |
100 | *) echo "ERROR: unknown option $opt"; show_help="yes" |
101 | ;; |
102 | esac |
103 | done |
104 | |
105 | if [ "$show_help" = "yes" ]; then |
106 | echo "options:" |
107 | echo " --help print this message" |
108 | echo " --platform=NAME target platform [$platform]" |
109 | echo " available: $platform_list" |
110 | echo " --sound-drivers=LIST sound output drivers [guessed]" |
111 | echo " available: $sound_driver_list" |
d4d62665 |
112 | echo "influential environment variables:" |
113 | echo " CROSS_COMPILE CC CXX AS CFLAGS ASFLAGS LDFLAGS LDLIBS" |
114 | exit 1 |
115 | fi |
116 | |
117 | # validate selections |
118 | if [ "x$sound_drivers" != "x" ]; then |
119 | for d in $sound_drivers; do |
120 | if ! echo $sound_driver_list | grep -q "\<$d\>"; then |
121 | fail "unsupported sound driver: $sound_driver" |
122 | fi |
123 | done |
124 | fi |
125 | |
720bfc5d |
126 | if ! test -f "platform/libpicofe/README"; then |
127 | fail "libpicofe is missing, please run 'git submodule update --init'" |
d4d62665 |
128 | fi |
129 | |
130 | #if [ "$need_warm" = "yes" ]; then |
131 | # if ! test -f "frontend/warm/README"; then |
132 | # fail "wARM is missing, please run 'git submodule init && git submodule update'" |
133 | # fi |
134 | #fi |
135 | |
136 | # basic compiler test |
137 | cat > $TMPC <<EOF |
138 | int main(void) { return 0; } |
139 | EOF |
140 | if ! compile_binary; then |
141 | fail "compiler test failed, please check config.log" |
142 | fi |
143 | |
144 | if [ -z "$ARCH" ]; then |
145 | ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'` |
146 | fi |
147 | |
148 | case "$ARCH" in |
149 | arm*) |
150 | # ARM stuff |
151 | ARCH="arm" |
152 | |
153 | if [ "$optimize_cortexa8" = "yes" ]; then |
154 | CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8" |
155 | ASFLAGS="$ASFLAGS -mcpu=cortex-a8" |
156 | fi |
157 | if [ "$optimize_arm926ej" = "yes" ]; then |
158 | CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s" |
159 | ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp" |
160 | fi |
75a30842 |
161 | if [ "$optimize_arm920" = "yes" ]; then |
162 | CFLAGS="$CFLAGS -mcpu=arm920t -mtune=arm920t" |
163 | ASFLAGS="$ASFLAGS -mcpu=arm920t -mfloat-abi=soft" |
164 | fi |
d4d62665 |
165 | |
166 | if [ "x$have_arm_neon" = "x" ]; then |
167 | # detect NEON from user-supplied cflags to enable asm code |
168 | have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true |
169 | fi |
170 | if [ "x$have_armv7" = "x" ]; then |
171 | if check_define HAVE_ARMV7; then |
172 | have_armv7="yes" |
173 | have_armv6="yes" |
174 | have_armv5="yes" |
175 | fi |
176 | fi |
177 | if [ "x$have_armv6" = "x" ]; then |
178 | if check_define HAVE_ARMV6; then |
179 | have_armv6="yes" |
180 | have_armv5="yes" |
181 | fi |
182 | fi |
183 | if [ "x$have_armv5" = "x" ]; then |
184 | have_armv5=`check_define HAVE_ARMV5 && echo yes` || true |
185 | fi |
186 | |
187 | # automatically set mfpu and mfloat-abi if they are not set |
188 | if [ "$have_arm_neon" = "yes" ]; then |
189 | fpu="neon" |
190 | elif [ "$have_armv6" = "yes" ]; then |
191 | fpu="vfp" |
192 | fi |
193 | if [ "x$fpu" != "x" ]; then |
194 | echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu" |
195 | echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu" |
196 | floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true |
197 | if [ "$floatabi_set_by_gcc" != "yes" ]; then |
198 | echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp" |
199 | echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp" |
200 | fi |
201 | fi |
202 | |
203 | # must disable thumb as recompiler can't handle it |
204 | if check_define __thumb__; then |
205 | CFLAGS="$CFLAGS -marm" |
206 | fi |
207 | |
208 | # warn about common mistakes |
75a30842 |
209 | if [ "$platform" != "gp2x" -a "$have_armv5" != "yes" ]; then |
d4d62665 |
210 | if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then |
211 | echo "Warning: compiling for ARMv4, is that really what you want?" |
212 | echo "You probably should specify -mcpu= or -march= like this:" |
213 | echo " CFLAGS=-march=armv6 ./configure ..." |
214 | fi |
215 | fi |
216 | if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then |
217 | echo "Warning: compiling for NEON, but not ARMv7?" |
218 | echo "You probably want to specify -mcpu= or -march= like this:" |
219 | echo " CFLAGS=-march=armv7-a ./configure ..." |
220 | fi |
221 | ;; |
222 | *) |
d4d62665 |
223 | ;; |
224 | esac |
225 | |
226 | case "$platform" in |
227 | generic) |
228 | need_sdl="yes" |
229 | ;; |
230 | esac |
231 | |
232 | # header/library presence tests |
233 | check_zlib() |
234 | { |
235 | cat > $TMPC <<EOF |
236 | #include <zlib.h> |
237 | int main(void) { uncompress(0, 0, 0, 0); } |
238 | EOF |
239 | compile_binary |
240 | } |
241 | |
242 | check_libpng() |
243 | { |
244 | cat > $TMPC <<EOF |
245 | #include <png.h> |
246 | void main() { png_init_io(0, 0); } |
247 | EOF |
75a30842 |
248 | # compile_binary |
249 | compile_object |
d4d62665 |
250 | } |
251 | |
252 | check_oss() |
253 | { |
254 | cat > $TMPC <<EOF |
255 | #include <sys/soundcard.h> |
256 | #include <sys/ioctl.h> |
257 | void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); } |
258 | EOF |
259 | compile_binary |
260 | } |
261 | |
262 | check_alsa() |
263 | { |
264 | cat > $TMPC <<EOF |
265 | #include <alsa/asoundlib.h> |
266 | void main() { snd_pcm_open(0, 0, 0, 0); } |
267 | EOF |
268 | compile_binary "$@" |
269 | } |
270 | |
271 | check_sdl() |
272 | { |
273 | cat > $TMPC <<EOF |
274 | #include <SDL.h> |
275 | void main() { SDL_OpenAudio(0, 0); } |
276 | EOF |
277 | compile_binary "$@" |
278 | } |
279 | |
fc11dd05 |
280 | check_libavcodec() |
281 | { |
282 | cat > $TMPC <<EOF |
283 | #include <libavcodec/avcodec.h> |
284 | void main() { avcodec_decode_audio3(0, 0, 0, 0); } |
285 | EOF |
986d60fc |
286 | compile_object "$@" |
fc11dd05 |
287 | } |
288 | |
d4d62665 |
289 | #MAIN_LDLIBS="$MAIN_LDLIBS -lz" |
290 | #check_zlib || fail "please install zlib (libz-dev)" |
291 | |
292 | MAIN_LDLIBS="-lpng $MAIN_LDLIBS" |
293 | check_libpng || fail "please install libpng (libpng-dev)" |
294 | |
fc11dd05 |
295 | if check_libavcodec; then |
296 | have_libavcodec="yes" |
986d60fc |
297 | # add -ldl if needed |
298 | case "$MAIN_LDLIBS" in |
299 | *"-ldl"*) ;; |
300 | *) MAIN_LDLIBS="-ldl $MAIN_LDLIBS" ;; |
301 | esac |
fc11dd05 |
302 | fi |
303 | |
d4d62665 |
304 | # find what audio support we can compile |
305 | if [ "x$sound_drivers" = "x" ]; then |
306 | if check_oss; then sound_drivers="$sound_drivers oss"; fi |
307 | if check_alsa -lasound; then |
308 | sound_drivers="$sound_drivers alsa" |
309 | MAIN_LDLIBS="-lasound $MAIN_LDLIBS" |
310 | fi |
311 | if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then |
312 | sound_drivers="$sound_drivers sdl" |
313 | need_sdl="yes" |
314 | fi |
315 | else |
316 | if echo $sound_drivers | grep -q "\<oss\>"; then |
317 | check_oss || fail "oss support is missing" |
318 | fi |
319 | if echo $sound_drivers | grep -q "\<alsa\>"; then |
320 | MAIN_LDLIBS="-lasound $MAIN_LDLIBS" |
75a30842 |
321 | check_alsa -lasound || fail "please install libasound2-dev" |
d4d62665 |
322 | fi |
323 | fi |
324 | |
325 | if [ "$need_sdl" = "yes" ]; then |
326 | which sdl-config > /dev/null || \ |
327 | fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)" |
328 | CFLAGS="$CFLAGS `sdl-config --cflags`" |
329 | MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS" |
75a30842 |
330 | check_sdl `sdl-config --libs` || fail "please install libsdl (libsdl1.2-dev)" |
d4d62665 |
331 | fi |
332 | |
333 | cat > $TMPC <<EOF |
334 | void test(void *f, void *d) { fread(d, 1, 1, f); } |
335 | EOF |
336 | if compile_object -Wno-unused-result; then |
337 | CFLAGS="$CFLAGS -Wno-unused-result" |
338 | fi |
339 | |
340 | # set things that failed to autodetect to "no" |
341 | test "x$have_armv6" != "x" || have_armv6="no" |
342 | test "x$have_armv7" != "x" || have_armv7="no" |
fc11dd05 |
343 | test "x$have_libavcodec" != "x" || have_libavcodec="no" |
d4d62665 |
344 | |
345 | echo "architecture $ARCH" |
346 | echo "platform $platform" |
347 | echo "sound drivers $sound_drivers" |
348 | echo "C compiler $CC" |
349 | echo "C compiler flags $CFLAGS" |
350 | echo "libraries $MAIN_LDLIBS" |
351 | echo "linker flags $LDFLAGS" |
fc11dd05 |
352 | echo "libavcodec (mp3) $have_libavcodec" |
d4d62665 |
353 | # echo "ARMv7 optimizations $have_armv7" |
d4d62665 |
354 | |
355 | echo "# Automatically generated by configure" > $config_mak |
356 | printf "# Configured with:" >> $config_mak |
357 | printf " '%s'" "$0" "$@" >> $config_mak |
358 | echo >> $config_mak |
359 | |
360 | echo "CC = $CC" >> $config_mak |
361 | echo "CXX = $CXX" >> $config_mak |
362 | echo "AS = $AS" >> $config_mak |
363 | echo "CFLAGS += $CFLAGS" >> $config_mak |
364 | echo "ASFLAGS += $ASFLAGS" >> $config_mak |
365 | echo "LDFLAGS += $LDFLAGS" >> $config_mak |
366 | echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak |
367 | echo >> $config_mak |
368 | |
369 | echo "ARCH = $ARCH" >> $config_mak |
370 | echo "PLATFORM = $platform" >> $config_mak |
371 | echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak |
fc11dd05 |
372 | if [ "$have_libavcodec" = "yes" ]; then |
373 | echo "HAVE_LIBAVCODEC = 1" >> $config_mak |
374 | fi |
75a30842 |
375 | |
376 | # GP2X toolchains are too old for UAL asm, |
377 | # so add this here to not litter main Makefile |
378 | if [ "$platform" = "g1p2x" ]; then |
379 | echo >> $config_mak |
380 | echo "%.o: %.S" >> $config_mak |
381 | echo " $(CC) $(CFLAGS) -E -c $^ -o /tmp/$(notdir $@).s" >> $config_mak |
382 | echo " $(AS) $(ASFLAGS) /tmp/$(notdir $@).s -o $@" >> $config_mak |
d4d62665 |
383 | fi |
384 | |
385 | # use pandora's skin (for now) |
386 | test -e skin || ln -s platform/pandora/skin skin |
387 | |
388 | # vim:shiftwidth=2:expandtab |