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"
36 sound_driver_list="oss alsa sdl"
45 # these are for known platforms
46 optimize_cortexa8="no"
47 optimize_arm926ej="no"
51 CC="${CC-${CROSS_COMPILE}gcc}"
52 CXX="${CXX-${CROSS_COMPILE}g++}"
53 AS="${AS-${CROSS_COMPILE}as}"
54 MAIN_LDLIBS="$LDLIBS -lm"
55 config_mak="config.mak"
63 # call during arg parsing, so that cmd line can override platform defaults
71 sound_drivers="oss alsa"
72 optimize_cortexa8="yes"
78 CFLAGS="$CFLAGS -D__GP2X__"
79 if [ "$CROSS_COMPILE" = "arm-linux-" ]; then
80 # still using static, dynamic linking slows Wiz 1-10%
81 # also libm on F100 is not compatible
82 MAIN_LDLIBS="$MAIN_LDLIBS -static"
86 fail "unsupported platform: $platform"
92 optarg=`expr "x$opt" : 'x[^=]*=\(.*\)'` || true
94 --help|-h) show_help="yes"
96 --platform=*) set_platform "$optarg"
98 --sound-drivers=*) sound_drivers="$optarg"
100 *) echo "ERROR: unknown option $opt"; show_help="yes"
105 if [ "$show_help" = "yes" ]; then
107 echo " --help print this message"
108 echo " --platform=NAME target platform [$platform]"
109 echo " available: $platform_list"
110 echo " --sound-drivers=LIST sound output drivers [guessed]"
111 echo " available: $sound_driver_list"
112 echo "influential environment variables:"
113 echo " CROSS_COMPILE CC CXX AS CFLAGS ASFLAGS LDFLAGS LDLIBS"
117 # validate selections
118 if [ "x$sound_drivers" != "x" ]; then
119 for d in $sound_drivers; do
120 if ! echo $sound_driver_list | grep -q "\<$d\>"; then
121 fail "unsupported sound driver: $sound_driver"
126 if ! test -f "platform/libpicofe/README"; then
127 fail "libpicofe is missing, please run 'git submodule update --init'"
130 #if [ "$need_warm" = "yes" ]; then
131 # if ! test -f "frontend/warm/README"; then
132 # fail "wARM is missing, please run 'git submodule init && git submodule update'"
136 # basic compiler test
138 int main(void) { return 0; }
140 if ! compile_binary; then
141 fail "compiler test failed, please check config.log"
144 if [ -z "$ARCH" ]; then
145 ARCH=`$CC -dumpmachine | awk -F '-' '{print $1}'`
153 if [ "$optimize_cortexa8" = "yes" ]; then
154 CFLAGS="$CFLAGS -mcpu=cortex-a8 -mtune=cortex-a8"
155 ASFLAGS="$ASFLAGS -mcpu=cortex-a8"
157 if [ "$optimize_arm926ej" = "yes" ]; then
158 CFLAGS="$CFLAGS -mcpu=arm926ej-s -mtune=arm926ej-s"
159 ASFLAGS="$ASFLAGS -mcpu=arm926ej-s -mfloat-abi=softfp"
161 if [ "$optimize_arm920" = "yes" ]; then
162 CFLAGS="$CFLAGS -mcpu=arm920t -mtune=arm920t"
163 ASFLAGS="$ASFLAGS -mcpu=arm920t -mfloat-abi=soft"
166 if [ "x$have_arm_neon" = "x" ]; then
167 # detect NEON from user-supplied cflags to enable asm code
168 have_arm_neon=`check_define __ARM_NEON__ && echo yes` || true
170 if [ "x$have_armv7" = "x" ]; then
171 if check_define HAVE_ARMV7; then
177 if [ "x$have_armv6" = "x" ]; then
178 if check_define HAVE_ARMV6; then
183 if [ "x$have_armv5" = "x" ]; then
184 have_armv5=`check_define HAVE_ARMV5 && echo yes` || true
187 # automatically set mfpu and mfloat-abi if they are not set
188 if [ "$have_arm_neon" = "yes" ]; then
190 elif [ "$have_armv6" = "yes" ]; then
193 if [ "x$fpu" != "x" ]; then
194 echo "$CFLAGS" | grep -q -- '-mfpu=' || CFLAGS="$CFLAGS -mfpu=$fpu"
195 echo "$ASFLAGS" | grep -q -- '-mfpu=' || ASFLAGS="$ASFLAGS -mfpu=$fpu"
196 floatabi_set_by_gcc=`$CC -v 2>&1 | grep -q -- --with-float= && echo yes` || true
197 if [ "$floatabi_set_by_gcc" != "yes" ]; then
198 echo "$CFLAGS" | grep -q -- '-mfloat-abi=' || CFLAGS="$CFLAGS -mfloat-abi=softfp"
199 echo "$ASFLAGS" | grep -q -- '-mfloat-abi=' || ASFLAGS="$ASFLAGS -mfloat-abi=softfp"
203 # must disable thumb as recompiler can't handle it
204 if check_define __thumb__; then
205 CFLAGS="$CFLAGS -marm"
208 # warn about common mistakes
209 if [ "$platform" != "gp2x" -a "$have_armv5" != "yes" ]; then
210 if ! echo "$CFLAGS" | grep -q -- '-mcpu=\|-march='; then
211 echo "Warning: compiling for ARMv4, is that really what you want?"
212 echo "You probably should specify -mcpu= or -march= like this:"
213 echo " CFLAGS=-march=armv6 ./configure ..."
216 if [ "$have_arm_neon" = "yes" -a "$have_armv7" != "yes" ]; then
217 echo "Warning: compiling for NEON, but not ARMv7?"
218 echo "You probably want to specify -mcpu= or -march= like this:"
219 echo " CFLAGS=-march=armv7-a ./configure ..."
232 # header/library presence tests
237 int main(void) { uncompress(0, 0, 0, 0); }
246 void main() { png_init_io(0, 0); }
255 #include <sys/soundcard.h>
256 #include <sys/ioctl.h>
257 void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
265 #include <alsa/asoundlib.h>
266 void main() { snd_pcm_open(0, 0, 0, 0); }
275 void main() { SDL_OpenAudio(0, 0); }
283 #include <libavcodec/avcodec.h>
284 void main() { avcodec_decode_audio3(0, 0, 0, 0); }
289 #MAIN_LDLIBS="$MAIN_LDLIBS -lz"
290 #check_zlib || fail "please install zlib (libz-dev)"
292 MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
293 check_libpng || fail "please install libpng (libpng-dev)"
295 if check_libavcodec; then
296 have_libavcodec="yes"
298 case "$MAIN_LDLIBS" in
300 *) MAIN_LDLIBS="-ldl $MAIN_LDLIBS" ;;
304 # find what audio support we can compile
305 if [ "x$sound_drivers" = "x" ]; then
306 if check_oss; then sound_drivers="$sound_drivers oss"; fi
307 if check_alsa -lasound; then
308 sound_drivers="$sound_drivers alsa"
309 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
311 if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then
312 sound_drivers="$sound_drivers sdl"
316 if echo $sound_drivers | grep -q "\<oss\>"; then
317 check_oss || fail "oss support is missing"
319 if echo $sound_drivers | grep -q "\<alsa\>"; then
320 MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
321 check_alsa -lasound || fail "please install libasound2-dev"
325 if [ "$need_sdl" = "yes" ]; then
326 which sdl-config > /dev/null || \
327 fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
328 CFLAGS="$CFLAGS `sdl-config --cflags`"
329 MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
330 check_sdl `sdl-config --libs` || fail "please install libsdl (libsdl1.2-dev)"
334 void test(void *f, void *d) { fread(d, 1, 1, f); }
336 if compile_object -Wno-unused-result; then
337 CFLAGS="$CFLAGS -Wno-unused-result"
340 # set things that failed to autodetect to "no"
341 test "x$have_armv6" != "x" || have_armv6="no"
342 test "x$have_armv7" != "x" || have_armv7="no"
343 test "x$have_libavcodec" != "x" || have_libavcodec="no"
345 echo "architecture $ARCH"
346 echo "platform $platform"
347 echo "sound drivers $sound_drivers"
348 echo "C compiler $CC"
349 echo "C compiler flags $CFLAGS"
350 echo "libraries $MAIN_LDLIBS"
351 echo "linker flags $LDFLAGS"
352 echo "libavcodec (mp3) $have_libavcodec"
353 # echo "ARMv7 optimizations $have_armv7"
355 echo "# Automatically generated by configure" > $config_mak
356 printf "# Configured with:" >> $config_mak
357 printf " '%s'" "$0" "$@" >> $config_mak
360 echo "CC = $CC" >> $config_mak
361 echo "CXX = $CXX" >> $config_mak
362 echo "AS = $AS" >> $config_mak
363 echo "CFLAGS += $CFLAGS" >> $config_mak
364 echo "ASFLAGS += $ASFLAGS" >> $config_mak
365 echo "LDFLAGS += $LDFLAGS" >> $config_mak
366 echo "LDLIBS += $MAIN_LDLIBS" >> $config_mak
369 echo "ARCH = $ARCH" >> $config_mak
370 echo "PLATFORM = $platform" >> $config_mak
371 echo "SOUND_DRIVERS = $sound_drivers" >> $config_mak
372 if [ "$have_libavcodec" = "yes" ]; then
373 echo "HAVE_LIBAVCODEC = 1" >> $config_mak
376 # GP2X toolchains are too old for UAL asm,
377 # so add this here to not litter main Makefile
378 if [ "$platform" = "g1p2x" ]; then
380 echo "%.o: %.S" >> $config_mak
381 echo " $(CC) $(CFLAGS) -E -c $^ -o /tmp/$(notdir $@).s" >> $config_mak
382 echo " $(AS) $(ASFLAGS) /tmp/$(notdir $@).s -o $@" >> $config_mak
385 # use pandora's skin (for now)
386 test -e skin || ln -s platform/pandora/skin skin
388 # vim:shiftwidth=2:expandtab