pandora: fix readme and pxml version
[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{
3d7e1640 13 c="$CC $MFLAGS $CFLAGS -c $TMPC -o $TMPO $@"
d4d62665 14 echo $c >> config.log
15 $c >> config.log 2>&1
16}
17
18compile_binary()
19{
3d7e1640 20 c="$CC $MFLAGS $CFLAGS $TMPC -o $TMPB $LDFLAGS $@ $SYSLIBS"
d4d62665 21 echo $c >> config.log
22 $c >> config.log 2>&1
23}
24
0f7a30ed 25check_option()
26{
27 echo 'void test(void) { }' >$TMPC
28 compile_object $1 || return 1
29 return 0
30}
31
d4d62665 32check_define()
33{
3d7e1640 34 $CC -E -dD $MFLAGS $CFLAGS pico/arm_features.h | grep -q "define[ ]*$1" || return 1
d4d62665 35 return 0
36}
37
38# setting options to "yes" or "no" will make that choice default,
39# "" means "autodetect".
40
b053cb20 41# TODO this is annoyingly messy. should have platform and device
1909e86c 42platform_list="generic pandora gph dingux retrofw opendingux[-gcw0] odbeta[-gcw0] miyoo rpi1 rpi2 ps2 psp win32"
d4d62665 43platform="generic"
44sound_driver_list="oss alsa sdl"
45sound_drivers=""
46have_armv5=""
47have_armv6=""
48have_armv7=""
0f7a30ed 49have_arm_oabi=""
d4d62665 50have_arm_neon=""
fc11dd05 51have_libavcodec=""
8374e606 52have_libchdr=""
23e47196 53have_gles="no"
d4d62665 54need_sdl="no"
0f7a30ed 55need_zlib="no"
d4d62665 56
57# hardcoded stuff
58CC="${CC-${CROSS_COMPILE}gcc}"
59CXX="${CXX-${CROSS_COMPILE}g++}"
60AS="${AS-${CROSS_COMPILE}as}"
d4bea61c 61STRIP="${STRIP-${CROSS_COMPILE}strip}"
cb774958 62LD="${LD-${CROSS_COMPILE}gcc}" # Use better gcc for linking
95cb712a 63SYSROOT=`$CC $CFLAGS $LDFLAGS --print-sysroot 2> /dev/null || true`
d4d62665 64config_mak="config.mak"
65
66fail()
67{
68 echo "$@"
842f4e44 69 if test -n "$DUMP_CONFIG_LOG"; then cat config.log; fi
d4d62665 70 exit 1
71}
72
73# call during arg parsing, so that cmd line can override platform defaults
74set_platform()
75{
76 platform=$1
58fc34b1 77 CFLAGS="$CFLAGS -D__`echo ${platform%-*} | tr '[a-z]' '[A-Z]'`__"
d4d62665 78 case "$platform" in
8450a2f5 79 rpi1)
0e67fb60 80 MFLAGS="-mcpu=arm1176jzf-s -mfpu=vfp"
23e47196 81 have_gles="yes"
8450a2f5
C
82 ;;
83 rpi2)
0e67fb60 84 MFLAGS="-mcpu=cortex-a7 -mfpu=neon"
23e47196 85 have_gles="yes"
8450a2f5 86 ;;
d4d62665 87 generic)
f2554438 88 MFLAGS=""
d4d62665 89 ;;
5d3b7ae2 90 dingux)
40a7d177 91 # dingoo a320, ritmix rzx-50, the like. all have Ingenic MIPS cpu <= JZ4755
5d3b7ae2 92 sound_drivers="sdl"
40a7d177 93 # use static linking since the lib situation is ... let's say vague
567c41ff 94 #LDFLAGS="$LDFLAGS -static"
3d7e1640 95 # uses a pre-gcw0 version of opendingux
3d7e1640 96 MFLAGS="-march=mips32 -msoft-float"
5d3b7ae2 97 platform="opendingux"
98 ;;
99 retrofw)
40a7d177 100 # devices using retrofw. AFAIK all have Ingenic MIPS JZ4760 with fpu
5d3b7ae2 101 sound_drivers="sdl"
102 # uses it's own modified version of opendingux
3d7e1640 103 MFLAGS="-march=mips32"
5d3b7ae2 104 platform="opendingux"
105 ;;
58fc34b1 106 opendingux | opendingux-gcw0)
40a7d177 107 # more modern devices using opendingux, with Ingenic MIPS JZ4770 or newer
d4bea61c 108 sound_drivers="sdl"
250c8ffb 109 # mostly based on opendingux for gcw0
f2554438 110 CFLAGS="$CFLAGS -D__OPENDINGUX__"
58fc34b1 111 [ "${platform#*gcw0}" = "" ] && CFLAGS="$CFLAGS -D__GCW0__"
3d7e1640 112 MFLAGS="-march=mips32r2"
0f7a30ed 113 platform="opendingux"
d4bea61c 114 ;;
f507a703 115 miyoo)
116 # Miyoo BittBoy, PocketGO 1, PowKiddy V90/Q90 with Allwinner F1C100s
117 sound_drivers="sdl"
250c8ffb 118 CFLAGS="$CFLAGS -D__OPENDINGUX__"
f507a703 119 MFLAGS="-mcpu=arm926ej-s -marm"
250c8ffb 120 platform="opendingux"
121 ;;
58fc34b1 122 odbeta | odbeta-gcw0)
250c8ffb 123 # various devices with opendingux beta, arch flags from toolchain default
58fc34b1 124 sound_drivers="sdl"
83093596 125 CFLAGS="$CFLAGS -D__OPENDINGUX__"
58fc34b1 126 [ "${platform#*gcw0}" = "" ] && CFLAGS="$CFLAGS -D__GCW0__"
85174a6d 127 MFLAGS="" # toolchains are arch specific
250c8ffb 128 platform="opendingux"
f507a703 129 ;;
d4d62665 130 pandora)
131 sound_drivers="oss alsa"
5d3b7ae2 132 have_libavcodec="yes"
f20ad523 133 MFLAGS="-mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
d4d62665 134 ;;
85174a6d 135 gph)
75a30842 136 sound_drivers="oss"
0f7a30ed 137 # compile for OABI if toolchain provides it (faster code on caanoo)
138 have_arm_oabi="yes"
139 # always use static linking, since caanoo doesn't have OABI libs. Moreover,
140 # dynamic linking slows Wiz 1-10%, and libm on F100 isn't compatible
141 LDFLAGS="$LDFLAGS -static"
b053cb20 142 # unified binary for all of them. picodrive detects device type for itself.
75a30842 143 CFLAGS="$CFLAGS -D__GP2X__"
3d7e1640 144 # add -mfpu=fpa to select correct parameter passing for -msoft-float :-/
145 MFLAGS="-mcpu=arm920t -mfloat-abi=soft -mfpu=fpa"
0f7a30ed 146 platform="gp2x"
75a30842 147 ;;
6c5784f0 148 psp)
149 # use newlib
bfd66623 150 SYSLIBS="-lc -lpspuser -lpspkernel"
0924243a 151 MFLAGS="-march=allegrex"
6c5784f0 152 ARCH=mipsel
153 ;;
cb774958
FJTM
154 ps2)
155 # use newlib
156 SYSLIBS=""
157 MFLAGS=""
158 ARCH=mips64r5900el
159 ASFLAGS="$ASFLAGS -G0 -call_shared"
888ca0b8
FJTM
160 CFLAGS="$CFLAGS -D_EE -G0 -I${PS2SDK}/ee/include -I${PS2SDK}/common/include -I${PS2DEV}/gsKit/include -I${PS2SDK}/ports/include"
161 LDFLAGS="$LDFLAGS -Wl,-zmax-page-size=128 -T${PS2SDK}/ee/startup/linkfile -L${PS2SDK}/ee/lib -L${PS2DEV}/gsKit/lib -L${PS2SDK}/ports/lib"
cb774958 162 ;;
1909e86c 163 win32)
164 MFLAGS=""
165 ;;
d4d62665 166 *)
167 fail "unsupported platform: $platform"
168 ;;
169 esac
170}
171
172for opt do
173 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
174 case "$opt" in
175 --help|-h) show_help="yes"
176 ;;
177 --platform=*) set_platform "$optarg"
178 ;;
179 --sound-drivers=*) sound_drivers="$optarg"
180 ;;
5d3b7ae2 181 --with-libavcodec=*) have_libavcodec="$optarg"
182 ;;
23e47196 183 --with-sdl-gles=*) have_gles="$optarg"
184 ;;
110a49ed 185 --with-zlib=*) need_zlib="$optarg"
186 ;;
d4d62665 187 *) echo "ERROR: unknown option $opt"; show_help="yes"
188 ;;
189 esac
190done
191
192if [ "$show_help" = "yes" ]; then
193 echo "options:"
194 echo " --help print this message"
195 echo " --platform=NAME target platform [$platform]"
196 echo " available: $platform_list"
197 echo " --sound-drivers=LIST sound output drivers [guessed]"
198 echo " available: $sound_driver_list"
5d3b7ae2 199 echo " --with-libavcodec=yes|no use libavcodec for mp3 decoding"
23e47196 200 echo " --with-sdl-gles=yes|no enable GLES usage for SDL"
110a49ed 201 echo " --with-zlib=yes|no use internal zlib"
d4d62665 202 echo "influential environment variables:"
d4bea61c 203 echo " CROSS_COMPILE CC CXX AS STRIP CFLAGS ASFLAGS LDFLAGS LDLIBS"
d4d62665 204 exit 1
205fi
206
207# validate selections
208if [ "x$sound_drivers" != "x" ]; then
209 for d in $sound_drivers; do
210 if ! echo $sound_driver_list | grep -q "\<$d\>"; then
211 fail "unsupported sound driver: $sound_driver"
212 fi
213 done
214fi
215
720bfc5d 216if ! test -f "platform/libpicofe/README"; then
217 fail "libpicofe is missing, please run 'git submodule update --init'"
d4d62665 218fi
219
220#if [ "$need_warm" = "yes" ]; then
221# if ! test -f "frontend/warm/README"; then
222# fail "wARM is missing, please run 'git submodule init && git submodule update'"
223# fi
224#fi
225
d4d62665 226if [ -z "$ARCH" ]; then
7401f700 227 ARCH=`$CC $MFLAGS $CFLAGS -dumpmachine | awk -F '-' '{print $1}'`
d4d62665 228fi
229
0f7a30ed 230# CPU/ABI stuff first, else compile test may fail
d4d62665 231case "$ARCH" in
6fa5a749 232arm64*)
233 ;;
d4d62665 234arm*)
235 # ARM stuff
236 ARCH="arm"
237
3d7e1640 238 # OABI/EABI selection
239 if [ "$have_arm_oabi" = "yes" ] && check_option -mabi=apcs-gnu; then
240 echo "$CFLAGS" | grep -q -- '-mabi=' || MFLAGS="$MFLAGS -mabi=apcs-gnu"
241 echo "$CFLAGS" | grep -q -- '-m\(no-\)*thumb-interwork' || CFLAGS="$CFLAGS -mno-thumb-interwork"
75a30842 242 fi
d4d62665 243
244 if [ "x$have_arm_neon" = "x" ]; then
245 # detect NEON from user-supplied cflags to enable asm code
246 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
247 fi
248 if [ "x$have_armv7" = "x" ]; then
249 if check_define HAVE_ARMV7; then
250 have_armv7="yes"
251 have_armv6="yes"
252 have_armv5="yes"
253 fi
254 fi
255 if [ "x$have_armv6" = "x" ]; then
256 if check_define HAVE_ARMV6; then
257 have_armv6="yes"
258 have_armv5="yes"
259 fi
260 fi
261 if [ "x$have_armv5" = "x" ]; then
262 have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
263 fi
264
0f7a30ed 265 # must disable thumb as recompiler can't handle it
266 if check_define __thumb__; then
267 CFLAGS="$CFLAGS -marm"
268 fi
d4d62665 269
0f7a30ed 270 # add -ldl for helix support
40a7d177 271 need_dl=yes
d4d62665 272
273 # warn about common mistakes
75a30842 274 if [ "$platform" != "gp2x" -a "$have_armv5" != "yes" ]; then
d4d62665 275 if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then
276 echo "Warning: compiling for ARMv4, is that really what you want?"
277 echo "You probably should specify -mcpu= or -march= like this:"
278 echo " CFLAGS=-march=armv6 ./configure ..."
279 fi
280 fi
281 if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then
282 echo "Warning: compiling for NEON, but not ARMv7?"
283 echo "You probably want to specify -mcpu= or -march= like this:"
284 echo " CFLAGS=-march=armv7-a ./configure ..."
285 fi
286 ;;
287*)
d4d62665 288 ;;
289esac
290
291case "$platform" in
1909e86c 292rpi1 | rpi2 | generic | opendingux | win32)
d4d62665 293 need_sdl="yes"
294 ;;
295esac
296
0f7a30ed 297# basic compiler test
298cat > $TMPC <<EOF
a97dd5cd 299int main (int argc, char *argv[]) { return 0; }
0f7a30ed 300EOF
301if ! compile_binary; then
302 fail "compiler test failed, please check config.log"
303fi
304
d4d62665 305# header/library presence tests
306check_zlib()
307{
308 cat > $TMPC <<EOF
309 #include <zlib.h>
a97dd5cd 310 int main (int argc, char *argv[]) { uncompress(0, 0, 0, 0); }
d4d62665 311EOF
325ee167 312 compile_binary "$@"
d4d62665 313}
314
315check_libpng()
316{
317 cat > $TMPC <<EOF
318 #include <png.h>
a97dd5cd 319 int main (int argc, char *argv[]) { png_init_io(0, 0); }
d4d62665 320EOF
75a30842 321# compile_binary
322 compile_object
d4d62665 323}
324
325check_oss()
326{
327 cat > $TMPC <<EOF
328 #include <sys/soundcard.h>
329 #include <sys/ioctl.h>
a97dd5cd 330 int main (int argc, char *argv[]) { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
d4d62665 331EOF
332 compile_binary
333}
334
335check_alsa()
336{
337 cat > $TMPC <<EOF
338 #include <alsa/asoundlib.h>
a97dd5cd 339 int main (int argc, char *argv[]) { snd_pcm_open(0, 0, 0, 0); }
d4d62665 340EOF
341 compile_binary "$@"
342}
343
344check_sdl()
345{
346 cat > $TMPC <<EOF
347 #include <SDL.h>
a97dd5cd 348 int main (int argc, char *argv[]) { SDL_OpenAudio(0, 0); }
d4d62665 349EOF
350 compile_binary "$@"
351}
352
fc11dd05 353check_libavcodec()
354{
355 cat > $TMPC <<EOF
356 #include <libavcodec/avcodec.h>
a97dd5cd 357 int main (int argc, char *argv[]) { avcodec_decode_audio3(0, 0, 0, 0); }
fc11dd05 358EOF
986d60fc 359 compile_object "$@"
fc11dd05 360}
361
8374e606 362check_libchdr()
363{
364 cat > $TMPC <<EOF
365 #include <libchdr/chd.h>
366 int main (int argc, char *argv[]) { chd_open("", 0, NULL, NULL); }
367EOF
368 compile_object "$@"
369}
370
3d7e1640 371test -n "$SDL_CONFIG" || SDL_CONFIG="$(ls $SYSROOT/*bin*/sdl-config 2>/dev/null | grep /bin/sdl-config | head -n 1)"
372test -n "$SDL_CONFIG" || SDL_CONFIG="$(ls $SYSROOT/*/*bin*/sdl-config 2>/dev/null | grep /bin/sdl-config | head -n 1)"
373#test -n "$SDL_CONFIG" || SDL_CONFIG="$(ls $SYSROOT/*bin*/sdl2-config 2>/dev/null | grep /bin/sdl2-config | head -n 1)"
374#test -n "$SDL_CONFIG" || SDL_CONFIG="$(ls $SYSROOT/*/*bin*/sdl2-config 2>/dev/null | grep /bin/sdl2-config | head -n 1)"
375SDLVERSION=sdl && echo $SDL_CONFIG | grep -q sdl2 && SDLVERSION=sdl2
250c8ffb 376test -n "$SDL_CONFIG" || SDL_CONFIG=false
3d7e1640 377
378MAIN_LDLIBS="$LDLIBS -lm"
379
6c5784f0 380check_zlib -lz && MAIN_LDLIBS="$MAIN_LDLIBS -lz" || need_zlib="yes"
d4d62665 381
382MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
383check_libpng || fail "please install libpng (libpng-dev)"
384
5d3b7ae2 385case "$have_libavcodec" in
386y|Y|yes)
387 if check_libavcodec; then
388 have_libavcodec="yes"
40a7d177 389 need_dl=yes
5d3b7ae2 390 else
391 have_libavcodec="no"
392 fi ;;
393*) have_libavcodec="no" ;;
394esac
fc11dd05 395
4bb0b70e 396#if check_libchdr; then
397# have_libchdr="yes"
398# MAIN_LDLIBS="-lchdr $MAIN_LDLIBS"
399#fi
8374e606 400
d4d62665 401# find what audio support we can compile
402if [ "x$sound_drivers" = "x" ]; then
403 if check_oss; then sound_drivers="$sound_drivers oss"; fi
404 if check_alsa -lasound; then
405 sound_drivers="$sound_drivers alsa"
406 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
407 fi
ae632fd1 408 if [ "$need_sdl" = "yes" ] || check_sdl `$SDL_CONFIG --cflags --libs`; then
d4d62665 409 sound_drivers="$sound_drivers sdl"
410 need_sdl="yes"
411 fi
412else
413 if echo $sound_drivers | grep -q "\<oss\>"; then
414 check_oss || fail "oss support is missing"
415 fi
416 if echo $sound_drivers | grep -q "\<alsa\>"; then
417 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
75a30842 418 check_alsa -lasound || fail "please install libasound2-dev"
d4d62665 419 fi
420fi
421
422if [ "$need_sdl" = "yes" ]; then
ae632fd1 423 [ -x "$SDL_CONFIG" ] || \
d4d62665 424 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
ae632fd1
PC
425 CFLAGS="$CFLAGS `$SDL_CONFIG --cflags`"
426 MAIN_LDLIBS="`$SDL_CONFIG --libs` $MAIN_LDLIBS"
40a7d177 427 SYSLIBS="$SYSLIBS -ldl"
428 need_dl=yes
ae632fd1 429 check_sdl `$SDL_CONFIG --libs` || fail "please install libsdl (libsdl1.2-dev)"
95cb712a 430 if [ "$SDLVERSION" = "sdl2" ]; then
431 CFLAGS="$CFLAGS -D__USE_SDL2__"
432 fi
d4d62665 433fi
434
40a7d177 435# add -ldl if needed
436if [ "$need_dl" = "yes" ]; then
437 case "$MAIN_LDLIBS" in
438 *"-ldl"*) ;;
439 *) MAIN_LDLIBS="$MAIN_LDLIBS -ldl" ;;
440 esac
441fi
442
0f7a30ed 443if check_option -Wno-unused_result; then
d4d62665 444 CFLAGS="$CFLAGS -Wno-unused-result"
445fi
446
447# set things that failed to autodetect to "no"
448test "x$have_armv6" != "x" || have_armv6="no"
449test "x$have_armv7" != "x" || have_armv7="no"
fc11dd05 450test "x$have_libavcodec" != "x" || have_libavcodec="no"
8374e606 451test "x$have_libchdr" != "x" || have_libchdr="no"
d4d62665 452
453echo "architecture $ARCH"
454echo "platform $platform"
455echo "sound drivers $sound_drivers"
456echo "C compiler $CC"
3d7e1640 457echo "C compiler flags $MFLAGS $CFLAGS"
d4d62665 458echo "libraries $MAIN_LDLIBS"
459echo "linker flags $LDFLAGS"
fc11dd05 460echo "libavcodec (mp3) $have_libavcodec"
4bb0b70e 461#echo "libchdr $have_libchdr"
d4d62665 462# echo "ARMv7 optimizations $have_armv7"
d4d62665 463
464echo "# Automatically generated by configure" > $config_mak
465printf "# Configured with:" >> $config_mak
466printf " '%s'" "$0" "$@" >> $config_mak
467echo >> $config_mak
468
469echo "CC = $CC" >> $config_mak
470echo "CXX = $CXX" >> $config_mak
471echo "AS = $AS" >> $config_mak
d4bea61c 472echo "STRIP = $STRIP" >> $config_mak
cb774958 473echo "LD = $LD" >> $config_mak
3d7e1640 474echo "CFLAGS += $MFLAGS $CFLAGS" >> $config_mak
475echo "ASFLAGS += $MFLAGS $ASFLAGS" >> $config_mak
d4d62665 476echo "LDFLAGS += $LDFLAGS" >> $config_mak
477echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak
478echo >> $config_mak
479
480echo "ARCH = $ARCH" >> $config_mak
481echo "PLATFORM = $platform" >> $config_mak
482echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
23e47196 483if [ "$have_gles" = "yes" ]; then
484 echo "HAVE_GLES = 1" >> $config_mak
485fi
fc11dd05 486if [ "$have_libavcodec" = "yes" ]; then
487 echo "HAVE_LIBAVCODEC = 1" >> $config_mak
488fi
8374e606 489if [ "$have_libchdr" = "yes" ]; then
490 echo "HAVE_LIBCHDR = 1" >> $config_mak
491fi
0f7a30ed 492if [ "$need_zlib" = "yes" ]; then
493 echo "PLATFORM_ZLIB = 1" >> $config_mak
494fi
5ab80df9 495if [ "$ARCH" = "arm" -a "$have_armv6" != "yes" -a "$have_armv7" != "yes" ]; then
496 # pass info to cyclone not to use newer arm arch instructions
497 echo "HAVE_ARMv6 = 0" >> $config_mak
498fi
75a30842 499
500# GP2X toolchains are too old for UAL asm,
501# so add this here to not litter main Makefile
0f7a30ed 502#if [ "$platform" = "gp2x" ]; then
503# echo >> $config_mak
504# echo '%.o: %.S' >> $config_mak
505# echo ' $(CC) $(CFLAGS) -E -c $^ -o /tmp/$(notdir $@).s' >> $config_mak
506# echo ' $(AS) $(ASFLAGS) /tmp/$(notdir $@).s -o $@' >> $config_mak
507#fi
d4d62665 508
509# use pandora's skin (for now)
510test -e skin || ln -s platform/pandora/skin skin
511
512# vim:shiftwidth=2:expandtab