-if [ "$platform" = "generic" ]; then
- generic_cflags=`sdl-config --cflags`
- generic_ldlibs=`sdl-config --libs`
- CFLAGS="$CFLAGS $generic_cflags"
- LDFLAGS="$LDFLAGS $generic_ldlibs"
-elif [ "$platform" = "maemo" ]; then
- maemo_cflags=`pkg-config --cflags hildon-1`
- maemo_ldlibs=`pkg-config --libs hildon-1`
- CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES $maemo_cflags"
- LDFLAGS="$LDFLAGS $maemo_ldlibs"
+case "$platform" in
+generic)
+ need_sdl="yes"
+ ;;
+maemo)
+ CFLAGS="$CFLAGS -DMAEMO -DMAEMO_CHANGES"
+ ;;
+libretro)
+ CFLAGS="$CFLAGS -fPIC"
+ MAIN_LDFLAGS="$MAIN_LDFLAGS -shared -Wl,--no-undefined"
+ ;;
+esac
+
+# header/library presence tests
+check_zlib()
+{
+ cat > $TMPC <<EOF
+ #include <zlib.h>
+ int main(void) { uncompress(0, 0, 0, 0); }
+EOF
+ compile_binary
+}
+
+check_libpng()
+{
+ cat > $TMPC <<EOF
+ #include <png.h>
+ void main() { png_init_io(0, 0); }
+EOF
+ compile_binary
+}
+
+check_oss()
+{
+ cat > $TMPC <<EOF
+ #include <sys/soundcard.h>
+ #include <sys/ioctl.h>
+ void main() { int a=0; ioctl(0, SNDCTL_DSP_SETFMT, &a); }
+EOF
+ compile_binary
+}
+
+check_alsa()
+{
+ cat > $TMPC <<EOF
+ #include <alsa/asoundlib.h>
+ void main() { snd_pcm_open(0, 0, 0, 0); }
+EOF
+ compile_binary "$@"
+}
+
+check_pulseaudio()
+{
+ cat > $TMPC <<EOF
+ #include <pulse/pulseaudio.h>
+ void main() { pa_threaded_mainloop_new(); }
+EOF
+ compile_binary "$@"
+}
+
+check_sdl()
+{
+ cat > $TMPC <<EOF
+ #include <SDL.h>
+ void main() { SDL_OpenAudio(0, 0); }
+EOF
+ compile_binary "$@"
+}
+
+check_xlib_headers()
+{
+ cat > $TMPC <<EOF
+ #include <X11/Xlib.h>
+ void *f() { return XOpenDisplay(0); }
+EOF
+ compile_object "$@"
+}
+
+MAIN_LDLIBS="$MAIN_LDLIBS -lz"
+check_zlib || fail "please install zlib (libz-dev)"
+
+MAIN_LDLIBS="-lpng $MAIN_LDLIBS"
+check_libpng || fail "please install libpng (libpng-dev)"
+
+# find what audio support we can compile
+if [ "x$sound_drivers" = "x" ]; then
+ if check_oss; then sound_drivers="$sound_drivers oss"; fi
+ if check_alsa -lasound; then
+ sound_drivers="$sound_drivers alsa"
+ MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
+ fi
+ if check_pulseaudio -lpulse; then
+ sound_drivers="$sound_drivers pulseaudio"
+ MAIN_LDLIBS="-lpulse $MAIN_LDLIBS"
+ fi
+ if [ "$need_sdl" = "yes" ] || check_sdl `sdl-config --cflags --libs`; then
+ sound_drivers="$sound_drivers sdl"
+ need_sdl="yes"
+ fi
+else
+ if echo $sound_drivers | grep -q "\<oss\>"; then
+ check_oss || fail "oss support is missing"
+ fi
+ if echo $sound_drivers | grep -q "\<alsa\>"; then
+ MAIN_LDLIBS="-lasound $MAIN_LDLIBS"
+ check_alsa || fail "please install libasound2-dev"
+ fi
+ if echo $sound_drivers | grep -q "\<pulseaudio\>"; then
+ MAIN_LDLIBS="-lpulse $MAIN_LDLIBS"
+ check_pulseaudio || fail "pulseaudio support is missing"
+ fi
+fi
+
+if [ "$need_sdl" = "yes" ]; then
+ which sdl-config > /dev/null || \
+ fail "sdl-config is missing; please install libsdl (libsdl1.2-dev)"
+ CFLAGS="$CFLAGS `sdl-config --cflags`"
+ MAIN_LDLIBS="`sdl-config --libs` $MAIN_LDLIBS"
+ check_sdl || fail "please install libsdl (libsdl1.2-dev)"