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 $CFLAGS -c $TMPC -o $TMPO $@"
20 c="$CC $CFLAGS $TMPC -o $TMPB $LDFLAGS $@"
27 $CC -E -dD $CFLAGS pico/arm_features.h | grep -q $1 || return 1
31 # setting options to "yes" or "no" will make that choice default,
32 # "" means "autodetect".
34 platform_list="generic pandora gp2x opendingux rpi1 rpi2"
36 sound_driver_list="oss alsa sdl"
45 # these are for known platforms
46 optimize_cortexa8="no"
47 optimize_cortexa7="no"
48 optimize_arm1176jzf="no"
49 optimize_arm926ej="no"
53 CC="${CC-${CROSS_COMPILE}gcc}"
54 CXX="${CXX-${CROSS_COMPILE}g++}"
55 AS="${AS-${CROSS_COMPILE}as}"
56 STRIP="${STRIP-${CROSS_COMPILE}strip}"
57 test -n "$SDL_CONFIG" || SDL_CONFIG="`$CC --print-sysroot 2> /dev/null || true`/usr/bin/sdl-config"
58 MAIN_LDLIBS="$LDLIBS -lm"
59 config_mak="config.mak"
67 # call during arg parsing, so that cmd line can override platform defaults
73 optimize_arm1176jzf="yes"
76 optimize_cortexa7="yes"
85 sound_drivers="oss alsa"
86 optimize_cortexa8="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"
100 fail "unsupported platform: $platform"
106 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
108 --help|-h) show_help="yes"
110 --platform=*) set_platform "$optarg"
112 --sound-drivers=*) sound_drivers="$optarg"
114 *) echo "ERROR: unknown option $opt"; show_help="yes"
119 if [ "$show_help" = "yes" ]; then
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"
126 echo "influential environment variables:"
127 echo " CROSS_COMPILE CC CXX AS STRIP CFLAGS ASFLAGS LDFLAGS LDLIBS"
131 # validate selections
132 if [ "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"
140 if ! test -f "platform/libpicofe/README"; then
141 fail "libpicofe is missing, please run 'git submodule update --init'"
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'"
150 # basic compiler test
152 int main(void) { return 0; }
154 if ! compile_binary; then
155 fail "compiler test failed, please check config.log"
158 if [ -z "$ARCH" ]; then
159 ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'`
167 if [ "$optimize_cortexa8" = "yes" ]; then
168 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
169 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
171 if [ "$optimize_cortexa7" = "yes" ]; then
172 CFLAGS="$CFLAGS -mcpu=cortex-a7"
173 ASFLAGS="$ASFLAGS -mcpu=cortex-a7"
175 if [ "$optimize_arm1176jzf" = "yes" ]; then
176 CFLAGS="$CFLAGS -mcpu=arm1176jzf-s -mfloat-abi=hard"
177 ASFLAGS="$ASFLAGS -mcpu=arm1176jzf-s -mfloat-abi=hard"
179 if [ "$optimize_arm926ej" = "yes" ]; then
180 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
181 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
183 if [ "$optimize_arm920" = "yes" ]; then
184 CFLAGS="$CFLAGS -mcpu=arm920t -mtune=arm920t"
185 ASFLAGS="$ASFLAGS -mcpu=arm920t -mfloat-abi=soft"
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
192 if [ "x$have_armv7" = "x" ]; then
193 if check_define HAVE_ARMV7; then
199 if [ "x$have_armv6" = "x" ]; then
200 if check_define HAVE_ARMV6; then
205 if [ "x$have_armv5" = "x" ]; then
206 have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
209 # automatically set mfpu and mfloat-abi if they are not set
210 if [ "$have_arm_neon" = "yes" ]; then
212 elif [ "$have_armv6" = "yes" ]; then
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"
225 # must disable thumb as recompiler can't handle it
226 if check_define __thumb__; then
227 CFLAGS="$CFLAGS -marm"
230 # warn about common mistakes
231 if [ "$platform" != "gp2x" -a "$have_armv5" != "yes" ]; then
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 ..."
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 ..."
249 rpi1 | rpi2 | generic | opendingux)
254 # header/library presence tests
259 int main(void) { uncompress(0, 0, 0, 0); }
268 void main() { png_init_io(0, 0); }
277 #include <sys/soundcard.h>
278 #include <sys/ioctl.h>
279 void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
287 #include <alsa/asoundlib.h>
288 void main() { snd_pcm_open(0, 0, 0, 0); }
297 void main() { SDL_OpenAudio(0, 0); }
305 #include <libavcodec/avcodec.h>
306 void main() { avcodec_decode_audio3(0, 0, 0, 0); }
311 MAIN_LDLIBS="$MAIN_LDLIBS -lz"
312 check_zlib -lz || fail "please install zlib (libz-dev)"
314 MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
315 check_libpng || fail "please install libpng (libpng-dev)"
317 if check_libavcodec; then
318 have_libavcodec="yes"
320 case "$MAIN_LDLIBS" in
322 *) MAIN_LDLIBS="-ldl $MAIN_LDLIBS" ;;
326 # find what audio support we can compile
327 if [ "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"
333 if [ "$need_sdl" = "yes" ] || check_sdl `$SDL_CONFIG --cflags --libs`; then
334 sound_drivers="$sound_drivers sdl"
338 if echo $sound_drivers | grep -q "\<oss\>"; then
339 check_oss || fail "oss support is missing"
341 if echo $sound_drivers | grep -q "\<alsa\>"; then
342 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
343 check_alsa -lasound || fail "please install libasound2-dev"
347 if [ "$need_sdl" = "yes" ]; then
348 [ -x "$SDL_CONFIG" ] || \
349 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
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)"
356 void test(void *f, void *d) { fread(d, 1, 1, f); }
358 if compile_object -Wno-unused-result; then
359 CFLAGS="$CFLAGS -Wno-unused-result"
362 # set things that failed to autodetect to "no"
363 test "x$have_armv6" != "x" || have_armv6="no"
364 test "x$have_armv7" != "x" || have_armv7="no"
365 test "x$have_libavcodec" != "x" || have_libavcodec="no"
367 echo "architecture $ARCH"
368 echo "platform $platform"
369 echo "sound drivers $sound_drivers"
370 echo "C compiler $CC"
371 echo "C compiler flags $CFLAGS"
372 echo "libraries $MAIN_LDLIBS"
373 echo "linker flags $LDFLAGS"
374 echo "libavcodec (mp3) $have_libavcodec"
375 # echo "ARMv7 optimizations $have_armv7"
377 echo "# Automatically generated by configure" > $config_mak
378 printf "# Configured with:" >> $config_mak
379 printf " '%s'" "$0" "$@" >> $config_mak
382 echo "CC = $CC" >> $config_mak
383 echo "CXX = $CXX" >> $config_mak
384 echo "AS = $AS" >> $config_mak
385 echo "STRIP = $STRIP" >> $config_mak
386 echo "CFLAGS += $CFLAGS" >> $config_mak
387 echo "ASFLAGS += $ASFLAGS" >> $config_mak
388 echo "LDFLAGS += $LDFLAGS" >> $config_mak
389 echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak
392 echo "ARCH = $ARCH" >> $config_mak
393 echo "PLATFORM = $platform" >> $config_mak
394 echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
395 if [ "$have_libavcodec" = "yes" ]; then
396 echo "HAVE_LIBAVCODEC = 1" >> $config_mak
399 # GP2X toolchains are too old for UAL asm,
400 # so add this here to not litter main Makefile
401 if [ "$platform" = "g1p2x" ]; then
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
408 # use pandora's skin (for now)
409 test -e skin || ln -s platform/pandora/skin skin
411 # vim:shiftwidth=2:expandtab