2 # some elements originated from qemu configure
5 TMPC="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.c"
6 TMPO="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}.o"
7 TMPB="/tmp/picodrive-conf-${RANDOM}-$$-${RANDOM}"
8 trap "rm -f $TMPC $TMPO $TMPB" EXIT INT QUIT TERM
13 c="$CC $MFLAGS $CFLAGS -c $TMPC -o $TMPO $@"
20 c="$CC $MFLAGS $CFLAGS $TMPC -o $TMPB $LDFLAGS $@ $SYSLIBS"
27 echo 'void test(void) { }' >$TMPC
28 compile_object $1 || return 1
34 $CC -E -dD $MFLAGS $CFLAGS pico/arm_features.h | grep -q "define[ ]*$1" || return 1
38 # setting options to "yes" or "no" will make that choice default,
39 # "" means "autodetect".
41 # TODO this is annoyingly messy. should have platform and device
42 platform_list="generic pandora gph dingux retrofw opendingux[-gcw0] odbeta[-gcw0] miyoo rpi1 rpi2 ps2 psp win32"
44 sound_driver_list="oss alsa sdl"
58 CC="${CC-${CROSS_COMPILE}gcc}"
59 CXX="${CXX-${CROSS_COMPILE}g++}"
60 AS="${AS-${CROSS_COMPILE}as}"
61 STRIP="${STRIP-${CROSS_COMPILE}strip}"
62 LD="${LD-${CROSS_COMPILE}gcc}" # Use better gcc for linking
63 SYSROOT=`$CC $CFLAGS $LDFLAGS --print-sysroot 2> /dev/null || true`
64 config_mak="config.mak"
69 if test -n "$DUMP_CONFIG_LOG"; then cat config.log; fi
73 # call during arg parsing, so that cmd line can override platform defaults
77 CFLAGS="$CFLAGS -D__`echo ${platform%-*} | tr '[a-z]' '[A-Z]'`__"
80 MFLAGS="-mcpu=arm1176jzf-s -mfpu=vfp"
84 MFLAGS="-mcpu=cortex-a7 -mfpu=neon"
91 # dingoo a320, ritmix rzx-50, the like. all have Ingenic MIPS cpu <= JZ4755
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"
100 # devices using retrofw. AFAIK all have Ingenic MIPS JZ4760 with fpu
102 # uses it's own modified version of opendingux
103 MFLAGS="-march=mips32"
104 platform="opendingux"
106 opendingux | opendingux-gcw0)
107 # more modern devices using opendingux, with Ingenic MIPS JZ4770 or newer
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"
116 # Miyoo BittBoy, PocketGO 1, PowKiddy V90/Q90 with Allwinner F1C100s
118 CFLAGS="$CFLAGS -D__OPENDINGUX__"
119 MFLAGS="-mcpu=arm926ej-s -marm"
120 platform="opendingux"
122 odbeta | odbeta-gcw0)
123 # various devices with opendingux beta, arch flags from toolchain default
125 CFLAGS="$CFLAGS -D__OPENDINGUX__"
126 [ "${platform#*gcw0}" = "" ] && CFLAGS="$CFLAGS -D__GCW0__"
127 MFLAGS="" # toolchains are arch specific
128 platform="opendingux"
131 sound_drivers="oss alsa"
132 have_libavcodec="yes"
133 MFLAGS="-mcpu=cortex-a8 -mfpu=neon -mfloat-abi=softfp"
137 # compile for OABI if toolchain provides it (faster code on caanoo)
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"
150 SYSLIBS="-lc -lpspuser -lpspkernel"
151 MFLAGS="-march=allegrex"
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"
167 fail "unsupported platform: $platform"
173 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
175 --help|-h) show_help="yes"
177 --platform=*) set_platform "$optarg"
179 --sound-drivers=*) sound_drivers="$optarg"
181 --with-libavcodec=*) have_libavcodec="$optarg"
183 --with-sdl-gles=*) have_gles="$optarg"
185 --with-zlib=*) need_zlib="$optarg"
187 *) echo "ERROR: unknown option $opt"; show_help="yes"
192 if [ "$show_help" = "yes" ]; then
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"
207 # validate selections
208 if [ "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"
216 if ! test -f "platform/libpicofe/README"; then
217 fail "libpicofe is missing, please run 'git submodule update --init'"
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'"
226 if [ -z "$ARCH" ]; then
227 ARCH=`$CC $MFLAGS $CFLAGS -dumpmachine | awk -F '-' '{print $1}'`
230 # CPU/ABI stuff first, else compile test may fail
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"
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
248 if [ "x$have_armv7" = "x" ]; then
249 if check_define HAVE_ARMV7; then
255 if [ "x$have_armv6" = "x" ]; then
256 if check_define HAVE_ARMV6; then
261 if [ "x$have_armv5" = "x" ]; then
262 have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
265 # must disable thumb as recompiler can't handle it
266 if check_define __thumb__; then
267 CFLAGS="$CFLAGS -marm"
270 # add -ldl for helix support
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 ..."
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 ..."
292 rpi1 | rpi2 | generic | opendingux | win32)
297 # basic compiler test
299 int main (int argc, char *argv[]) { return 0; }
301 if ! compile_binary; then
302 fail "compiler test failed, please check config.log"
305 # header/library presence tests
310 int main (int argc, char *argv[]) { uncompress(0, 0, 0, 0); }
319 int main (int argc, char *argv[]) { png_init_io(0, 0); }
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); }
338 #include <alsa/asoundlib.h>
339 int main (int argc, char *argv[]) { snd_pcm_open(0, 0, 0, 0); }
348 int main (int argc, char *argv[]) { SDL_OpenAudio(0, 0); }
356 #include <libavcodec/avcodec.h>
357 int main (int argc, char *argv[]) { avcodec_decode_audio3(0, 0, 0, 0); }
365 #include <libchdr/chd.h>
366 int main (int argc, char *argv[]) { chd_open("", 0, NULL, NULL); }
371 test -n "$SDL_CONFIG" || SDL_CONFIG="$(ls $SYSROOT/*bin*/sdl-config 2>/dev/null | grep /bin/sdl-config | head -n 1)"
372 test -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)"
375 SDLVERSION=sdl && echo $SDL_CONFIG | grep -q sdl2 && SDLVERSION=sdl2
376 test -n "$SDL_CONFIG" || SDL_CONFIG=false
378 MAIN_LDLIBS="$LDLIBS -lm"
380 check_zlib -lz && MAIN_LDLIBS="$MAIN_LDLIBS -lz" || need_zlib="yes"
382 MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
383 check_libpng || fail "please install libpng (libpng-dev)"
385 case "$have_libavcodec" in
387 if check_libavcodec; then
388 have_libavcodec="yes"
393 *) have_libavcodec="no" ;;
396 #if check_libchdr; then
398 # MAIN_LDLIBS="-lchdr $MAIN_LDLIBS"
401 # find what audio support we can compile
402 if [ "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"
408 if [ "$need_sdl" = "yes" ] || check_sdl `$SDL_CONFIG --cflags --libs`; then
409 sound_drivers="$sound_drivers sdl"
413 if echo $sound_drivers | grep -q "\<oss\>"; then
414 check_oss || fail "oss support is missing"
416 if echo $sound_drivers | grep -q "\<alsa\>"; then
417 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
418 check_alsa -lasound || fail "please install libasound2-dev"
422 if [ "$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"
429 check_sdl `$SDL_CONFIG --libs` || fail "please install libsdl (libsdl1.2-dev)"
430 if [ "$SDLVERSION" = "sdl2" ]; then
431 CFLAGS="$CFLAGS -D__USE_SDL2__"
436 if [ "$need_dl" = "yes" ]; then
437 case "$MAIN_LDLIBS" in
439 *) MAIN_LDLIBS="$MAIN_LDLIBS -ldl" ;;
443 if check_option -Wno-unused_result; then
444 CFLAGS="$CFLAGS -Wno-unused-result"
447 # set things that failed to autodetect to "no"
448 test "x$have_armv6" != "x" || have_armv6="no"
449 test "x$have_armv7" != "x" || have_armv7="no"
450 test "x$have_libavcodec" != "x" || have_libavcodec="no"
451 test "x$have_libchdr" != "x" || have_libchdr="no"
453 echo "architecture $ARCH"
454 echo "platform $platform"
455 echo "sound drivers $sound_drivers"
456 echo "C compiler $CC"
457 echo "C compiler flags $MFLAGS $CFLAGS"
458 echo "libraries $MAIN_LDLIBS"
459 echo "linker flags $LDFLAGS"
460 echo "libavcodec (mp3) $have_libavcodec"
461 #echo "libchdr $have_libchdr"
462 # echo "ARMv7 optimizations $have_armv7"
464 echo "# Automatically generated by configure" > $config_mak
465 printf "# Configured with:" >> $config_mak
466 printf " '%s'" "$0" "$@" >> $config_mak
469 echo "CC = $CC" >> $config_mak
470 echo "CXX = $CXX" >> $config_mak
471 echo "AS = $AS" >> $config_mak
472 echo "STRIP = $STRIP" >> $config_mak
473 echo "LD = $LD" >> $config_mak
474 echo "CFLAGS += $MFLAGS $CFLAGS" >> $config_mak
475 echo "ASFLAGS += $MFLAGS $ASFLAGS" >> $config_mak
476 echo "LDFLAGS += $LDFLAGS" >> $config_mak
477 echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak
480 echo "ARCH = $ARCH" >> $config_mak
481 echo "PLATFORM = $platform" >> $config_mak
482 echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
483 if [ "$have_gles" = "yes" ]; then
484 echo "HAVE_GLES = 1" >> $config_mak
486 if [ "$have_libavcodec" = "yes" ]; then
487 echo "HAVE_LIBAVCODEC = 1" >> $config_mak
489 if [ "$have_libchdr" = "yes" ]; then
490 echo "HAVE_LIBCHDR = 1" >> $config_mak
492 if [ "$need_zlib" = "yes" ]; then
493 echo "PLATFORM_ZLIB = 1" >> $config_mak
495 if [ "$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
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
509 # use pandora's skin (for now)
510 test -e skin || ln -s platform/pandora/skin skin
512 # vim:shiftwidth=2:expandtab