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