shithub: sox

Download patch

ref: 5d1a242d862057bd3a046882fd511f2a15fafd77
parent: ffc11e800e271c0ed38284fdd114507253c7112d
author: robs <robs>
date: Thu Feb 12 15:33:57 EST 2009

allow optional formats to be loaded statically or dynamically

--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -67,6 +67,7 @@
   set(CMAKE_REQUIRED_LIBRARIES ${CMAKE_REQUIRED_LIBRARIES} -lm)
 endif(NEED_LIBM)
 optional(EXTERNAL_GSM gsm/gsm.h gsm gsm_create "")
+optional(EXTERNAL_LPC10 lpc10/lpc10.h lpc10 lpc10_create "")
 optional(HAVE_ALSA alsa/asoundlib.h asound snd_pcm_open alsa)
 optional(HAVE_AMRNB amrnb/sp_dec.h amrnb Decoder_Interface_init amr-nb)
 optional(HAVE_AMRWB amrwb/dec.h amrwb D_IF_init amr-wb)
@@ -79,7 +80,7 @@
 optional(HAVE_ID3TAG id3tag.h id3tag id3_file_open "")
 optional(HAVE_SNDIO CoreAudio/CoreAudio.h CoreAudio AudioHardwareGetProperty coreaudio)
 optional(HAVE_SNDIO sndio.h sndio sio_open sndio)
-optional(HAVE_LIBAO ao/ao.h ao ao_play ao)
+optional(HAVE_AO ao/ao.h ao ao_play ao)
 optional(HAVE_FLAC FLAC/all.h FLAC FLAC__stream_encoder_new flac)
 optional(HAVE_MAD_H mad.h mad mad_stream_buffer mp3)
 optional(HAVE_LAME_LAME_H lame/lame.h mp3lame lame_init mp3)
@@ -89,6 +90,7 @@
 optional(HAVE_MAGIC magic.h magic magic_open "")
 #optional(HAVE_OGG_SPEEX speex/speex.h speex speex_decoder_init speex)
 optional(HAVE_PNG png.h png png_set_rows spectrogram)
+optional(HAVE_PULSEAUDIO pulse/simple.h pulse-simple pa_simple_new pulseaudio)
 optional(HAVE_SNDFILE sndfile.h sndfile sf_open sndfile)
 optional(HAVE_SNDFILE sndfile.h sndfile sf_open fap)
 optional(HAVE_SNDFILE sndfile.h sndfile sf_open mat4)
@@ -115,12 +117,23 @@
   set(HAVE_MP3 1)
 endif (HAVE_LAME_LAME_H OR HAVE_MAD_H)
 
+if (HAVE_SUN_AUDIOIO_H OR HAVE_SYS_AUDIOIO_H)
+  set(HAVE_SUN_AUDIO 1)
+endif (HAVE_SUN_AUDIOIO_H OR HAVE_SYS_AUDIOIO_H)
+
+if (HAVE_SYS_SOUNDCARD_H OR HAVE_MACHINE_SOUNDCARD_H)
+  set(HAVE_OSS 1)
+endif (HAVE_SYS_SOUNDCARD_H OR HAVE_MACHINE_SOUNDCARD_H)
+
 configure_file(sox.pc.in sox.pc @ONLY)
 install_files(/lib/pkgconfig FILES sox.pc)
 
-subdirs(src lpc10)
+subdirs(src)
 
 if (NOT EXTERNAL_GSM)
   add_subdirectory(libgsm)
 endif (NOT EXTERNAL_GSM)
 
+if (NOT EXTERNAL_LPC10)
+  add_subdirectory(lpc10)
+endif (NOT EXTERNAL_LPC10)
--- a/configure.ac
+++ b/configure.ac
@@ -45,7 +45,7 @@
 fi
 
 if test "$using_libltdl" != "no"; then
