+# header/library presence tests
+check_zlib()
+{
+ cat > $TMPC <<EOF
+ #include <zlib.h>
+ void main() { uncompress(0, 0, 0, 0); }
+EOF
+ compile_binary
+}
+
+check_bzlib()
+{
+ cat > $TMPC <<EOF
+ #include <bzlib.h>
+ void main() { BZ2_bzBuffToBuffDecompress(0, 0, 0, 0, 0, 0); }
+EOF
+ compile_object
+}
+
+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_sdl()
+{
+ cat > $TMPC <<EOF
+ #include <SDL.h>
+ void main() { SDL_OpenAudio(0, 0); }
+EOF
+ compile_binary "$@"
+}
+
+check_zlib || fail "please install libz-dev"
+check_bzlib || fail "please install libbz2-dev"
+check_libpng || fail "please install 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"; fi
+ if check_sdl; then sound_drivers="$sound_drivers sdl"; fi
+fi
+
+if echo $sound_drivers | grep -q "\<oss\>"; then
+ check_oss || fail "oss support missing"
+fi
+if echo $sound_drivers | grep -q "\<alsa\>"; then
+ MAIN_LDLIBS="$MAIN_LDLIBS -lasound"
+ check_alsa || fail "please install libasound2-dev"
+fi
+if echo $sound_drivers | grep -q "\<sdl\>"; then
+ echo $MAIN_LDLIBS | grep -qi SDL || CFLAGS="$CFLAGS `sdl-config --cflags`"
+ echo $MAIN_LDLIBS | grep -qi SDL || MAIN_LDLIBS="$MAIN_LDLIBS `sdl-config --libs`"
+ check_sdl || fail "please install libsdl1.2-dev"
+fi
+