-AC_MSG_CHECKING(for audio API)
-case $host in
- *-*-linux*)
- AC_SUBST( sound_api, [_NO_API_] )
- AC_ARG_WITH(jack, [ --with-jack = choose JACK server support (linux only)], [AC_SUBST( sound_api, [-D__LINUX_JACK__] ) AC_MSG_RESULT(using JACK)], )
- if [test $sound_api = -D__LINUX_JACK__;] then
- TEMP_LIBS=$LIBS
- AC_CHECK_LIB(jack, jack_client_new, , AC_MSG_ERROR(JACK support requires the jack library!))
- AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(Jack support also requires the asound library!))
- LIBS="`pkg-config --cflags --libs jack` $TEMP_LIBS -lasound"
- audio_apis="-D__LINUX_JACK__"
- fi
-
- # Look for Alsa flag
- AC_ARG_WITH(alsa, [ --with-alsa = choose native ALSA API support (linux only)], [AC_SUBST( sound_api, [-D__LINUX_ALSA__] ) AC_MSG_RESULT(using ALSA)], )
- if [test $sound_api = -D__LINUX_ALSA__;] then
- AC_CHECK_LIB(asound, snd_pcm_open, , AC_MSG_ERROR(ALSA support requires the asound library!))
- audio_apis="-D__LINUX_ALSA__ $audio_apis"
- fi
-
- # Look for OSS flag
- AC_ARG_WITH(oss, [ --with-oss = choose OSS API support (linux only)], [AC_SUBST( sound_api, [-D__LINUX_OSS__] ) AC_MSG_RESULT(using OSS)], )
- if test $sound_api = -D__LINUX_OSS__; then
- audio_apis="-D__LINUX_OSS__ $audio_apis"
- fi
-
- # If no audio api flags specified, use OSS
- if [test $sound_api = _NO_API_;] then
- AC_SUBST( sound_api, [-D__LINUX_OSS__] )
- AC_MSG_RESULT(using OSS)
- AC_SUBST( audio_apis, [-D__LINUX_OSS__] )
- fi
- ;;
-
- *-sgi*)
- AC_SUBST( audio_apis, ["-D__IRIX_AL__ -LANG:std -w"] )
- AC_MSG_RESULT(using IRIX AL)
- AC_CHECK_LIB(audio, alOpenPort, , AC_MSG_ERROR(IRIX audio support requires the audio library!) )
- ;;
-
- *-apple*)
- # Check for CoreAudio framework
+
+# Aggregate options into a single string.
+AS_IF([test "x$with_jack" = "xyes"], [systems="$systems jack"])
+AS_IF([test "x$with_alsa" = "xyes"], [systems="$systems alsa"])
+AS_IF([test "x$with_pulse" = "xyes"], [systems="$systems pulse"])
+AS_IF([test "x$with_oss" = "xyes"], [systems="$systems oss"])
+AS_IF([test "x$with_core" = "xyes"], [systems="$systems core"])
+AS_IF([test "x$with_asio" = "xyes"], [systems="$systems asio"])
+AS_IF([test "x$with_dsound" = "xyes"], [systems="$systems dsound"])
+AS_IF([test "x$with_wasapi" = "xyes"], [systems="$systems wasapi"])
+required=" $systems "
+
+# If none, assign defaults if any are known for this OS.
+# User must specified with-* options for any unknown OS.
+AS_IF([test "x$systems" = "x"],
+ AS_CASE([$host],
+ [*-*-netbsd*], [systems="oss"],
+ [*-*-freebsd*], [systems="oss"],
+ [*-*-linux*], [systems="alsa pulse jack oss"],
+ [*-apple*], [systems="core jack"],
+ [*-mingw32*], [systems="asio dsound wasapi jack"],
+ [*-mingw64*], [systems="asio dsound wasapi jack"],
+ [*-msys*], [systems="asio dsound wasapi jack"],
+ ))
+
+# If any were specifically requested disabled, do it.
+AS_IF([test "x$with_jack" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v jack`])
+AS_IF([test "x$with_alsa" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v alsa`])
+AS_IF([test "x$with_pulse" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v pulse`])
+AS_IF([test "x$with_oss" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v oss`])
+AS_IF([test "x$with_core" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v core`])
+AS_IF([test "x$with_asio" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v asio`])
+AS_IF([test "x$with_dsound" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v dsound`])
+AS_IF([test "x$with_wasapi" = "xno"], [systems=`echo $systems|tr ' ' \\\\n|grep -v wasapi`])
+systems=" `echo $systems|tr \\\\n ' '` "
+
+# For each audio system, check if it is selected and found.
+# Note: Order specified above is not necessarily respected. However,
+# *actual* priority is set at run-time, see RtAudio::openRtApi.
+# One AS_CASE per system, since they are not mutually-exclusive.
+
+AS_CASE(["$systems"], [*" alsa "*], [
+ AC_CHECK_LIB(asound, snd_pcm_open,
+ [api="$api -D__LINUX_ALSA__"
+ req="$req alsa"
+ need_pthread=yes
+ found="$found ALSA"
+ LIBS="-lasound $LIBS"],
+ AS_CASE(["$required"], [*" alsa "*],
+ AC_MSG_ERROR([ALSA support requires the asound library!])))
+])
+
+AS_CASE(["$systems"], [*" pulse "*], [
+ AC_CHECK_LIB(pulse-simple, pa_simple_flush,
+ [api="$api -D__LINUX_PULSE__"
+ req="$req libpulse-simple"
+ need_pthread=yes
+ found="$found PulseAudio"
+ LIBS="-lpulse-simple $LIBS"],
+ AS_CASE(["$required"], [*" pulse "*],
+ AC_MSG_ERROR([PulseAudio support requires the pulse-simple library!])))
+])
+
+AS_CASE(["$systems"], [*" oss "*], [
+ # libossaudio not required on some platforms (e.g. linux) so we
+ # don't break things if it's not found, but issue a warning when we
+ # are not sure (i.e. not on linux)
+ AS_CASE([$host], [*-*-linux*], [], [*], [need_ossaudio=yes])
+ AC_CHECK_LIB(ossaudio, main, [have_ossaudio=true],
+ AS_CASE(["$required"], [*" oss "*],
+ AS_IF([test "x$need_ossaudio" = xyes],
+ AC_MSG_WARN([RtAudio may require the ossaudio library]))))
+
+ # linux systems may have soundcard.h but *not* have OSS4 installed,
+ # we have to actually check if it exports OSS4 symbols
+ AC_CHECK_DECL(SNDCTL_SYSINFO,
+ [api="$api -D__LINUX_OSS__"
+ need_pthread=yes
+ found="$found OSS"],
+ AS_CASE(["$required"], [*" oss "*],
+ AC_MSG_ERROR([sys/soundcard.h not found]))
+ [],
+ [#include <sys/soundcard.h>])
+])
+
+AS_CASE(["$systems"], [*" jack "*], [
+ AC_CHECK_LIB(jack, jack_client_open,
+ [api="$api -D__UNIX_JACK__"
+ req="$req jack"
+ need_pthread=yes
+ found="$found JACK"
+ LIBS="-ljack $LIBS"],
+ AS_CASE(["$required"], [*" jack "*],
+ AC_MSG_ERROR([JACK support requires the jack library!])))
+])
+
+AS_CASE(["$systems"], [*" core "*], [