-  AC_CHECK_HEADERS(ltdl.h, 
+  AC_CHECK_HEADERS(ltdl.h,
                    AC_CHECK_LIB(ltdl, lt_dlinit, LIBLTDL="$LIBLTDL -lltdl",
                                 using_libltdl=no), using_libltdl=no)
 fi
@@ -98,7 +98,7 @@
 dnl Extra CFLAGS if we have gcc
 if test "$GCC" = yes; then
 
-    dnl Detect gcc version.  Convert GCC version number to 
+    dnl Detect gcc version.  Convert GCC version number to
     dnl something easier to compare.
     AC_MSG_CHECKING([gcc version])
     gccver=`$CC -dumpversion`
@@ -179,8 +179,10 @@
     LIBTOOLFLAGS=--silent
 fi
 AC_SUBST(LIBTOOLFLAGS)
-   
-dnl Check for GOMP
+
+
+
+dnl Check for GOMP library
 AC_MSG_CHECKING([whether to use GOMP])
 AC_ARG_ENABLE(gomp,
     AC_HELP_STRING([--disable-gomp], [Don't use GOMP.]),,enable_gomp=yes)
@@ -197,262 +199,9 @@
 AM_CONDITIONAL(HAVE_OPENMP, test x$enable_gomp = xyes)
 AC_SUBST(GOMP_LIBS)
 
-audio_driver_found=no  
-    
-dnl Check for ALSA
-AC_MSG_CHECKING([whether to try building ALSA sound driver])
-AC_ARG_ENABLE(alsa,
-    AC_HELP_STRING([--disable-alsa], [Don't build ALSA sound driver.]),,enable_alsa=yes)
-AC_MSG_RESULT($enable_alsa)
-if test "$enable_alsa" = "yes"; then
-    AC_CHECK_HEADERS(alsa/asoundlib.h,
-        AC_CHECK_LIB(asound, snd_pcm_open, ALSA_LIBS="$ALSA_LIBS -lasound", enable_alsa=no),
-        enable_alsa=no)
-fi
-if test "$enable_alsa" = yes; then
-   AC_DEFINE(HAVE_ALSA, 1, [Define to 1 if you have ALSA.])
-   audio_driver_found=yes
-fi
-AM_CONDITIONAL(HAVE_ALSA, test x$enable_alsa = xyes)
-AC_SUBST(ALSA_LIBS)
 
-dnl Check for libao
-AC_MSG_CHECKING([whether to try building libao sound driver])
-AC_ARG_ENABLE(libao,
-    AC_HELP_STRING([--disable-libao], [Don't build libao sound driver.]),,enable_libao=yes)
-AC_MSG_RESULT($enable_libao)
-if test "$enable_libao" = "yes"; then
-    AC_CHECK_HEADERS(ao/ao.h,
-        AC_CHECK_LIB(ao, ao_play, AO_LIBS="$AO_LIBS -lao", enable_libao=no),
-        enable_libao=no)
-fi
-if test "$enable_libao" = yes; then
-   AC_DEFINE(HAVE_LIBAO, 1, [Define to 1 if you have libao.])
-   audio_driver_found=yes
-fi
-AM_CONDITIONAL(HAVE_LIBAO, test x$enable_libao = xyes)
-AC_SUBST(AO_LIBS)
 
-dnl Check for OSS
-AC_MSG_CHECKING([whether to try building OSS sound driver])
-AC_ARG_ENABLE(oss,
-    AC_HELP_STRING([--disable-oss], [Don't build OSS sound driver.]),,enable_oss=yes)
-AC_MSG_RESULT($enable_oss)
-if test "$enable_oss" = "yes"; then
-    AC_CHECK_HEADERS(sys/soundcard.h,,
-        [AC_CHECK_HEADERS(machine/soundcard.h,
-            [AC_CHECK_LIB(ossaudio, _oss_ioctl, OSS_LIBS="$OSS_LIBS -lossaudio")],
-            enable_oss=no)])
-fi
-if test "$enable_oss" = yes; then
-   AC_DEFINE(HAVE_OSS, 1, [Define to 1 if you have OSS.])
-   audio_driver_found=yes
-fi
-AM_CONDITIONAL(HAVE_OSS, test x$enable_oss = xyes)
-AC_SUBST(OSS_LIBS)
-
-dnl Check for sndio
-AC_MSG_CHECKING([whether to try building sndio sound driver])
-AC_ARG_ENABLE(sndio,
-    AC_HELP_STRING([--disable-sndio], [Don't build sndio sound driver.]),,enable_sndio=yes)
-AC_MSG_RESULT($enable_sndio)
-if test "$enable_sndio" = "yes"; then
-    AC_CHECK_HEADERS(sndio.h,
-        [AC_CHECK_LIB(sndio, sio_open, SNDIO_LIBS="$SNDIO_LIBS -lsndio")],
-        enable_sndio=no)
-fi
-if test "$enable_sndio" = yes; then
-   AC_DEFINE(HAVE_SNDIO, 1, [Define to 1 if you have sndio.])
-   audio_driver_found=yes
-fi
-AM_CONDITIONAL(HAVE_SNDIO, test x$enable_sndio = xyes)
-AC_SUBST(SNDIO_LIBS)
-
-dnl Check for Sun audio
-AC_MSG_CHECKING([whether to try building Sun audio driver])
-AC_ARG_ENABLE(sun-audio,
-    AC_HELP_STRING([--disable-sun-audio], [Don't build Sun audio driver.]),,enable_sun_audio=yes)
-AC_MSG_RESULT($enable_sun_audio)
-if test "$enable_sun_audio" = "yes"; then
-    AC_CHECK_HEADERS(sys/audioio.h,,
-        [AC_CHECK_HEADERS(sun/audioio.h,, enable_sun_audio=no)])
-fi
-if test "$enable_sun_audio" = yes; then
-   AC_DEFINE(HAVE_SUN_AUDIO, 1, [Define to 1 if you have Sun audio.])
-   audio_driver_found=yes
-fi
-AM_CONDITIONAL(HAVE_SUN_AUDIO, test x$enable_sun_audio = xyes)
-
-dnl Check for Mac OSX CoreAudio
-AC_MSG_CHECKING([whether to try building CoreAudio driver])
-AC_ARG_ENABLE(coreaudio,
-    AC_HELP_STRING([--disable-coreaudio], [Don't build CoreAudio driver.]),,enable_coreaudio=yes)
-AC_MSG_RESULT($enable_coreaudio)
-if test "$enable_coreaudio" = "yes"; then
-    AC_CHECK_HEADERS(CoreAudio/CoreAudio.h, [COREAUDIO_LIBS="$COREAUDIO_LIBS -Wl,-framework,CoreAudio"], enable_coreaudio=no)
-fi
-if test "$enable_coreaudio" = yes; then
-   AC_DEFINE(HAVE_COREAUDIO, 1, [Define to 1 if you have CoreAudio.])
-   audio_driver_found=yes
-fi
-AM_CONDITIONAL(HAVE_COREAUDIO, test x$enable_coreaudio = xyes)
-AC_SUBST(COREAUDIO_LIBS)
-
-dnl Check for Pulse Audio
-AC_MSG_CHECKING([whether to try building Pulse Audio driver])
-AC_ARG_ENABLE(pulseaudio,
-    AC_HELP_STRING([--disable-pulseaudio], [Don't build Pulse Audio driver.]),,enable_pulseaudio=yes)
-AC_MSG_RESULT($enable_pulseaudio)
-if test "$enable_pulseaudio" = "yes"; then
-    AC_CHECK_HEADERS(pulse/simple.h, [PULSEAUDIO_LIBS="$PULSEAUDIO_LIBS -lpulse -lpulse-simple"], enable_pulseaudio=no)
-fi
-if test "$enable_pulseaudio" = yes; then
-   AC_DEFINE(HAVE_PULSEAUDIO, 1, [Define to 1 if you have Pulse Audio.])
-   audio_driver_found=yes
-fi
-AM_CONDITIONAL(HAVE_PULSEAUDIO, test x$enable_pulseaudio = xyes)
-AC_SUBST(PULSEAUDIO_LIBS)
-
-dnl Check if we want to disable all symlinks
-AC_MSG_CHECKING([whether to enable symlinks])
-AC_ARG_ENABLE(symlinks,
-    AC_HELP_STRING([--disable-symlinks], [Don't make any symlinks to sox.]),,enable_symlinks=yes)
-AC_MSG_RESULT($enable_symlinks)
-
-enable_playrec_symlinks=no
-if test "$enable_symlinks" = "yes"; then
-    SYMLINKS=yes
-    if test "$audio_driver_found" = "yes"; then
-        PLAYRECLINKS=yes
-        enable_playrec_symlinks=yes
-    fi
-fi
-AC_SUBST(SYMLINKS)
-AC_SUBST(PLAYRECLINKS)
- 
-dnl Check for libgsm
-found_libgsm=yes
-AC_CHECK_HEADERS(gsm/gsm.h, ,
-    [AC_CHECK_HEADERS(gsm.h, ,found_libgsm=no)])
-    AC_CHECK_LIB(gsm, gsm_create, GSM_LIBS="$GSM_LIBS -lgsm", found_libgsm=no)
-if test "$found_libgsm" = yes; then
-    AC_DEFINE(EXTERNAL_GSM, 1, [Define if you are using an external GSM library])
-else
-    LIBGSM_LIBADD=../libgsm/libgsm.la
-fi
-AC_SUBST(LIBGSM_LIBADD)
-AC_SUBST(GSM_LIBS)
-AM_CONDITIONAL(EXTERNAL_GSM, test x$found_libgsm = xyes)
-
-dnl Check for liblpc10
-found_liblpc10=yes
-AC_CHECK_HEADERS(lpc10.h, ,
-    [AC_CHECK_HEADERS(lpc10.h, ,found_liblpc10=no)])
-    AC_CHECK_LIB(lpc10, create_lpc10_encoder_state, LPC10_LIBS="$LPC10_LIBS -llpc10", found_liblpc10=no)
-if test "$found_liblpc10" = yes; then
-    AC_DEFINE(EXTERNAL_LPC10, 1, [Define if you are using an external LPC10 library])
-else
-    LIBLPC10_LIBADD=../lpc10/liblpc10.la
-fi
-AC_SUBST(LIBLPC10_LIBADD)
-AC_SUBST(LPC10_LIBS)
-AM_CONDITIONAL(EXTERNAL_LPC10, test x$found_liblpc10 = xyes)
-
-dnl Check for libsndfile
-AC_ARG_WITH(sndfile,
-    AC_HELP_STRING([--without-sndfile],
-    [Don't try to use libsndfile]))
-using_sndfile=no
-if test "$with_sndfile" != "no"; then
-    using_sndfile=yes
-    SOX_PATH_SNDFILE(, using_sndfile=no)
-    if test "$with_sndfile" = "yes" -a "$using_sndfile" = "no"; then
-        AC_MSG_FAILURE([cannot find libsndfile])
-    fi
-fi
-if test "$using_sndfile" = yes; then
-   AC_DEFINE(HAVE_SNDFILE, 1, [Define to 1 if you have libsndfile.])
-fi
-AM_CONDITIONAL(HAVE_SNDFILE, test x$using_sndfile = xyes)
-AC_SUBST(SNDFILE_CFLAGS)
-AC_SUBST(SNDFILE_LIBS)
-        
-dnl Check for Ogg Vorbis libraries
-AC_ARG_WITH(ogg,
-    AC_HELP_STRING([--without-ogg], 
-	[Don't try to use Ogg Vorbis]))
-using_ogg=no
-if test "$with_ogg" != "no"; then
-    using_ogg=yes
-    AC_CHECK_HEADER(vorbis/codec.h,
-        [AC_CHECK_LIB(ogg, ogg_packet_clear, OGG_LIBS="$OGG_LIBS -logg", using_ogg=no)
-        AC_CHECK_LIB(vorbis, vorbis_analysis_headerout, OGG_LIBS="-lvorbis $OGG_LIBS", using_ogg=no, $OGG_LIBS)
-        AC_CHECK_LIB(vorbisfile, ov_clear, OGG_LIBS="-lvorbisfile $OGG_LIBS", using_ogg=no, $OGG_LIBS)
-        AC_CHECK_LIB(vorbisenc, vorbis_encode_init_vbr, OGG_LIBS="-lvorbisenc $OGG_LIBS", using_ogg=no, $OGG_LIBS)],
-        using_ogg=no)
-    if test "$with_ogg" = "yes" -a "$using_ogg" = "no"; then
-        AC_MSG_FAILURE([cannot find Ogg Vorbis])
-    fi
-fi
-if test "$using_ogg" = yes; then
-   AC_DEFINE(HAVE_OGG_VORBIS, 1, [Define to 1 if you have Ogg Vorbis.])
-fi
-AM_CONDITIONAL(HAVE_OGG_VORBIS, test x$using_ogg = xyes)
-AC_SUBST(OGG_LIBS)
-
-dnl Check for FLAC libraries
-case $target in
-  *mingw*)
-  FLAC_LIBS="-lwsock32"
-  ;;
-esac
-
-AC_ARG_WITH(flac, AC_HELP_STRING([--without-flac], [Don't try to use FLAC]),
-    [], with_flac=yes)
-AC_ARG_WITH(flac, AC_HELP_STRING([--with-flac=dyn], [Try to use FLAC dynamically]))
-using_flac=no
-if test "$with_flac" != "no"; then
-    using_flac=$with_flac
-    dnl  Note passing in OGG_LIBS.  That is because FLAC has optional
-    dnl  support for OGG and if OGG libraries are found on this
-    dnl  system then its highly likely to be compiled into FLAC
-    dnl  and will require these at link time.
-    AC_CHECK_HEADER(FLAC/all.h,
-        [AC_CHECK_LIB(FLAC, FLAC__stream_encoder_new, FLAC_LIBS="-lFLAC $FLAC_LIBS $OGG_LIBS",using_flac=no, $FLAC_LIBS $OGG_LIBS)],
-        using_flac=no)
-    if test "$with_flac" = "yes" -a "$using_flac" = "no"; then
-        AC_MSG_FAILURE([cannot find FLAC])
-    fi
-fi
-if test "$using_flac" != no; then
-  AC_DEFINE(HAVE_FLAC, 1, [Define to 1 if you have FLAC.])
-  if test "$using_flac" = yes; then
-    AC_DEFINE(STATIC_FLAC, 1, [Define to 1 if you have static FLAC.])
-  fi
-fi
-AM_CONDITIONAL(HAVE_FLAC, test $using_flac != no)
-AM_CONDITIONAL(STATIC_FLAC, test $using_flac = yes)
-AC_SUBST(FLAC_LIBS)
-
-dnl Check for ffmpeg libraries
-AC_ARG_WITH(ffmpeg,
-    AC_HELP_STRING([--without-ffmpeg],
-        [Don't try to use ffmpeg]))
-using_ffmpeg=no
-if test "$with_ffmpeg" != "no"; then
-    using_ffmpeg=yes
-    SOX_PATH_FFMPEG(, using_ffmpeg=no)
-    if test "$with_ffmpeg" = "yes" -a "$using_ffmpeg" = "no"; then
-        AC_MSG_FAILURE([cannot find ffmpeg])
-    fi
-fi
-if test "$using_ffmpeg" = yes; then
-   AC_DEFINE(HAVE_FFMPEG, 1, [Define to 1 if you have ffmpeg.])
-fi
-AM_CONDITIONAL(HAVE_FFMPEG, test x$using_ffmpeg = xyes)
-AC_SUBST(FFMPEG_LIBS)
-
-dnl Check for magic libraries
+dnl Check for magic library
 AC_ARG_WITH(magic,
     AC_HELP_STRING([--without-magic],
         [Don't try to use magic]))
@@ -472,6 +221,48 @@
 AM_CONDITIONAL(HAVE_MAGIC, test x$using_magic = xyes)
 AC_SUBST(MAGIC_LIBS)
 
+
+
+dnl Check for png libraries
+AC_ARG_WITH(png,
+    AC_HELP_STRING([--without-png],
+        [Don't try to use png]))
+using_png=no
+if test "$with_png" != "no"; then
+    using_png=yes
+    AC_CHECK_HEADER(png.h,
+        [AC_CHECK_LIB(png, png_set_rows, PNG_LIBS="$PNG_LIBS -lpng -lz" ,using_png=no, -lz)],
+        using_png=no)
+    if test "$with_png" = "yes" -a "$using_png" = "no"; then
+        AC_MSG_FAILURE([cannot find png])
+    fi
+fi
+if test "$using_png" = yes; then
+   AC_DEFINE(HAVE_PNG, 1, [Define to 1 if you have PNG.])
+fi
+AM_CONDITIONAL(HAVE_PNG, test x$using_png = xyes)
+AC_SUBST(PNG_LIBS)
+
+
+
+dnl Test for LADSPA
+AC_ARG_WITH(ladspa,
+    AC_HELP_STRING([--without-ladspa], [Don't try to use LADSPA]))
+using_ladspa=no
+if test "$with_ladspa" != "no" -a "$using_libltdl" = "yes"; then
+    using_ladspa=yes
+    AC_CHECK_HEADERS(ladspa.h,, using_ladspa=no)
+    if test "$with_ladspa" = "yes" -a "$using_ladspa" = "no"; then
+        AC_MSG_FAILURE([cannot find ladspa.h])
+    fi
+fi
+LADSPA_PATH=${libdir}/ladspa
+AC_ARG_WITH(ladspa-path,
+    AC_HELP_STRING([--with-ladspa-path], [Default search path for LADSPA plugins]))
+AC_SUBST(LADSPA_PATH)
+
+
+
 dnl Check for MAD libraries
 AC_ARG_WITH(mad,
     AC_HELP_STRING([--without-mad],
@@ -479,14 +270,14 @@
 using_mad=no
 if test "$with_mad" != "no"; then
     using_mad=yes
-    AC_CHECK_HEADERS(mad.h,
-        [AC_CHECK_LIB(mad, mad_stream_buffer, MP3_LIBS="$MP3_LIBS -lmad",using_mad=no)],
-        using_mad=no)
+    AC_CHECK_HEADERS(mad.h, [AC_CHECK_LIB(mad, mad_stream_buffer, MP3_LIBS="$MP3_LIBS -lmad",using_mad=no)], using_mad=no)
     if test "$with_mad" = "yes" -a "$using_mad" = "no"; then
         AC_MSG_FAILURE([cannot find libmad])
     fi
 fi
 
+
+
 dnl Check for id3tag libraries
 AC_ARG_WITH(id3tag,
     AC_HELP_STRING([--without-id3tag],
@@ -506,7 +297,9 @@
 fi
 AM_CONDITIONAL(HAVE_ID3TAG, test x$using_id3tag = xyes)
 
-dnl Test for LAME library.
+
+
+dnl Check for LAME library.
 AC_ARG_WITH(lame,
     AC_HELP_STRING([--without-lame],
         [Don't try to use LAME (LAME Ain't an MP3 Encoder)]))
@@ -521,163 +314,420 @@
     fi
 fi
 
-dnl MP3 library depends on libmad || LAME
-if test "$using_mad" = yes -o "$using_lame" = yes; then
-   AC_DEFINE(HAVE_MP3, 1, [Define to 1 if you have lame or mad support.])
+
+
+dnl Check for FLAC libraries
+dnl  Note passing in OGG_VORBIS_LIBS.  That is because FLAC has optional
+dnl  support for OGG and if OGG libraries are found on this
+dnl  system then its highly likely to be compiled into FLAC
+dnl  and will require these at link time.
+case $target in
+  *mingw*)
+  FLAC_LIBS="-lwsock32"
+  ;;
+esac
+AC_OPTIONAL_FORMAT(flac, FLAC, FLAC/all.h, FLAC, FLAC__stream_encoder_new, "-lFLAC $FLAC_LIBS $OGG_VORBIS_LIBS", $FLAC_LIBS $OGG_VORBIS_LIBS, yes)
+
+
+
+AC_OPTIONAL_FORMAT(amrwb, AMRWB, amrwb/dec.h, amrwb, D_IF_init, "$AMR_WB_LIBS -lamrwb", [$AMR_WB_LIBS -lamrwb])
+
+
+
+AC_OPTIONAL_FORMAT(amrnb, AMRNB, amrnb/sp_dec.h, amrnb, Decoder_Interface_init, "$AMR_WB_LIBS -lamrnb", [$AMR_WB_LIBS -lamrnb])
+
+
+
+AC_OPTIONAL_FORMAT(wavpack, WAVPACK, wavpack/wavpack.h, wavpack, WavpackGetSampleRate, "$WAVPACK_LIBS -lwavpack", [$WAVPACK_LIBS -lwavpack])
+
+
+
+AC_OPTIONAL_FORMAT(sndio, SNDIO, sndio.h, sndio, sio_open, "$SNDIO_LIBS -lsndio", [$SNDIO_LIBS -lsndio],yes)
+
+
+
+AC_OPTIONAL_FORMAT(coreaudio, COREAUDIO, CoreAudio/CoreAudio.h, CoreAudio, AudioHardwareGetProperty, [$COREAUDIO_LIBS -Wl,-framework,CoreAudio], [$COREAUDIO_LIBS -Wl,-framework,CoreAudio],yes)
+
+
+
+AC_OPTIONAL_FORMAT(alsa, ALSA, alsa/asoundlib.h, asound, snd_pcm_open, "$ALSA_LIBS -lasound", [$ALSA_LIBS -lasound],yes)
+
+
+
+AC_OPTIONAL_FORMAT(ao, AO, ao/ao.h, ao, ao_play, "$AO_LIBS -lao", [$AO_LIBS -lao])
+
+
+
+AC_OPTIONAL_FORMAT(pulseaudio, PULSEAUDIO, pulse/simple.h, pulse, pa_simple_new, "$PULSEAUDIO_LIBS -lpulse -lpulse-simple", [$PULSEAUDIO_LIBS -lpulse -lpulse-simple])
+
+
+
+dnl Check for Ogg Vorbis libraries
+AC_ARG_WITH(oggvorbis, AC_HELP_STRING([--with-oggvorbis=dyn], [load oggvorbis dynamically]))
+using_oggvorbis=$with_oggvorbis
+if test "_$with_oggvorbis" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load oggvorbis dynamically])
+  fi
+elif test "_$with_oggvorbis" = _; then
+  using_oggvorbis=yes
+elif test "_$with_oggvorbis" != _yes -a "_$with_oggvorbis" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-oggvorbis=$with_oggvorbis])
 fi
-AM_CONDITIONAL(HAVE_MP3, test "x$using_mad" = "xyes" -o "x$using_lame" = "xyes")
-AC_SUBST(MP3_LIBS)
+if test _$with_oggvorbis != _no; then
+  AC_CHECK_HEADER(vorbis/codec.h,
+      [AC_CHECK_LIB(ogg, ogg_packet_clear, OGG_VORBIS_LIBS="$OGG_VORBIS_LIBS -logg", using_oggvorbis=no)
+      AC_CHECK_LIB(vorbis, vorbis_analysis_headerout, OGG_VORBIS_LIBS="-lvorbis $OGG_VORBIS_LIBS", using_oggvorbis=no, $OGG_VORBIS_LIBS)
+      AC_CHECK_LIB(vorbisfile, ov_clear, OGG_VORBIS_LIBS="-lvorbisfile $OGG_VORBIS_LIBS", using_oggvorbis=no, $OGG_VORBIS_LIBS)
+      AC_CHECK_LIB(vorbisenc, vorbis_encode_init_vbr, OGG_VORBIS_LIBS="-lvorbisenc $OGG_VORBIS_LIBS", using_oggvorbis=no, $OGG_VORBIS_LIBS)],
+      using_oggvorbis=no)
+  if test _$with_oggvorbis != _ -a $using_oggvorbis = no; then
+    AC_MSG_FAILURE([cannot find oggvorbis])
+  fi
+fi
+if test "$using_oggvorbis" != no; then
+  AC_DEFINE(HAVE_OGG_VORBIS, 1, [Define to 1 if you have oggvorbis.])
+  if test "$using_oggvorbis" = yes; then
+    AC_DEFINE(STATIC_OGG_VORBIS, 1, [Define to 1 if you have static oggvorbis.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_OGG_VORBIS, test $using_oggvorbis != no)
+AM_CONDITIONAL(STATIC_OGG_VORBIS, test $using_oggvorbis = yes)
+AC_SUBST(OGG_VORBIS_LIBS)
 
-dnl Check for amr-wb libraries
-AC_ARG_WITH(amr-wb,
-    AC_HELP_STRING([--without-amr-wb],
-        [Don't try to use amr-wb]))
-using_amr_wb=no
-if test "$with_amr_wb" != "no"; then
-    using_amr_wb=yes
-    AC_CHECK_HEADER(amrwb/dec.h,
-        [AC_CHECK_LIB(amrwb, D_IF_init, AMR_WB_LIBS="$AMR_WB_LIBS -lamrwb",using_amr_wb=no)],
-        using_amr_wb=no)
-    if test "$with_amr_wb" = "yes" -a "$using_amr_wb" = "no"; then
-        AC_MSG_FAILURE([cannot find amr-wb])
-    fi
+
+
+dnl Check for libsndfile
+AC_ARG_WITH(sndfile, AC_HELP_STRING([--with-sndfile=dyn], [load sndfile dynamically]))
+using_sndfile=$with_sndfile
+if test "_$with_sndfile" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load sndfile dynamically])
+  fi
+elif test "_$with_sndfile" = _; then
+  using_sndfile=yes
+elif test "_$with_sndfile" != _yes -a "_$with_sndfile" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-sndfile=$with_sndfile])
 fi
-if test "$using_amr_wb" = yes; then
-   AC_DEFINE(HAVE_AMRWB, 1, [Define to 1 if you have AMR-WB.])
+if test _$with_sndfile != _no; then
+  SOX_PATH_SNDFILE(, using_sndfile=no)
+  if test _$with_sndfile != _ -a $using_sndfile = no; then
+    AC_MSG_FAILURE([cannot find sndfile])
+  fi
 fi
-AM_CONDITIONAL(HAVE_AMRWB, test x$using_amr_wb = xyes)
-AC_SUBST(AMR_WB_LIBS)
+if test "$using_sndfile" != no; then
+  AC_DEFINE(HAVE_SNDFILE, 1, [Define to 1 if you have sndfile.])
+  if test "$using_sndfile" = yes; then
+    AC_DEFINE(STATIC_SNDFILE, 1, [Define to 1 if you have static sndfile.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_SNDFILE, test $using_sndfile != no)
+AM_CONDITIONAL(STATIC_SNDFILE, test $using_sndfile = yes)
+AC_SUBST(SNDFILE_LIBS)
+AC_SUBST(SNDFILE_CFLAGS)
 
-dnl Check for amr-nb libraries
-AC_ARG_WITH(amr-nb,
-    AC_HELP_STRING([--without-amr-nb],
-        [Don't try to use amr-nb]))
-using_amr_nb=no
-if test "$with_amr_nb" != "no"; then
-    using_amr_nb=yes
-    AC_CHECK_HEADER(amrnb/sp_dec.h,
-        [AC_CHECK_LIB(amrnb, Decoder_Interface_init, AMR_NB_LIBS="$AMR_NB_LIBS -lamrnb" ,using_amr_nb=no)],
-        using_amr_nb=no)
-    if test "$with_amr_nb" = "yes" -a "$using_amr_nb" = "no"; then
-        AC_MSG_FAILURE([cannot find amr-nb])
-    fi
+
+
+dnl Check for libffmpeg
+AC_ARG_WITH(ffmpeg, AC_HELP_STRING([--with-ffmpeg=dyn], [load ffmpeg dynamically]))
+using_ffmpeg=$with_ffmpeg
+if test "_$with_ffmpeg" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load ffmpeg dynamically])
+  fi
+elif test "_$with_ffmpeg" = _; then
+  using_ffmpeg=yes
+elif test "_$with_ffmpeg" != _yes -a "_$with_ffmpeg" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-ffmpeg=$with_ffmpeg])
 fi
-if test "$using_amr_nb" = yes; then
-   AC_DEFINE(HAVE_AMRNB, 1, [Define to 1 if you have AMR-NB.])
+if test _$with_ffmpeg != _no; then
+  SOX_PATH_FFMPEG(, using_ffmpeg=no)
+  if test _$with_ffmpeg != _ -a $using_ffmpeg = no; then
+    AC_MSG_FAILURE([cannot find ffmpeg])
+  fi
 fi
-AM_CONDITIONAL(HAVE_AMRNB, test x$using_amr_nb = xyes)
-AC_SUBST(AMR_NB_LIBS)
+if test "$using_ffmpeg" != no; then
+  AC_DEFINE(HAVE_FFMPEG, 1, [Define to 1 if you have ffmpeg.])
+  if test "$using_ffmpeg" = yes; then
+    AC_DEFINE(STATIC_FFMPEG, 1, [Define to 1 if you have static ffmpeg.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_FFMPEG, test $using_ffmpeg != no)
+AM_CONDITIONAL(STATIC_FFMPEG, test $using_ffmpeg = yes)
+AC_SUBST(FFMPEG_LIBS)
 
-dnl Check for wavpack libraries
-AC_ARG_WITH(wavpack,
-    AC_HELP_STRING([--without-wavpack],
-        [Don't try to use wavpack]))
-using_wavpack=no
-if test "$with_wavpack" != "no"; then
-    using_wavpack=yes
-    AC_CHECK_HEADER(wavpack/wavpack.h,
-        [AC_CHECK_LIB(wavpack, WavpackGetSampleRate, WAVPACK_LIBS="$WAVPACK_LIBS -lwavpack" ,using_wavpack=no)],
-        using_wavpack=no)
-    if test "$with_wavpack" = "yes" -a "$using_wavpack" = "no"; then
-        AC_MSG_FAILURE([cannot find wavpack])
-    fi
+
+
+dnl Check for OSS
+AC_ARG_WITH(oss, AC_HELP_STRING([--with-oss=dyn], [load oss dynamically]))
+using_oss=$with_oss
+if test "_$with_oss" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load oss dynamically])
+  fi
+elif test "_$with_oss" = _; then
+  using_oss=yes
+elif test "_$with_oss" != _yes -a "_$with_oss" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-oss=$with_oss])
 fi
-if test "$using_wavpack" = yes; then
-   AC_DEFINE(HAVE_WAVPACK, 1, [Define to 1 if you have WavPack.])
+if test _$with_oss != _no; then
+  AC_CHECK_HEADERS(sys/soundcard.h,,
+      [AC_CHECK_HEADERS(machine/soundcard.h,
+	  [AC_CHECK_LIB(ossaudio, _oss_ioctl, OSS_LIBS="$OSS_LIBS -lossaudio")],
+	  enable_oss=no)])
+  if test _$with_oss != _ -a $using_oss = no; then
+    AC_MSG_FAILURE([cannot find oss])
+  fi
 fi
-AM_CONDITIONAL(HAVE_WAVPACK, test x$using_wavpack = xyes)
-AC_SUBST(WAVPACK_LIBS)
+if test "$using_oss" != no; then
+  AC_DEFINE(HAVE_OSS, 1, [Define to 1 if you have oss.])
+  if test "$using_oss" = yes; then
+    AC_DEFINE(STATIC_OSS, 1, [Define to 1 if you have static oss.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_OSS, test $using_oss != no)
+AM_CONDITIONAL(STATIC_OSS, test $using_oss = yes)
+AC_SUBST(OSS_LIBS)
 
-dnl Check for png libraries
-AC_ARG_WITH(png,
-    AC_HELP_STRING([--without-png],
-        [Don't try to use png]))
-using_png=no
-if test "$with_png" != "no"; then
-    using_png=yes
-    AC_CHECK_HEADER(png.h,
-        [AC_CHECK_LIB(png, png_set_rows, PNG_LIBS="$PNG_LIBS -lpng -lz" ,using_png=no, -lz)],
-        using_png=no)
-    if test "$with_png" = "yes" -a "$using_png" = "no"; then
-        AC_MSG_FAILURE([cannot find png])
-    fi
+
+
+dnl Check for Sun audio
+AC_ARG_WITH(sunaudio, AC_HELP_STRING([--with-sunaudio=dyn], [load sunaudio dynamically]))
+using_sunaudio=$with_sunaudio
+if test "_$with_sunaudio" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load sunaudio dynamically])
+  fi
+elif test "_$with_sunaudio" = _; then
+  using_sunaudio=yes
+elif test "_$with_sunaudio" != _yes -a "_$with_sunaudio" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-sunaudio=$with_sunaudio])
 fi
-if test "$using_png" = yes; then
-   AC_DEFINE(HAVE_PNG, 1, [Define to 1 if you have PNG.])
+if test _$with_sunaudio != _no; then
+  AC_CHECK_HEADERS(sys/audioio.h,,
+      [AC_CHECK_HEADERS(sun/audioio.h,, using_sunaudio=no)])
+  if test _$with_sunaudio != _ -a $using_sunaudio = no; then
+    AC_MSG_FAILURE([cannot find sunaudio])
+  fi
 fi
-AM_CONDITIONAL(HAVE_PNG, test x$using_png = xyes)
-AC_SUBST(PNG_LIBS)
+if test "$using_sunaudio" != no; then
+  AC_DEFINE(HAVE_SUN_AUDIO, 1, [Define to 1 if you have sunaudio.])
+  if test "$using_sunaudio" = yes; then
+    AC_DEFINE(STATIC_SUN_AUDIO, 1, [Define to 1 if you have static sunaudio.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_SUN_AUDIO, test $using_sunaudio != no)
+AM_CONDITIONAL(STATIC_SUN_AUDIO, test $using_sunaudio = yes)
+AC_SUBST(SUN_AUDIO_LIBS)
 
-dnl Test for LADSPA
-AC_ARG_WITH(ladspa,
-    AC_HELP_STRING([--without-ladspa], [Don't try to use LADSPA]))
-using_ladspa=no
-if test "$with_ladspa" != "no" -a "$using_libltdl" = "yes"; then
-    using_ladspa=yes
-    AC_CHECK_HEADERS(ladspa.h,, using_ladspa=no)
-    if test "$with_ladspa" = "yes" -a "$using_ladspa" = "no"; then
-        AC_MSG_FAILURE([cannot find ladspa.h])
-    fi
+
+
+dnl MP3 format depends on libmad || LAME
+AC_ARG_WITH(mp3, AC_HELP_STRING([--with-mp3=dyn], [load mp3 dynamically]))
+using_mp3=$with_mp3
+if test "_$with_mp3" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load mp3 dynamically])
+  fi
+elif test "_$with_mp3" = _; then
+  using_mp3=yes
+elif test "_$with_mp3" != _yes -a "_$with_mp3" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-mp3=$with_mp3])
 fi
-LADSPA_PATH=${libdir}/ladspa
-AC_ARG_WITH(ladspa-path,
-    AC_HELP_STRING([--with-ladspa-path], [Default search path for LADSPA plugins]))
-AC_SUBST(LADSPA_PATH)
+if test _$with_mp3 != _no; then
+  if test "$using_mad" != yes -a "$using_lame" != yes; then
+    using_mp3=no
+  fi
+  if test _$with_mp3 != _ -a $using_mp3 = no; then
+    AC_MSG_FAILURE([cannot find mp3])
+  fi
+fi
+if test "$using_mp3" != no; then
+  AC_DEFINE(HAVE_MP3, 1, [Define to 1 if you have mp3.])
+  if test "$using_mp3" = yes; then
+    AC_DEFINE(STATIC_MP3, 1, [Define to 1 if you have static mp3.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_MP3, test $using_mp3 != no)
+AM_CONDITIONAL(STATIC_MP3, test $using_mp3 = yes)
+AC_SUBST(MP3_LIBS)
 
+
+
+dnl Check for libgsm
+found_libgsm=yes
+AC_CHECK_HEADERS(gsm/gsm.h, ,
+    [AC_CHECK_HEADERS(gsm.h, ,found_libgsm=no)])
+    AC_CHECK_LIB(gsm, gsm_create, GSM_LIBS="$GSM_LIBS -lgsm", found_libgsm=no)
+if test "$found_libgsm" = yes; then
+    AC_DEFINE(EXTERNAL_GSM, 1, [Define if you are using an external GSM library])
+else
+    LIBGSM_LIBADD=../libgsm/libgsm.la
+fi
+AM_CONDITIONAL(EXTERNAL_GSM, test x$found_libgsm = xyes)
+AC_SUBST(LIBGSM_LIBADD)
+AC_SUBST(GSM_LIBS)
+
+
+
+dnl GSM format depends on libgsm
+AC_ARG_WITH(gsm, AC_HELP_STRING([--with-gsm=dyn], [load gsm dynamically]))
+using_gsm=$with_gsm
+if test "_$with_gsm" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load gsm dynamically])
+  fi
+elif test "_$with_gsm" = _; then
+  using_gsm=yes
+elif test "_$with_gsm" != _yes -a "_$with_gsm" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-gsm=$with_gsm])
+fi
+# No need to check; GSM is always found
+if test "$using_gsm" != no; then
+  AC_DEFINE(HAVE_GSM, 1, [Define to 1 if you have gsm.])
+  if test "$using_gsm" = yes; then
+    AC_DEFINE(STATIC_GSM, 1, [Define to 1 if you have static gsm.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_GSM, test $using_gsm != no)
+AM_CONDITIONAL(STATIC_GSM, test $using_gsm = yes)
+
+
+
+dnl Check for liblpc10
+found_liblpc10=yes
+AC_CHECK_HEADERS(lpc10.h, ,
+    [AC_CHECK_HEADERS(lpc10.h, ,found_liblpc10=no)])
+    AC_CHECK_LIB(lpc10, create_lpc10_encoder_state, LPC10_LIBS="$LPC10_LIBS -llpc10", found_liblpc10=no)
+if test "$found_liblpc10" = yes; then
+    AC_DEFINE(EXTERNAL_LPC10, 1, [Define if you are using an external LPC10 library])
+else
+    LIBLPC10_LIBADD=../lpc10/liblpc10.la
+fi
+AM_CONDITIONAL(EXTERNAL_LPC10, test x$found_liblpc10 = xyes)
+AC_SUBST(LIBLPC10_LIBADD)
+AC_SUBST(LPC10_LIBS)
+
+
+
+dnl LPC10 format
+AC_ARG_WITH(lpc10, AC_HELP_STRING([--with-lpc10=dyn], [load lpc10 dynamically]))
+using_lpc10=$with_lpc10
+if test "_$with_lpc10" = _dyn; then
+  if test $using_libltdl != yes; then
+    AC_MSG_FAILURE([not using libltdl; cannot load lpc10 dynamically])
+  fi
+elif test "_$with_lpc10" = _; then
+  using_lpc10=yes
+elif test "_$with_lpc10" != _yes -a "_$with_lpc10" != _no; then
+  AC_MSG_FAILURE([invalid selection --with-lpc10=$with_lpc10])
+fi
+# No need to check; LPC10 is always found
+if test "$using_lpc10" != no; then
+  AC_DEFINE(HAVE_LPC10, 1, [Define to 1 if you have lpc10.])
+  if test "$using_lpc10" = yes; then
+    AC_DEFINE(STATIC_LPC10, 1, [Define to 1 if you have static lpc10.])
+  fi
+fi
+AM_CONDITIONAL(HAVE_LPC10, test $using_lpc10 != no)
+AM_CONDITIONAL(STATIC_LPC10, test $using_lpc10 = yes)
+
+
+
+dnl Check if we want to disable all symlinks
+AC_MSG_CHECKING([whether to enable symlinks])
+AC_ARG_ENABLE(symlinks,
+    AC_HELP_STRING([--disable-symlinks], [Don't make any symlinks to sox.]),,enable_symlinks=yes)
+AC_MSG_RESULT($enable_symlinks)
+
+enable_playrec_symlinks=no
+if test "$enable_symlinks" = "yes"; then
+  SYMLINKS=yes
+  if test false \
+      -o "$enable_alsa" = yes \
+      -o "$enable_ao" = yes \
+      -o "$enable_coreaudio" = yes \
+      -o "$enable_oss" = yes \
+      -o "$enable_pulseaudio" = yes \
+      -o "$enable_sndio" = yes \
+    ; then
+    PLAYRECLINKS=yes
+    enable_playrec_symlinks=yes
+  fi
+fi
+AC_SUBST(SYMLINKS)
+AC_SUBST(PLAYRECLINKS)
+
+
+
 dnl Generate output files.
 AX_CREATE_STDINT_H(src/soxstdint.h)
 AC_CONFIG_FILES(Makefile src/Makefile libgsm/Makefile lpc10/Makefile sox.pc)
 AC_OUTPUT
 
-if test "$found_libgsm" = "yes"; then
-   gsm_option="external"
-else
-   gsm_option="in-tree"
+if test "$using_gsm" != "no"; then
+  if test "$found_libgsm" = "yes"; then
+    gsm_option="(external)"
+  else
+    gsm_option="(in-tree)"
+  fi
 fi
 
-if test "$found_liblpc10" = "yes"; then
-   lpc10_option="external"
-else
-   lpc10_option="in-tree"
+if test "$using_lpc10" != "no"; then
+  if test "$found_liblpc10" = "yes"; then
+    lpc10_option="(external)"
+  else
+    lpc10_option="(in-tree)"
+  fi
 fi
 
 if test "$using_pkgconfig" = "no"; then
-    pkgconfig_option="disabled"
+  pkgconfig_option="disabled"
 else
-    pkgconfig_option="$with_pkgconfigdir"
+  pkgconfig_option="$with_pkgconfigdir"
 fi
 
-dnl Report configuration.
+
+
+# Report configuration.
 echo
-echo "Distro name ...................... $DISTRO"
-echo "Debugging build................... $enable_debug"
-echo "External module support........... $using_libltdl"
-echo "GOMP support...................... $enable_gomp"
-echo "ALSA driver....................... $enable_alsa"
-echo "libao driver...................... $enable_libao"
-echo "OSS driver........................ $enable_oss"
-echo "sndio driver...................... $enable_sndio"
-echo "SUN audio driver.................. $enable_sun_audio"
-echo "CoreAudio driver.................. $enable_coreaudio"
-echo "Pulse Audio driver................ $enable_pulseaudio"
-echo "symlinks enabled.................. $enable_symlinks"
-echo "play and rec symlinks............. $enable_playrec_symlinks"
-echo "libgsm............................ $gsm_option"
-echo "liblpc10.......................... $lpc10_option"
-echo "libsndfile formats................ $using_sndfile"
-echo "Ogg Vorbis format................. $using_ogg"
-echo "FLAC format....................... $using_flac"
-echo "ffmpeg formats.................... $using_ffmpeg"
-echo "magic library..................... $using_magic"
-echo "MAD MP3 reader.................... $using_mad"
-echo "id3tag library.................... $using_id3tag"
-echo "LAME MP3 writer................... $using_lame"
-echo "AMR-WB format..................... $using_amr_wb"
-echo "AMR-NB format..................... $using_amr_nb"
-echo "WavPack format.................... $using_wavpack"
-echo "LADSPA effects.................... $using_ladspa"
-echo "PNG support....................... $using_png"
-echo "pkg-config location............... $pkgconfig_option"
+echo "BUILD OPTIONS"
+echo "Debugging build............$enable_debug"
+echo "Distro name ...............$DISTRO"
+echo "Dynamic loading support....$using_libltdl"
+echo "GOMP support...............$enable_gomp"
+echo "Pkg-config location........$pkgconfig_option"
+echo "Play and rec symlinks......$enable_playrec_symlinks"
+echo "Symlinks enabled...........$enable_symlinks"
+echo
+echo "OPTIONAL DEVICE DRIVERS"
+echo "ao (Xiph)..................$using_ao"
+echo "alsa (Linux)...............$using_alsa"
+echo "coreaudio (MAC OS X).......$using_coreaudio"
+echo "sndio (OpenBSD)............$using_sndio"
+echo "oss........................$using_oss"
+echo "pulseaudio.................$using_pulseaudio"
+echo "sunaudio...................$using_sunaudio"
+echo
+echo "OPTIONAL FILE FORMATS"
+echo "amrnb......................$using_amrnb"
+echo "amrwb......................$using_amrwb"
+echo "ffmpeg.....................$using_ffmpeg"
+echo "flac.......................$using_flac"
+echo "gsm........................$using_gsm $gsm_option"
+echo "lpc10......................$using_lpc10 $lpc10_option"
+echo "mp3........................$using_mp3$mp3_option"
+echo " id3tag....................$using_id3tag"
+echo " lame......................$using_lame"
+echo " mad.......................$using_mad"
+echo "oggvorbis..................$using_oggvorbis"
+echo "sndfile....................$using_sndfile"
+echo "wavpack....................$using_wavpack"
+echo
+echo "MISC OPTIONS"
+echo "ladspa effects.............$using_ladspa"
+echo "magic support..............$using_magic"
+echo "png support................$using_png"
 echo
 echo "Configure finished.  Do 'make && make install' to compile and install SoX."
 echo
--- /dev/null
+++ b/m4/optional-fmt.m4
@@ -1,0 +1,37 @@
+dnl $1 package name                  e.g. flac 
+dnl $2 package name in conditionals  e.g. FLAC 
+dnl $3 header name                   e.g. FLAC/all.h 
+dnl $4 check-lib name                e.g. FLAC 
+dnl $5 check-lib fn-name             e.g. FLAC__stream_encoder_new 
+dnl $6 libs1                         e.g. "-lFLAC $FLAC_LIBS $OGG_VORBIS_LIBS"
+dnl $7 libs2                         e.g. "$FLAC_LIBS $OGG_VORBIS_LIBS"
+
+AC_DEFUN([AC_OPTIONAL_FORMAT],
+  [AC_ARG_WITH($1, AC_HELP_STRING([--with-$1=dyn], [load $1 dynamically]))
+  using_$1=$with_$1
+  if test "_$with_$1" = _dyn; then
+    if test $using_libltdl != yes; then
+      AC_MSG_FAILURE([not using libltdl; cannot load $1 dynamically])
+    fi
+  elif test "_$with_$1" = _; then
+    using_$1=yes
+  elif test "_$with_$1" != _yes -a "_$with_$1" != _no; then
+    AC_MSG_FAILURE([invalid selection --with-$1=$with_$1])
+  fi
+  if test _$with_$1 != _no; then
+    AC_CHECK_HEADER($3, [AC_CHECK_LIB($4, $5, $2_LIBS=$6,using_$1=no, $7)], using_$1=no)
+    if test _$with_$1 != _ -a $using_$1 = no; then
+      AC_MSG_FAILURE([cannot find $1])
+    fi
+  fi
+  if test "$using_$1" != no; then
+    AC_DEFINE(HAVE_$2, 1, [Define to 1 if you have $1.])
+    if test "$using_$1" = yes; then
+      AC_DEFINE(STATIC_$2, 1, [Define to 1 if you have static $1.])
+    fi
+  fi
+  AM_CONDITIONAL(HAVE_$2, test $using_$1 != no)
+  AM_CONDITIONAL(STATIC_$2, test $using_$1 = yes)
+  AC_SUBST($2_CFLAGS)
+  AC_SUBST($2_LIBS)]
+)
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -28,16 +28,17 @@
 
 # Format with: !xargs echo|tr ' ' '\n'|sort|column|expand|sed 's/^/  /'
 set(effects_srcs
-  bend            dither          gain            pan             speed
-  biquad          earwax          input           phaser          splice
-  biquads         echo            loudness        rate            stat
-  chorus          echos           mcompand        remix           stretch
-  compand         fade            mixer           repeat          swap
-  compandt        fft4g           noiseprof       reverb          synth
-  contrast        filter          noisered        reverse         tempo
-  dcshift         fir             output          silence         tremolo
-  delay           firfit          overdrive       sinc            trim
-  dft_filter      flanger         pad             skeleff         vol
+  bend            dither          input           rate            stretch
+  biquad          earwax          loudness        remix           swap
+  biquads         echo            mcompand        repeat          synth
+  chorus          echos           mixer           reverb          tempo
+  compand         fade            noiseprof       reverse         tremolo
+  compandt        fft4g           noisered        silence         trim
+  contrast        filter          output          sinc            vol
+  crop            fir             overdrive       skeleff
+  dcshift         firfit          pad             speed
+  delay           flanger         pan             splice
+  dft_filter      gain            phaser          stat
 )
 set(formats_srcs
   8svx            dat             ima-fmt         s3-fmt          u3-fmt
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -23,6 +23,8 @@
 AM_CPPFLAGS += -DDISTRO="\"@DISTRO@\""
 endif
 
+
+
 #########################
 # SoX - the application #
 #########################
@@ -39,125 +41,8 @@
 example2_SOURCES = example2.c
 sox_sample_test_SOURCES = sox_sample_test.c sox_sample_test.h
 
-###############################################
-# libsox - Dynamic Libraries for File Formats #
-###############################################
 
-if HAVE_LIBLTDL
 
-# Format modules; listed first so optional ones can be added later
-pkglib_LTLIBRARIES =
-
-# File formats
-if HAVE_FLAC
-if !STATIC_FLAC
-libsox_fmt_flac_la_SOURCES = flac.c
-libsox_fmt_flac_la_LIBADD = libsox.la @FLAC_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_flac.la
-endif
-endif
-if HAVE_FFMPEG
-libsox_fmt_ffmpeg_la_SOURCES = ffmpeg.c
-libsox_fmt_ffmpeg_la_LIBADD = libsox.la @FFMPEG_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_ffmpeg.la
-endif
-if HAVE_SNDFILE
-libsox_fmt_sndfile_la_SOURCES = sndfile.c
-libsox_fmt_sndfile_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_sndfile_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_caf_la_SOURCES = caf.c sndfile.c
-libsox_fmt_caf_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_caf_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_mat4_la_SOURCES = mat4.c sndfile.c
-libsox_fmt_mat4_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_mat4_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_mat5_la_SOURCES = mat5.c sndfile.c
-libsox_fmt_mat5_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_mat5_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_paf_la_SOURCES = paf.c sndfile.c
-libsox_fmt_paf_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_paf_la_LIBADD = libsox.la  @SNDFILE_LIBS@
-libsox_fmt_fap_la_SOURCES = fap.c sndfile.c
-libsox_fmt_fap_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_fap_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_w64_la_SOURCES = w64.c sndfile.c
-libsox_fmt_w64_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_w64_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_xi_la_SOURCES = xi.c sndfile.c
-libsox_fmt_wi_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_xi_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_pvf_la_SOURCES = pvf.c sndfile.c
-libsox_fmt_pvf_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_pvf_la_LIBADD = libsox.la @SNDFILE_LIBS@
-libsox_fmt_sd2_la_SOURCES = sd2.c sndfile.c
-libsox_fmt_sd2_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
-libsox_fmt_sd2_la_LIBADD = libsox.la @SNDFILE_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_sndfile.la libsox_fmt_caf.la libsox_fmt_mat4.la libsox_fmt_mat5.la libsox_fmt_paf.la libsox_fmt_fap.la libsox_fmt_w64.la libsox_fmt_xi.la libsox_fmt_pvf.la libsox_fmt_sd2.la
-endif
-if HAVE_AMRWB
-libsox_fmt_amr_wb_la_SOURCES = amr-wb.c amr.h amr1.h amr2.h
-libsox_fmt_amr_wb_la_LIBADD = libsox.la @AMR_WB_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_amr_wb.la
-endif
-if HAVE_AMRNB
-libsox_fmt_amr_nb_la_SOURCES = amr-nb.c amr.h amr1.h amr2.h
-libsox_fmt_amr_nb_la_LIBADD = libsox.la @AMR_NB_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_amr_nb.la
-endif
-if HAVE_WAVPACK
-libsox_fmt_wavpack_la_SOURCES = wavpack.c
-libsox_fmt_wavpack_la_LIBADD = libsox.la @WAVPACK_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_wavpack.la
-endif
-if HAVE_MP3
-libsox_fmt_mp3_la_SOURCES = mp3.c mp3-duration.h
-libsox_fmt_mp3_la_LIBADD = libsox.la @MP3_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_mp3.la
-endif
-if HAVE_OGG_VORBIS
-libsox_fmt_vorbis_la_SOURCES = vorbis.c vorbis1.h
-libsox_fmt_vorbis_la_LIBADD = libsox.la @OGG_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_vorbis.la
-endif
-
-# I/O devices
-if HAVE_ALSA
-libsox_fmt_alsa_la_SOURCES = alsa.c
-libsox_fmt_alsa_la_LIBADD = libsox.la @ALSA_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_alsa.la
-endif
-if HAVE_COREAUDIO
-libsox_fmt_coreaudio_la_SOURCES = coreaudio.c
-libsox_fmt_coreaudio_la_LIBADD = libsox.la @COREAUDIO_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_coreaudio.la
-endif
-if HAVE_LIBAO
-libsox_fmt_ao_la_SOURCES = ao.c
-libsox_fmt_ao_la_LIBADD = libsox.la @AO_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_ao.la
-endif
-if HAVE_OSS
-libsox_fmt_oss_la_SOURCES = oss.c
-libsox_fmt_oss_la_LIBADD = libsox.la @OSS_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_oss.la
-endif
-if HAVE_PULSEAUDIO
-libsox_fmt_pulseaudio_la_SOURCES = pulseaudio.c
-libsox_fmt_pulseaudio_la_LIBADD = libsox.la @PULSEAUDIO_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_pulseaudio.la
-endif
-if HAVE_SNDIO
-libsox_fmt_sndio_la_SOURCES = sndio.c
-libsox_fmt_sndio_la_LIBADD = libsox.la @SNDIO_LIBS@
-pkglib_LTLIBRARIES += libsox_fmt_sndio.la
-endif
-if HAVE_SUN_AUDIO
-libsox_fmt_sunau_la_SOURCES = sunaudio.c
-libsox_fmt_sunau_la_LIBADD = libsox.la
-pkglib_LTLIBRARIES += libsox_fmt_sunau.la
-endif
-endif
-
 ######################################################
 # libsox - file format, effects, and utility library #
 ######################################################
@@ -171,7 +56,7 @@
 
 # Effects source
 libsox_la_SOURCES += \
-	band.h bend.c biquad.c biquad.h biquads.c chorus.c compand.c \
+	band.h bend.c biquad.c biquad.h biquads.c chorus.c compand.c crop.c \
 	compandt.c compandt.h contrast.c dcshift.c delay.c dft_filter.c \
 	dft_filter.h dither.c dither_fir.h dither_iir.h earwax.c echo.c \
 	echos.c effects.c effects.h effects_i.c effects_i_dsp.c fade.c fft4g.c \
@@ -192,6 +77,7 @@
 if HAVE_MAGIC
 libsox_la_LIBADD += @MAGIC_LIBS@
 endif
+
 if HAVE_OPENMP
 libsox_la_LIBADD += @GOMP_LIBS@
 endif
@@ -199,110 +85,42 @@
 libsox_la_CFLAGS = @WARN_CFLAGS@
 libsox_la_LDFLAGS = @APP_LDFLAGS@ -version-info @SHLIB_VERSION@
 
+if HAVE_LIBLTDL
+  libsox_la_CFLAGS += $(LTDLINCL) 
+  libsox_la_LDFLAGS += $(LIBLTDL) 
+endif
+
+
+
+#########################
+# libsox - File Formats #
+#########################
+
+# Uncomment for bit-rot detection on linux
+#libsox_la_SOURCES += coreaudio.c sndio.c sunaudio.c
+
 libsox_la_SOURCES += raw-fmt.c s1-fmt.c s2-fmt.c s3-fmt.c \
   s4-fmt.c u1-fmt.c u2-fmt.c u3-fmt.c u4-fmt.c al-fmt.c la-fmt.c ul-fmt.c \
   lu-fmt.c 8svx.c aiff-fmt.c aifc-fmt.c au.c avr.c cdr.c cvsd-fmt.c \
-  dvms-fmt.c dat.c gsm.c hcom.c htk.c lpc10.c maud.c prc.c sf.c smp.c \
+  dvms-fmt.c dat.c hcom.c htk.c maud.c prc.c sf.c smp.c \
   sounder.c soundtool.c sphere.c tx16w.c voc.c vox-fmt.c ima-fmt.c adpcm.c adpcm.h \
   ima_rw.c ima_rw.h wav.c wve.c xa.c nulfile.c f4-fmt.c f8-fmt.c
+
 libsox_la_LIBADD += @GSM_LIBS@ @LIBGSM_LIBADD@
 libsox_la_LIBADD += @LPC10_LIBS@ @LIBLPC10_LIBADD@
 
-# Uncomment for bit-rot detection on linux
-#libsox_la_SOURCES += coreaudio.c sndio.c sunaudio.c
+pkglib_LTLIBRARIES =
 
-if STATIC_FLAC
-    libsox_la_SOURCES += flac.c
-    libsox_la_LIBADD += @FLAC_LIBS@
-    sox_LDADD += @FLAC_LIBS@
-endif
+include optional-fmts.am
 
-if HAVE_LIBLTDL
-  libsox_la_CFLAGS += $(LTDLINCL) 
-  libsox_la_LDFLAGS += $(LIBLTDL) 
-else
-sox_LDADD += @GSM_LIBS@ @LIBGSM_LIBADD@
-sox_LDADD += @LPC10_LIBS@ @LIBLPC10_LIBADD@
 
-if HAVE_FFMPEG
-    libsox_la_SOURCES += ffmpeg.h ffmpeg.c
-    libsox_la_LIBADD += @FFMPEG_LIBS@
-    sox_LDADD += @FFMPEG_LIBS@
-endif
-if HAVE_SNDFILE
-    libsox_la_SOURCES += sndfile.c caf.c mat4.c mat5.c paf.c fap.c w64.c xi.c pvf.c sd2.c
-    libsox_la_CFLAGS += @SNDFILE_CFLAGS@
-    libsox_la_LIBADD += @SNDFILE_LIBS@
-    sox_LDADD += @SNDFILE_LIBS@
-endif
-if HAVE_AMRWB
-    libsox_la_SOURCES += amr-wb.c amr.h amr1.h amr2.h
-    libsox_la_LIBADD += @AMR_WB_LIBS@
-    sox_LDADD += @AMR_WB_LIBS@
-endif
-if HAVE_AMRNB
-    libsox_la_SOURCES += amr-nb.c amr.h amr1.h amr2.h
-    libsox_la_LIBADD += @AMR_NB_LIBS@
-    sox_LDADD += @AMR_NB_LIBS@
-endif
-if HAVE_COREAUDIO
-    libsox_la_SOURCES += coreaudio.c
-    libsox_la_LIBADD += @COREAUDIO_LIBS@
-    sox_LDADD += @COREAUDIO_LIBS@
-endif
-if HAVE_PULSEAUDIO
-    libsox_la_SOURCES += pulseaudio.c
-    libsox_la_LIBADD += @PULSEAUDIO_LIBS@
-    sox_LDADD += @PULSEAUDIO_LIBS@
-endif
-if HAVE_WAVPACK
-    libsox_la_SOURCES += wavpack.c
-    libsox_la_LIBADD += @WAVPACK_LIBS@
-    sox_LDADD += @WAVPACK_LIBS@
-endif
-if HAVE_MP3
-    libsox_la_SOURCES += mp3.c mp3-duration.h
-    libsox_la_LIBADD += @MP3_LIBS@
-    sox_LDADD += @MP3_LIBS@
-endif
-if HAVE_OGG_VORBIS
-    libsox_la_SOURCES += vorbis.c vorbis1.h
-    libsox_la_LIBADD += @OGG_LIBS@
-    sox_LDADD += @OGG_LIBS@
-endif
-if HAVE_ALSA
-    libsox_la_SOURCES += alsa.c
-    libsox_la_LIBADD += @ALSA_LIBS@
-    sox_LDADD += @ALSA_LIBS@
-endif
-if HAVE_LIBAO
-    libsox_la_SOURCES += ao.c
-    libsox_la_LIBADD += @AO_LIBS@
-    sox_LDADD += @AO_LIBS@
-endif
-if HAVE_OSS
-    libsox_la_SOURCES += oss.c
-    libsox_la_LIBADD += @OSS_LIBS@
-    sox_LDADD += @OSS_LIBS@
-endif
-if HAVE_SNDIO
-    libsox_la_SOURCES += sndio.c
-    libsox_la_LIBADD += @SNDIO_LIBS@
-    sox_LDADD += @SNDIO_LIBS@
-endif
-if HAVE_SUN_AUDIO
-    libsox_la_SOURCES += sunaudio.c
-endif
 
-#end !HAVE_LIBLTDL
-endif
-
 # example programs will need same link options as sox does.
 example0_LDADD = ${sox_LDADD}
 example1_LDADD = ${sox_LDADD}
 example2_LDADD = ${sox_LDADD}
 
-EXTRA_DIST = monkey.au monkey.wav \
+EXTRA_DIST = monkey.au monkey.wav optional-fmts.in \
 	     CMakeLists.txt soxstdint.h.cmake soxconfig.h.cmake \
 	     tests.sh testall.sh tests.bat testall.bat test-comments
 
--- a/src/formats.h
+++ b/src/formats.h
@@ -15,6 +15,8 @@
  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
  */
 
+/*-------------------------- Static format handlers --------------------------*/
+
   FORMAT(aifc)
   FORMAT(aiff)
   FORMAT(al)
@@ -27,12 +29,10 @@
   FORMAT(dvms)
   FORMAT(f4)
   FORMAT(f8)
-  FORMAT(gsm)
   FORMAT(hcom)
   FORMAT(htk)
   FORMAT(ima)
   FORMAT(la)
-  FORMAT(lpc10)
   FORMAT(lu)
   FORMAT(maud)
   FORMAT(nul)
@@ -61,37 +61,48 @@
   FORMAT(wve)
   FORMAT(xa)
 
-#if defined HAVE_FLAC && (defined STATIC_FLAC || !defined HAVE_LIBLTDL)
-  FORMAT(flac)
-#endif
+/*--------------------- Plugin or static format handlers ---------------------*/
 
-#ifndef HAVE_LIBLTDL /* Plugin format handlers */
-
-#if defined HAVE_ALSA
+#if defined HAVE_ALSA && (defined STATIC_ALSA || !defined HAVE_LIBLTDL)
   FORMAT(alsa)
 #endif
-#if defined HAVE_AMRNB
+#if defined HAVE_AMRNB && (defined STATIC_AMRNB || !defined HAVE_LIBLTDL)
   FORMAT(amr_nb)
 #endif
-#if defined HAVE_AMRWB
+#if defined HAVE_AMRWB && (defined STATIC_AMRWB || !defined HAVE_LIBLTDL)
   FORMAT(amr_wb)
 #endif
-#if defined HAVE_LIBAO
+#if defined HAVE_AO && (defined STATIC_AO || !defined HAVE_LIBLTDL)
   FORMAT(ao)
 #endif
-#if defined HAVE_FFMPEG
+#if defined HAVE_COREAUDIO && (defined STATIC_COREAUDIO || !defined HAVE_LIBLTDL)
+  FORMAT(coreaudio)
+#endif
+#if defined HAVE_FFMPEG && (defined STATIC_FFMPEG || !defined HAVE_LIBLTDL)
   FORMAT(ffmpeg)
 #endif
-#if defined(HAVE_MP3)
+#if defined HAVE_FLAC && (defined STATIC_FLAC || !defined HAVE_LIBLTDL)
+  FORMAT(flac)
+#endif
+#if defined HAVE_GSM && (defined STATIC_GSM || !defined HAVE_LIBLTDL)
+  FORMAT(gsm)
+#endif
+#if defined HAVE_LPC10 && (defined STATIC_LPC10 || !defined HAVE_LIBLTDL)
+  FORMAT(lpc10)
+#endif
+#if defined HAVE_MP3 && (defined STATIC_MP3 || !defined HAVE_LIBLTDL)
   FORMAT(mp3)
 #endif
-#if defined(HAVE_SYS_SOUNDCARD_H) || defined(HAVE_MACHINE_SOUNDCARD_H)
+#if defined HAVE_OSS && (defined STATIC_OSS || !defined HAVE_LIBLTDL)
   FORMAT(oss)
 #endif
-#if defined HAVE_SNDIO
+#if defined HAVE_PULSEAUDIO && (defined STATIC_PULSEAUDIO || !defined HAVE_LIBLTDL)
+  FORMAT(pulseaudio)
+#endif
+#if defined HAVE_SNDIO && (defined STATIC_SNDIO || !defined HAVE_LIBLTDL)
   FORMAT(sndio)
 #endif
-#if defined HAVE_SNDFILE
+#if defined HAVE_SNDFILE && (defined STATIC_SNDFILE || !defined HAVE_LIBLTDL)
   FORMAT(sndfile)
   #if defined HAVE_SNDFILE_1_0_12
   FORMAT(caf)
@@ -105,17 +116,12 @@
   FORMAT(w64)
   FORMAT(xi)
 #endif
-#if defined(HAVE_SYS_AUDIOIO_H) || defined(HAVE_SUN_AUDIOIO_H)
+#if defined HAVE_SUN_AUDIO && (defined STATIC_SUN_AUDIO || !defined HAVE_LIBLTDL)
   FORMAT(sunau)
 #endif
-#if defined(HAVE_COREAUDIO) || defined(HAVE_COREAUDIO)
-  FORMAT(coreaudio)
-#endif
-#if defined HAVE_OGG_VORBIS
+#if defined HAVE_OGG_VORBIS && (defined STATIC_OGG_VORBIS || !defined HAVE_LIBLTDL)
   FORMAT(vorbis)
 #endif
-#if defined HAVE_WAVPACK
+#if defined HAVE_WAVPACK && (defined STATIC_WAVPACK || !defined HAVE_LIBLTDL)
   FORMAT(wavpack)
-#endif
-
 #endif
--- /dev/null
+++ b/src/optional-fmts.am
@@ -1,0 +1,236 @@
+
+
+if HAVE_ALSA
+if STATIC_ALSA
+  libsox_la_SOURCES += alsa.c
+  libsox_la_LIBADD += @ALSA_LIBS@
+  sox_LDADD += @ALSA_LIBS@
+else
+  libsox_fmt_alsa_la_SOURCES = alsa.c
+  libsox_fmt_alsa_la_LIBADD = libsox.la @ALSA_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_alsa.la
+endif
+endif
+
+if HAVE_AMRNB
+if STATIC_AMRNB
+  libsox_la_SOURCES += amr-nb.c amr.h amr1.h amr2.h
+  libsox_la_LIBADD += @AMRNB_LIBS@
+  sox_LDADD += @AMRNB_LIBS@
+else
+  libsox_fmt_amr_nb_la_SOURCES = amr-nb.c amr.h amr1.h amr2.h
+  libsox_fmt_amr_nb_la_LIBADD = libsox.la @AMRNB_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_amr_nb.la
+endif
+endif
+
+if HAVE_AMRWB
+if STATIC_AMRWB
+  libsox_la_SOURCES += amr-wb.c amr.h amr1.h amr2.h
+  libsox_la_LIBADD += @AMRWB_LIBS@
+  sox_LDADD += @AMRWB_LIBS@
+else
+  libsox_fmt_amr_wb_la_SOURCES = amr-wb.c amr.h amr1.h amr2.h
+  libsox_fmt_amr_wb_la_LIBADD = libsox.la @AMRWB_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_amr_wb.la
+endif
+endif
+
+if HAVE_AO
+if STATIC_AO
+  libsox_la_SOURCES += ao.c
+  libsox_la_LIBADD += @AO_LIBS@
+  sox_LDADD += @AO_LIBS@
+else
+  libsox_fmt_ao_la_SOURCES = ao.c
+  libsox_fmt_ao_la_LIBADD = libsox.la @AO_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_ao.la
+endif
+endif
+
+if HAVE_COREAUDIO
+if STATIC_COREAUDIO
+  libsox_la_SOURCES += coreaudio.c
+  libsox_la_LIBADD += @COREAUDIO_LIBS@
+  sox_LDADD += @COREAUDIO_LIBS@
+else
+  libsox_fmt_coreaudio_la_SOURCES = coreaudio.c
+  libsox_fmt_coreaudio_la_LIBADD = libsox.la @COREAUDIO_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_coreaudio.la
+endif
+endif
+
+if HAVE_FFMPEG
+if STATIC_FFMPEG
+  libsox_la_SOURCES += ffmpeg.c
+  libsox_la_LIBADD += @FFMPEG_LIBS@
+  sox_LDADD += @FFMPEG_LIBS@
+else
+  libsox_fmt_ffmpeg_la_SOURCES = ffmpeg.c
+  libsox_fmt_ffmpeg_la_LIBADD = libsox.la @FFMPEG_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_ffmpeg.la
+endif
+endif
+
+if HAVE_FLAC
+if STATIC_FLAC
+  libsox_la_SOURCES += flac.c
+  libsox_la_LIBADD += @FLAC_LIBS@
+  sox_LDADD += @FLAC_LIBS@
+else
+  libsox_fmt_flac_la_SOURCES = flac.c
+  libsox_fmt_flac_la_LIBADD = libsox.la @FLAC_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_flac.la
+endif
+endif
+
+if HAVE_GSM
+if STATIC_GSM
+  libsox_la_SOURCES += gsm.c
+  libsox_la_LIBADD += @GSM_LIBS@
+  sox_LDADD += @GSM_LIBS@
+else
+  libsox_fmt_gsm_la_SOURCES = gsm.c
+  libsox_fmt_gsm_la_LIBADD = libsox.la @GSM_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_gsm.la
+endif
+endif
+
+if HAVE_LPC10
+if STATIC_LPC10
+  libsox_la_SOURCES += lpc10.c
+  libsox_la_LIBADD += @LPC10_LIBS@
+  sox_LDADD += @LPC10_LIBS@
+else
+  libsox_fmt_lpc10_la_SOURCES = lpc10.c
+  libsox_fmt_lpc10_la_LIBADD = libsox.la @LPC10_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_lpc10.la
+endif
+endif
+
+if HAVE_MP3
+if STATIC_MP3
+  libsox_la_SOURCES += mp3.c mp3-duration.h
+  libsox_la_LIBADD += @MP3_LIBS@
+  sox_LDADD += @MP3_LIBS@
+else
+  libsox_fmt_mp3_la_SOURCES = mp3.c mp3-duration.h
+  libsox_fmt_mp3_la_LIBADD = libsox.la @MP3_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_mp3.la
+endif
+endif
+
+if HAVE_OSS
+if STATIC_OSS
+  libsox_la_SOURCES += oss.c
+  libsox_la_LIBADD += @OSS_LIBS@
+  sox_LDADD += @OSS_LIBS@
+else
+  libsox_fmt_oss_la_SOURCES = oss.c
+  libsox_fmt_oss_la_LIBADD = libsox.la @OSS_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_oss.la
+endif
+endif
+
+if HAVE_PULSEAUDIO
+if STATIC_PULSEAUDIO
+  libsox_la_SOURCES += pulseaudio.c
+  libsox_la_LIBADD += @PULSEAUDIO_LIBS@
+  sox_LDADD += @PULSEAUDIO_LIBS@
+else
+  libsox_fmt_pulseaudio_la_SOURCES = pulseaudio.c
+  libsox_fmt_pulseaudio_la_LIBADD = libsox.la @PULSEAUDIO_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_pulseaudio.la
+endif
+endif
+
+if HAVE_SNDIO
+if STATIC_SNDIO
+  libsox_la_SOURCES += sndio.c
+  libsox_la_LIBADD += @SNDIO_LIBS@
+  sox_LDADD += @SNDIO_LIBS@
+else
+  libsox_fmt_sndio_la_SOURCES = sndio.c
+  libsox_fmt_sndio_la_LIBADD = libsox.la @SNDIO_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_sndio.la
+endif
+endif
+
+if HAVE_SUN_AUDIO
+if STATIC_SUN_AUDIO
+  libsox_la_SOURCES += sunaudio.c
+  libsox_la_LIBADD += @SUN_AUDIO_LIBS@
+  sox_LDADD += @SUN_AUDIO_LIBS@
+else
+  libsox_fmt_sunau_la_SOURCES = sunaudio.c
+  libsox_fmt_sunau_la_LIBADD = libsox.la @SUN_AUDIO_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_sunau.la
+endif
+endif
+
+if HAVE_OGG_VORBIS
+if STATIC_OGG_VORBIS
+  libsox_la_SOURCES += vorbis.c vorbis1.h
+  libsox_la_LIBADD += @OGG_VORBIS_LIBS@
+  sox_LDADD += @OGG_VORBIS_LIBS@
+else
+  libsox_fmt_vorbis_la_SOURCES = vorbis.c vorbis1.h
+  libsox_fmt_vorbis_la_LIBADD = libsox.la @OGG_VORBIS_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_vorbis.la
+endif
+endif
+
+if HAVE_WAVPACK
+if STATIC_WAVPACK
+  libsox_la_SOURCES += wavpack.c
+  libsox_la_LIBADD += @WAVPACK_LIBS@
+  sox_LDADD += @WAVPACK_LIBS@
+else
+  libsox_fmt_wavpack_la_SOURCES = wavpack.c
+  libsox_fmt_wavpack_la_LIBADD = libsox.la @WAVPACK_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_wavpack.la
+endif
+endif
+
+
+if HAVE_SNDFILE
+if STATIC_SNDFILE
+  libsox_la_SOURCES += sndfile.c caf.c mat4.c mat5.c paf.c fap.c w64.c xi.c pvf.c sd2.c
+  libsox_la_CFLAGS += @SNDFILE_CFLAGS@
+  libsox_la_LIBADD += @SNDFILE_LIBS@
+  sox_LDADD += @SNDFILE_LIBS@
+else
+libsox_fmt_sndfile_la_SOURCES = sndfile.c
+libsox_fmt_sndfile_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_sndfile_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_caf_la_SOURCES = caf.c sndfile.c
+libsox_fmt_caf_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_caf_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_mat4_la_SOURCES = mat4.c sndfile.c
+libsox_fmt_mat4_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_mat4_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_mat5_la_SOURCES = mat5.c sndfile.c
+libsox_fmt_mat5_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_mat5_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_paf_la_SOURCES = paf.c sndfile.c
+libsox_fmt_paf_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_paf_la_LIBADD = libsox.la  @SNDFILE_LIBS@
+libsox_fmt_fap_la_SOURCES = fap.c sndfile.c
+libsox_fmt_fap_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_fap_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_w64_la_SOURCES = w64.c sndfile.c
+libsox_fmt_w64_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_w64_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_xi_la_SOURCES = xi.c sndfile.c
+libsox_fmt_wi_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_xi_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_pvf_la_SOURCES = pvf.c sndfile.c
+libsox_fmt_pvf_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_pvf_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_sd2_la_SOURCES = sd2.c sndfile.c
+libsox_fmt_sd2_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_sd2_la_LIBADD = libsox.la @SNDFILE_LIBS@
+pkglib_LTLIBRARIES += libsox_fmt_sndfile.la libsox_fmt_caf.la libsox_fmt_mat4.la libsox_fmt_mat5.la libsox_fmt_paf.la libsox_fmt_fap.la libsox_fmt_w64.la libsox_fmt_xi.la libsox_fmt_pvf.la libsox_fmt_sd2.la
+endif
+endif
+
--- /dev/null
+++ b/src/optional-fmts.in
@@ -1,0 +1,72 @@
+define(`OPT_FORMAT',
+if HAVE_$2
+if STATIC_$2
+  libsox_la_SOURCES += $3
+  libsox_la_LIBADD += @$2_LIBS@
+  sox_LDADD += @$2_LIBS@
+else
+  libsox_fmt_$1_la_SOURCES = $3
+  libsox_fmt_$1_la_LIBADD = libsox.la @$2_LIBS@
+  pkglib_LTLIBRARIES += libsox_fmt_$1.la
+endif
+endif
+)
+
+OPT_FORMAT(alsa, ALSA, alsa.c)
+OPT_FORMAT(amr_nb, AMRNB, amr-nb.c amr.h amr1.h amr2.h)
+OPT_FORMAT(amr_wb, AMRWB, amr-wb.c amr.h amr1.h amr2.h)
+OPT_FORMAT(ao, AO, ao.c)
+OPT_FORMAT(coreaudio, COREAUDIO, coreaudio.c)
+OPT_FORMAT(ffmpeg, FFMPEG, ffmpeg.c)
+OPT_FORMAT(flac, FLAC, flac.c)
+OPT_FORMAT(gsm, GSM, gsm.c)
+OPT_FORMAT(lpc10, LPC10, lpc10.c)
+OPT_FORMAT(mp3, MP3, mp3.c mp3-duration.h)
+OPT_FORMAT(oss, OSS, oss.c)
+OPT_FORMAT(pulseaudio, PULSEAUDIO, pulseaudio.c)
+OPT_FORMAT(sndio, SNDIO, sndio.c)
+OPT_FORMAT(sunau, SUN_AUDIO, sunaudio.c)
+OPT_FORMAT(vorbis, OGG_VORBIS, vorbis.c vorbis1.h)
+OPT_FORMAT(wavpack, WAVPACK, wavpack.c)
+
+if HAVE_SNDFILE
+if STATIC_SNDFILE
+  libsox_la_SOURCES += sndfile.c caf.c mat4.c mat5.c paf.c fap.c w64.c xi.c pvf.c sd2.c
+  libsox_la_CFLAGS += @SNDFILE_CFLAGS@
+  libsox_la_LIBADD += @SNDFILE_LIBS@
+  sox_LDADD += @SNDFILE_LIBS@
+else
+libsox_fmt_sndfile_la_SOURCES = sndfile.c
+libsox_fmt_sndfile_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_sndfile_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_caf_la_SOURCES = caf.c sndfile.c
+libsox_fmt_caf_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_caf_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_mat4_la_SOURCES = mat4.c sndfile.c
+libsox_fmt_mat4_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_mat4_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_mat5_la_SOURCES = mat5.c sndfile.c
+libsox_fmt_mat5_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_mat5_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_paf_la_SOURCES = paf.c sndfile.c
+libsox_fmt_paf_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_paf_la_LIBADD = libsox.la  @SNDFILE_LIBS@
+libsox_fmt_fap_la_SOURCES = fap.c sndfile.c
+libsox_fmt_fap_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_fap_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_w64_la_SOURCES = w64.c sndfile.c
+libsox_fmt_w64_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_w64_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_xi_la_SOURCES = xi.c sndfile.c
+libsox_fmt_wi_la_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_xi_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_pvf_la_SOURCES = pvf.c sndfile.c
+libsox_fmt_pvf_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_pvf_la_LIBADD = libsox.la @SNDFILE_LIBS@
+libsox_fmt_sd2_la_SOURCES = sd2.c sndfile.c
+libsox_fmt_sd2_CFLAGS = @WARN_CFLAGS@ @SNDFILE_CFLAGS@
+libsox_fmt_sd2_la_LIBADD = libsox.la @SNDFILE_LIBS@
+pkglib_LTLIBRARIES += libsox_fmt_sndfile.la libsox_fmt_caf.la libsox_fmt_mat4.la libsox_fmt_mat5.la libsox_fmt_paf.la libsox_fmt_fap.la libsox_fmt_w64.la libsox_fmt_xi.la libsox_fmt_pvf.la libsox_fmt_sd2.la
+endif
+endif
+
--- a/src/soxconfig.h.cmake
+++ b/src/soxconfig.h.cmake
@@ -1,9 +1,11 @@
 #define PACKAGE_VERSION "14.3.0alpha"
 
 #cmakedefine EXTERNAL_GSM             1
+#cmakedefine EXTERNAL_LPC10           1
 #cmakedefine HAVE_ALSA                1
 #cmakedefine HAVE_AMRNB               1
 #cmakedefine HAVE_AMRWB               1
+#cmakedefine HAVE_AO                  1
 #cmakedefine HAVE_BYTESWAP_H          1
 #cmakedefine HAVE_COREAUDIO           1
 #cmakedefine HAVE_FFMPEG              1
@@ -10,31 +12,35 @@
 #cmakedefine HAVE_FLAC                1
 #cmakedefine HAVE_FSEEKO              1
 #cmakedefine HAVE_GETTIMEOFDAY        1
+#cmakedefine HAVE_GLOB_H              1
+#define HAVE_GSM                      1
 #cmakedefine HAVE_ID3TAG              1
 #cmakedefine HAVE_INTTYPES_H          1
-#cmakedefine HAVE_GLOB_H              1
 #cmakedefine HAVE_IO_H                1
 #cmakedefine HAVE_LAME_LAME_H         1
-#cmakedefine HAVE_LIBAO               1
+#define HAVE_LPC10                    1
 #cmakedefine HAVE_LTDL_H              1
 #cmakedefine HAVE_MACHINE_SOUNDCARD_H 1
 #cmakedefine HAVE_MAD_H               1
-#cmakedefine HAVE_MP3                 1
 #cmakedefine HAVE_MAGIC               1
 #cmakedefine HAVE_MKSTEMP             1
+#cmakedefine HAVE_MP3                 1
 #cmakedefine HAVE_OGG_SPEEX           1
 #cmakedefine HAVE_OGG_VORBIS          1
 #cmakedefine HAVE_OPENMP              1
-#cmakedefine HAVE_POPEN               1
+#cmakedefine HAVE_OSS                 1
 #cmakedefine HAVE_PNG                 1
-#cmakedefine HAVE_SNDFILE_1_0_12      1
+#cmakedefine HAVE_POPEN               1
+#cmakedefine HAVE_PULSEAUDIO          1
 #cmakedefine HAVE_SNDFILE             1
+#cmakedefine HAVE_SNDFILE_1_0_12      1
 #cmakedefine HAVE_SNDIO               1
 #cmakedefine HAVE_STDINT_H            1
 #cmakedefine HAVE_STRCASECMP          1
-#cmakedefine HAVE_STRINGS_H           1
 #cmakedefine HAVE_STRING_H            1
+#cmakedefine HAVE_STRINGS_H           1
 #cmakedefine HAVE_STRRSTR             1
+#cmakedefine HAVE_SUN_AUDIO           1
 #cmakedefine HAVE_SUN_AUDIOIO_H       1
 #cmakedefine HAVE_SYS_AUDIOIO_H       1
 #cmakedefine HAVE_SYS_SOUNDCARD_H     1
--- a/src/sys/audioio.h
+++ b/src/sys/audioio.h
@@ -1,4 +1,4 @@
-#ifndef HAVE_SYS_AUDIOIO_H
+#ifndef HAVE_SUN_AUDIO
 /*
  * SoX bit-rot detection file, obtained from: Solaris 9 /usr/include/sys
  */