pandora: fix readme and pxml version
[picodrive.git] / configure
... / ...
CommitLineData
1#!/bin/sh
2# some elements originated from qemu configure
3set -e
4
5TMPC="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.c"
6TMPO="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.o"
7TMPB="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}"
8trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM
9rm -f config.log
10
11compile_object()
12{
13 c="$CC $MFLAGS $CFLAGS -c $TMPC -o $TMPO $@"
14 echo $c >> config.log
15 $c >> config.log 2>&1
16}
17
18compile_binary()
19{
20 c="$CC $MFLAGS $CFLAGS $TMPC -o $TMPB $LDFLAGS $@ $SYSLIBS"
21 echo $c >> config.log
22 $c >> config.log 2>&1
23}
24
25check_option()
26{
27 echo 'void test(void) { }' >$TMPC
28 compile_object $1 || return 1
29 return 0
30}
31
32check_define()
33{
34 $CC -E -dD $MFLAGS $CFLAGS pico/arm_features.h | grep -q "define[ ]*$1" || return 1
35 return 0
36}
37
38# setting options to "yes" or "no" will make that choice default,
39# "" means "autodetect".
40
41# TODO this is annoyingly messy. should have platform and device
42platform_list="generic pandora gph dingux retrofw opendingux[-gcw0] odbeta[-gcw0] miyoo rpi1 rpi2 ps2 psp win32"
43platform="generic"
44sound_driver_list="oss alsa sdl"
45sound_drivers=""
46have_armv5=""
47have_armv6=""
48have_armv7=""
49have_arm_oabi=""
50have_arm_neon=""
51have_libavcodec=""
52have_libchdr=""
53have_gles="no"
54need_sdl="no"
55need_zlib="no"
56
57# hardcoded stuff
58CC="${CC-${CROSS_COMPILE}gcc}"
59CXX="${CXX-${CROSS_COMPILE}g++}"
60AS="${AS-${CROSS_COMPILE}as}"
61STRIP="${STRIP-${CROSS_COMPILE}strip}"
62LD="${LD-${CROSS_COMPILE}gcc}" # Use better gcc for linking
63SYSROOT=`$CC $CFLAGS $LDFLAGS --print-sysroot 2> /dev/null || true`
64config_mak="config.mak"
65
66fail()
67{
68 echo "$@"
69 if test -n "$DUMP_CONFIG_LOG"; then cat config.log; fi
70 exit 1
71}
72
73# call during arg parsing, so that cmd line can override platform defaults
74set_platform()
75{
76 platform=$1
77 CFLAGS="$CFLAGS -D__`echo ${platform%-*} | tr '[a-z]' '[A-Z]'`__"
78 case "$platform" in
79 rpi1)
80 MFLAGS="-mcpu=arm1176jzf-s -mfpu=vfp"
81 have_gles="yes"
82 ;;
83 rpi2)
84 MFLAGS="-mcpu=cortex-a7 -mfpu=neon"
85 have_gles="yes"
86 ;;
87 generic)
88 MFLAGS=""
89 ;;
90 dingux)
91 # dingoo a320, ritmix rzx-50, the like. all have Ingenic MIPS cpu <= JZ4755
92 sound_drivers="sdl"
93 # use static linking since the lib situation is ... let's say vague
94 #LDFLAGS="$LDFLAGS -static"
95 # uses a pre-gcw0 version of opendingux
96 MFLAGS="-march=mips32 -msoft-float"
97 platform="opendingux"
98 ;;
99 retrofw)
100 # devices using retrofw. AFAIK all have Ingenic MIPS JZ4760 with fpu
101 sound_drivers="sdl"
102 # uses it's own modified version of opendingux
103 MFLAGS="-march=mips32"
104 platform="opendingux"
105 ;;
106 opendingux | opendingux-gcw0)
107 # more modern devices using opendingux, with Ingenic MIPS JZ4770 or newer
108 sound_drivers="sdl"
109 # mostly based on opendingux for gcw0
110 CFLAGS="$CFLAGS -D__OPENDINGUX__"
111 [ "${platform#*gcw0}" = "" ] && CFLAGS="$CFLAGS -D__GCW0__"
112 MFLAGS="-march=mips32r2"
113 platform="opendingux"
114 ;;
115 miyoo)
116 # Miyoo BittBoy, PocketGO 1, PowKiddy V90/Q90 with Allwinner F1C100s
117 sound_drivers="sdl"
118 CFLAGS="$CFLAGS -D__OPENDINGUX__"
119 MFLAGS="-mcpu=arm926ej-s -marm"
120 platform="opendingux"
121 ;;
122 odbeta | odbeta-gcw0)
123 # various devices with opendingux beta, arch flags from toolchain default
124 sound_drivers="sdl"
125 CFLAGS="$CFLAGS -D__OPENDINGUX__"
126 [ "${platform#*gcw0}" = "" ] && CFLAGS="$CFLAGS -D__GCW0__"
127 MFLAGS="" # toolchains are arch specific
128 platform="opendingux"
129 ;;
130 pandora)
131 sound_drivers="oss alsa"
132 have_libavcodec="yes"
133 MFLAGS="-mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
134 ;;
135 gph)
136 sound_drivers="oss"
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"
142 # unified binary for all of them. picodrive detects device type for itself.
143 CFLAGS="$CFLAGS -D__GP2X__"
144 # add -mfpu=fpa to select correct parameter passing for -msoft-float :-/
145 MFLAGS="-mcpu=arm920t -mfloat-abi=soft -mfpu=fpa"
146 platform="gp2x"
147 ;;
148 psp)
149 # use newlib
150 SYSLIBS="-lc -lpspuser -lpspkernel"
151 MFLAGS="-march=allegrex"
152 ARCH=mipsel
153 ;;
154 ps2)
155 # use newlib
156 SYSLIBS=""
157 MFLAGS=""
158 ARCH=mips64r5900el
159 ASFLAGS="$ASFLAGS -G0 -call_shared"
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"
162 ;;
163 win32)
164 MFLAGS=""
165 ;;
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 ;;
181 --with-libavcodec=*) have_libavcodec="$optarg"
182 ;;
183 --with-sdl-gles=*) have_gles="$optarg"
184 ;;
185 --with-zlib=*) need_zlib="$optarg"
186 ;;
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"
199 echo " --with-libavcodec=yes|no use libavcodec for mp3 decoding"
200 echo " --with-sdl-gles=yes|no enable GLES usage for SDL"
201 echo " --with-zlib=yes|no use internal zlib"
202 echo "influential environment variables:"
203 echo " CROSS_COMPILE CC CXX AS STRIP CFLAGS ASFLAGS LDFLAGS LDLIBS"
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
216if ! test -f "platform/libpicofe/README"; then
217 fail "libpicofe is missing, please run 'git submodule update --init'"
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
226if [ -z "$ARCH" ]; then
227 ARCH=`$CC $MFLAGS $CFLAGS -dumpmachine | awk -F '-' '{print $1}'`
228fi
229
230# CPU/ABI stuff first, else compile test may fail
231case "$ARCH" in
232arm64*)
233 ;;
234arm*)
235 # ARM stuff
236 ARCH="arm"
237
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"
242 fi
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
265 # must disable thumb as recompiler can't handle it
266 if check_define __thumb__; then
267 CFLAGS="$CFLAGS -marm"
268 fi
269
270 # add -ldl for helix support
271 need_dl=yes
272
273 # warn about common mistakes
274 if [ "$platform" != "gp2x" -a "$have_armv5" != "yes" ]; then
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*)
288 ;;
289esac
290
291case "$platform" in
292rpi1 | rpi2 | generic | opendingux | win32)
293 need_sdl="yes"
294 ;;
295esac
296
297# basic compiler test
298cat > $TMPC <<EOF
299int main (int argc, char *argv[]) { return 0; }
300EOF
301if ! compile_binary; then
302 fail "compiler test failed, please check config.log"
303fi
304
305# header/library presence tests
306check_zlib()
307{
308 cat > $TMPC <<EOF
309 #include <zlib.h>
310 int main (int argc, char *argv[]) { uncompress(0, 0, 0, 0); }
311EOF
312 compile_binary "$@"
313}
314
315check_libpng()
316{
317 cat > $TMPC <<EOF
318 #include <png.h>
319 int main (int argc, char *argv[]) { png_init_io(0, 0); }
320EOF
321# compile_binary
322 compile_object
323}
324
325check_oss()
326{
327 cat > $TMPC <<EOF
328 #include <sys/soundcard.h>
329 #include <sys/ioctl.h>
330 int main (int argc, char *argv[]) { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
331EOF
332 compile_binary
333}
334
335check_alsa()
336{
337 cat > $TMPC <<EOF
338 #include <alsa/asoundlib.h>
339 int main (int argc, char *argv[]) { snd_pcm_open(0, 0, 0, 0); }
340EOF
341 compile_binary "$@"
342}
343
344check_sdl()
345{
346 cat > $TMPC <<EOF
347 #include <SDL.h>
348 int main (int argc, char *argv[]) { SDL_OpenAudio(0, 0); }
349EOF
350 compile_binary "$@"
351}
352
353check_libavcodec()
354{
355 cat > $TMPC <<EOF
356 #include <libavcodec/avcodec.h>
357 int main (int argc, char *argv[]) { avcodec_decode_audio3(0, 0, 0, 0); }
358EOF
359 compile_object "$@"
360}
361
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
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
376test -n "$SDL_CONFIG" || SDL_CONFIG=false
377
378MAIN_LDLIBS="$LDLIBS -lm"
379
380check_zlib -lz && MAIN_LDLIBS="$MAIN_LDLIBS -lz" || need_zlib="yes"
381
382MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
383check_libpng || fail "please install libpng (libpng-dev)"
384
385case "$have_libavcodec" in
386y|Y|yes)
387 if check_libavcodec; then
388 have_libavcodec="yes"
389 need_dl=yes
390 else
391 have_libavcodec="no"
392 fi ;;
393*) have_libavcodec="no" ;;
394esac
395
396#if check_libchdr; then
397# have_libchdr="yes"
398# MAIN_LDLIBS="-lchdr $MAIN_LDLIBS"
399#fi
400
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
408 if [ "$need_sdl" = "yes" ] || check_sdl `$SDL_CONFIG --cflags --libs`; then
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"
418 check_alsa -lasound || fail "please install libasound2-dev"
419 fi
420fi
421
422if [ "$need_sdl" = "yes" ]; then
423 [ -x "$SDL_CONFIG" ] || \
424 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
425 CFLAGS="$CFLAGS `$SDL_CONFIG --cflags`"
426 MAIN_LDLIBS="`$SDL_CONFIG --libs` $MAIN_LDLIBS"
427 SYSLIBS="$SYSLIBS -ldl"
428 need_dl=yes
429 check_sdl `$SDL_CONFIG --libs` || fail "please install libsdl (libsdl1.2-dev)"
430 if [ "$SDLVERSION" = "sdl2" ]; then
431 CFLAGS="$CFLAGS -D__USE_SDL2__"
432 fi
433fi
434
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
443if check_option -Wno-unused_result; then
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"
450test "x$have_libavcodec" != "x" || have_libavcodec="no"
451test "x$have_libchdr" != "x" || have_libchdr="no"
452
453echo "architecture $ARCH"
454echo "platform $platform"
455echo "sound drivers $sound_drivers"
456echo "C compiler $CC"
457echo "C compiler flags $MFLAGS $CFLAGS"
458echo "libraries $MAIN_LDLIBS"
459echo "linker flags $LDFLAGS"
460echo "libavcodec (mp3) $have_libavcodec"
461#echo "libchdr $have_libchdr"
462# echo "ARMv7 optimizations $have_armv7"
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
472echo "STRIP = $STRIP" >> $config_mak
473echo "LD = $LD" >> $config_mak
474echo "CFLAGS += $MFLAGS $CFLAGS" >> $config_mak
475echo "ASFLAGS += $MFLAGS $ASFLAGS" >> $config_mak
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
483if [ "$have_gles" = "yes" ]; then
484 echo "HAVE_GLES = 1" >> $config_mak
485fi
486if [ "$have_libavcodec" = "yes" ]; then
487 echo "HAVE_LIBAVCODEC = 1" >> $config_mak
488fi
489if [ "$have_libchdr" = "yes" ]; then
490 echo "HAVE_LIBCHDR = 1" >> $config_mak
491fi
492if [ "$need_zlib" = "yes" ]; then
493 echo "PLATFORM_ZLIB = 1" >> $config_mak
494fi
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
499
500# GP2X toolchains are too old for UAL asm,
501# so add this here to not litter main Makefile
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
508
509# use pandora's skin (for now)
510test -e skin || ln -s platform/pandora/skin skin
511
512# vim:shiftwidth=2:expandtab