+# 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!])))