dnl TiMidity++ -- MIDI to WAVE converter and player
dnl Copyright (C) 1999-2002 Masanao Izumo <mo@goice.co.jp>
dnl Copyright (C) 1995 Tuukka Toivonen <tt@cgs.fi>
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2 of the License, or
dnl (at your option) any later version.
dnl
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details.
dnl
dnl You should have received a copy of the GNU General Public License
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

dnl configure.in created from configure.scan
dnl by URABE, Shyouhei <root@mput.dip.jp> on 2002.07.06

dnl variable note:
dnl CFLAGS	- Flags for compile.
dnl CPPFLAGS	- Flags for cpp
dnl LDFLAGS	- Flags for linker
dnl		ac_cpp:	    $CPP $CPPFLAGS
dnl		ac_compile: ${CC-cc} -c $CFLAGS $CPPFLAGS
dnl		ac_link:    ${CC-cc} -o * $CFLAGS $CPPFLAGS $LDFLAGS *.c $LIBS
dnl EXTRACFLAGS - Extra flags to compile.  Adds to CFLAGS.
dnl EXTRADEFS	- Extra define macros.	Adds to CPPFLAGS.
dnl EXTRALIBS	- Extra libraries  Adds to LIBS.
dnl SYSEXTRAS	- Additional source codes to compile.
dnl lib_*_opt	- Optional libraries. Adds to LIBS.
dnl LIBRARY_PATH
dnl		- add to -L LDFLAGS
dnl C_INCLUDE_PATH
dnl		- add to -I CPPFLAGS
dnl MSYS	- `yes' if cygnus or Mingw windows environment.
dnl TCLSH	- tclsh
dnl LN_S	- ln -s
dnl tcltk_dep	- make dependencies for tcl/tk interface
dnl
dnl so		- File extension of shared object library.
dnl SHLD	- Linker to make shared object library.
dnl SHLDFLAGS	- Link flags to link shared object library.
dnl SHCFLAGS	- Additional flags to compile shared object library.
dnl		  (such as -fPIC)

# This is a autoscan-generated configure.scan.
# AC_PREREQ([2.71])

AC_INIT([TiMidity++],[2.15.0],[timidity-talk@lists.sourceforge.net],[TiMidity++])
AC_CONFIG_AUX_DIR([autoconf])
AC_CANONICAL_TARGET
AM_INIT_AUTOMAKE([gnu dist-bzip2])
AC_CONFIG_SRCDIR([timidity/timidity.c])
AC_CONFIG_HEADERS([config.h interface.h])
AM_MAINTAINER_MODE

SHELL=${CONFIG_SHELL-"/bin/sh"}
TCLSH=${TCLSH-"tclsh"}

dnl to use contains() macro (see autoconf/acinclude.m4)
CONTAINS_INIT

# Check for compiler options -- such as debug flags.

dnl "--enable-debug" turnes -g on.
AC_MSG_CHECKING(if --enable-debug option specified)
AC_ARG_ENABLE(debug,
	      AS_HELP_STRING([--enable-debug], [Build a debugging version.]),
	      [timidity_cv_debug="yes"], [timidity_cv_debug="no"])
AS_IF([test "x$timidity_cv_debug" = "xyes"],[
  AC_DEFINE(DEBUG,1,Define to 1 if you are in debug mode)
  CFLAGS=${CFLAGS-"-g"}
])
AS_IF([test "x$timidity_cv_debug" = "xno"],[
  AC_DEFINE(NDEBUG,1,Define to 1 if you are NOT in debug mode)
])
AC_MSG_RESULT($timidity_cv_debug)

AS_IF([test "x$CFLAGS" = "x"],[
  NOCFLAGS="yes"
])

dnl --with-x turns on if `--with-x' is NOT specified.
AS_IF([test "x$with_x" = x], [
  with_x=yes
],[
  x_config_flag=yes
])

# Checking gcc environment
for i in `echo $LIBRARY_PATH|sed -e 's,:, ,g'`; do
  LDFLAGS="$LDFLAGS -L${i}"
done
for i in `echo $C_INCLUDE_PATH|sed -e 's,:, ,g'`; do
  CPPFLAGS="$CPPFLAGS -I${i}"
done

# add $prefix if specified.
AS_IF([test "x$prefix" != xNONE -a "x$prefix" != "x$ac_default_prefix" -a "x$prefix" != "x/usr"],[
  LDFLAGS="-L$prefix/lib $LDFLAGS"
  SHLDFLAGS="-L$prefix/lib $SHLDFLAGS"
  CPPFLAGS="-I$prefix/include $CPPFLAGS"
])

dnl add --with-includes, --with-libraries
AC_ARG_WITH(includes,
  AS_HELP_STRING([--with-includes=DIR], [Specify include directories (colon separated)]),
  [ j=' '
    for i in `echo "$withval"|sed -e 's,:, ,g'`; do
      j="${j}-I${i} "
    done
    CPPFLAGS="$j$CPPFLAGS"
  ])

AC_ARG_WITH(libraries,
  AS_HELP_STRING([--with-libraries=DIR], [Specify library directories (colon separated)]),
  [ j=' '
    for i in `echo "$withval"|sed -e 's,:, ,g'`; do
      j="${j}-L${i} "
    done
    LDFLAGS="$j$LDFLAGS"
  ])


dnl a bit hairly yet.(20020718:mput)
dnl CPPFLAGS="$CPPFLAGS \$(DEF_PKGDATADIR) \$(DEF_PKGLIBDIR) \$(DEF_DEFAULT_PATH)"
AC_ARG_WITH(default-path,
  AS_HELP_STRING([--with-default-path=DIR], [Where timidity.cfg is  (PREFIX/share/timidity)]),
  [pkgdatadir=$withval],
  [
   AS_IF([test "x$prefix" != "xNONE"], [
      pkgdatadir='${prefix}/share/timidity'
   ], [
      pkgdatadir='/usr/local/share/timidity'
   ])
  ])
tmpdefpath="`eval \"echo ${pkgdatadir}\"`"
AC_DEFINE_UNQUOTED(DEFAULT_PATH,"$tmpdefpath",place to install patches)
AC_DEFINE(PKGDATADIR,DEFAULT_PATH,a compatibility matter. ignore it.)

AC_ARG_WITH(module-dir,
  AS_HELP_STRING([--with-module-dir=DIR], [Where to install interfaces (PREFIX/lib/timidity)]),
  [pkglibdir=$withval],
  [
   AS_IF([test "x$prefix" != "xNONE"],[
      pkglibdir='${prefix}/lib/timidity'
   ], [
      pkglibdir='/usr/local/lib/timidity'
   ])
  ])
tmplibdir="`eval \"echo ${pkglibdir}\"`"
AC_DEFINE_UNQUOTED(PKGLIBDIR,"$tmplibdir",place to install modules)

AC_ARG_WITH(xaw-resource-prefix,
  AS_HELP_STRING([--with-xaw-resource-prefix=DIR], [What prefix to install X resource files to (optional, used by Xaw/Motif interfaces)]),
  [xawresdir=$withval], [])
AM_CONDITIONAL(XAW_INSTALL_RESOURCE_FILES, test "x$xawresdir" != "x")
AC_SUBST(xawresdir)

# Checks for programs.
AM_PATH_LISPDIR
AC_PROG_CC
AC_PROG_GCC_TRADITIONAL
AC_PROG_INSTALL
AC_PROG_AWK
AC_PROG_RANLIB
AC_PROG_LN_S
CHECK_COMPILER_OPTION(rdynamic)

AS_IF([test "x$NOCFLAGS" = "xyes"], [
  AS_IF([test "x$GCC" = "xyes"], [
    CFLAGS="-O2"
  ], [
    CFLAGS=""
  ])
])

# Checks for target dependencies

AC_ARG_WITH(elf,
  AS_HELP_STRING([--with-elf], [create ELF shared object instead of AOUT]),
  [ ELFFORMAT=$withval ], [ ELFFORMAT="yes" ])

# AC_ARG_WITH(simd,
#  AS_HELP_STRING([--with-simd], [create SIMD friendly binary (default is no) ]),
#  [ SIMD=$withval ], [ SIMD="no" ])

case "$target" in
  *-*-hpux*)
    EXTRADEFS="-DHPUX"
    AS_IF([! test -n "$SHLD" ], [ SHLD="ld -b" ])
    so="sl"
    ;;
  *-sgi-irix*)
    dnl IRIX cc needs -signed option
    case ".$CC" in .cc*) EXTRACFLAGS="-signed";; esac
    AS_IF([! test -n "$SHLD" ], [ SHLD="cc -shared -all" ])
    so="so"
    ;;
  *-*-netbsd*)
    AS_IF([! test -n "$SHLD" ], [ SHLD="$CC -shared -nostartfiles" ])
    so="so"
    ;;

  *-*-freebsd2*)
    dnl EXTRALIBS="$EXTRALIBS -lxpg4"
    AS_IF([! test -n "$SHLD" ], [ SHLD="ld -Bshareable" ])
    so="so"
    ;;
  *-*-freebsd*)
    AS_IF([test "$ELFFORMAT" = yes],[
	AS_IF([! test -n "$SHLD" ], [ SHLD="ld -Bshareable" ])
    ], [
	SHCFLAGS=-aou
	SHLDFLAGS="-L/usr/X11R6/lib/aout $SHLDFLAGS"
	AS_IF([! test -n "$SHLD" ], [ SHLD="env OBJFORMAT=aout ld -shared" ])
    ])
    dnl EXTRALIBS="$EXTRALIBS -lxpg4"
    so="so"
    ;;

#  *-*-freebsd*)
#    EXTRALIBS="$EXTRALIBS -lxpg4"
#    test -n "$SHLD" || SHLD="ld -Bshareable"
#    so="so"
#  ;;

  *-*-cygwin*|*-*-mingw*)
    EXTRADEFS="-D__W32__"
    # ??
    case "x${CC} " in
      "xbcc32 "*|xbcc32)
#        test -n "$SHLD" || SHLD="tlink32 -Tpd"
        AS_IF([! test -n "$SHLD" ], [ SHLD="BCC32 -WD" ])
        BORLANDC=yes
        BORLANDC_LDFLAGS="kernel32.lib winspool.lib comdlg32.lib advapi32.lib oleaut32.lib uuid.lib odbc32.lib ws2_32.lib user32.lib shell32.lib cw32mt.lib"
        BORLANDC_START='C0X32.OBJ'
        CFLAGS="$CFLAGS  -tWM -VM"
        EXTRADEFS="$EXTRADEFS -D_WINDOWS -DWIN32"
        ;;
      "xcc "*|xcc)
        AS_IF([! test -n "$SHLD" ], [ SHLD="polink -DLL" ])
        POCC=yes
         case " $CFLAGS " in
           *" -MT "*)  NODEF="-nodefaultlib:pocrt.lib -nodefaultlib:crt.lib -defaultlib:crtmt.lib"  ;;
           *" -MD "*)  NODEF="-nodefaultlib:crtmt.lib -nodefaultlib:crt.lib -defaultlib:pocrt.lib"  ;;
           *) CFLAGS="$CFLAGS -MT"; NODEF="-nodefaultlib:pocrt.lib -nodefaultlib:crtmt.lib -defaultlib:crt.lib" ;;
         esac
        POCC_LDFLAGS="$NODEF winmm.lib ws2_32.lib user32.lib kernel32.lib shell32.lib gdi32.lib comctl32.lib comdlg32.lib ole32.lib advapi32.lib oldnames.lib"
        CFLAGS="$CFLAGS -Ze -D__POCC__OLDNAMES"
        EXTRADEFS="$EXTRADEFS -D_WINDOWS -DWIN32"
        ;;
      "xdmc "*|xdmc)
        AS_IF([! test -n "$SHLD" ], [ SHLD="dmc -WD" ])
        DMC=yes
        DMC_LDFLAGS="winmm.lib ws2_32.lib user32.lib kernel32.lib shell32.lib gdi32.lib comctl32.lib comdlg32.lib ole32.lib advapi32.lib"
        CFLAGS="$CFLAGS  -mn -j0"
        DLLFLAG=" "
        EXTRADEFS="$EXTRADEFS -D_WINDOWS -DWIN32"
        ;;
      "xwcc386_w.sh "*|xwcc386)
         WATCOM_C=yes
         CFLAGS="$CFLAGS -br -bm -5s -zk0 -zp=16 -w=4 -D_WINDOWS -DWIN32 -DINCLUDE_WINDOWS_H"
         DLLFLAG=" "
         WATCOM_LDFLAGS=
         EXTRALIBS="$EXTRALIBS kernel32.lib winspool.lib comdlg32.lib advapi32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ws2_32.lib user32.lib shell32.lib"
         ;;
      "xcl "*|xcl)
         AS_IF([! test -n "$SHLD" ], [ SHLD="link -dll" ])
         VCPP=yes
         case " $CFLAGS " in
           *" -MT "*)  NODEF="-nodefaultlib:msvcrt.lib -nodefaultlib:msvcrtd.lib -nodefaultlib:libcmtd.lib -nodefaultlib:libc.lib -nodefaultlib:libcd.lib"  ;;
           *" -MD "*)  NODEF="-nodefaultlib:libcmt.lib -nodefaultlib:libcmtd.lib -nodefaultlib:msvcrtd.lib -nodefaultlib:libc.lib -nodefaultlib:libcd.lib"  ;;
           *" -MTd "*) NODEF="-nodefaultlib:msvcrt.lib -nodefaultlib:msvcrtd.lib -nodefaultlib:libcmt.lib -nodefaultlib:libc.lib -nodefaultlib:libcd.lib"  ;;
           *" -MDd "*) NODEF="-nodefaultlib:libcmt.lib -nodefaultlib:libcmtd.lib -nodefaultlib:msvcrt.lib -nodefaultlib:libc.lib -nodefaultlib:libcd.lib"  ;;
           *) CFLAGS="$CFLAGS -MT"; NODEF="-nodefaultlib:msvcrt.lib -nodefaultlib:msvcrtd.lib -nodefaultlib:libcmtd.lib -nodefaultlib:libc.lib -nodefaultlib:libcd.lib"  ;;
         esac
         VCPP_LDFLAGS="-nologo -incremental:no  $NODEF kernel32.lib winspool.lib comdlg32.lib advapi32.lib oleaut32.lib uuid.lib  ws2_32.lib user32.lib shell32.lib"
         CFLAGS="$CFLAGS -nologo -Zp16 -W3 -GX  -Ob2"
         EXTRADEFS="$EXTRADEFS -DNDEBUG -D_WINDOWS -DWIN32 -DMBCS -D_MT -YX  -FD -c"
         ;;
      x*gcc*)
         AS_IF([! test -n "$SHLD" ], [ SHLD="gcc -mdll" ]);
         MINGWGCC=yes
         ;;
      *)
         AS_IF([! test -n "$SHLD" ], [ SHLD="unknown" ])
         ;;
    esac
    so="dll"
    MSYS=yes
    lib_user32_test=-luser32
    ;;
  *-dec-*)
    EXTRADEFS="-DDEC"
    AS_IF([! test -n "$SHLD" ], [ SHLD="ld -Bdynamic -G" ])
    so="so"
    ;;
  *-*-solaris*)
    EXTRADEFS="-DSOLARIS"
    AS_IF([! test -n "$SHLD" ], [ SHLD="/usr/ccs/bin/ld -G" ])
    so="so"
    ;;
  *-*-nextstep*)
    AS_IF([! test -n "$SHLD" ], [ SHLD="/usr/ccs/bin/ld -G" ])
    so="so"
    ;;
  *-*-darwin*)
    AS_IF([test "x$SIMD" = "xyes"],[
       AC_DEFINE(USE_ALTIVEC,1,Define to 1 if you use altivec)
       # EXTRACFLAGS="$EXTRACFLAGS -faltivec -mabi=altivec -maltivec" # for GCC3.
       EXTRACFLAGS="$EXTRACFLAGS -faltivec"
    ],[
       AC_DEFINE(USE_ALTIVEC,0,Define to 1 if you use altivec)
    ])
    CPPFLAGS="$CPPFLAGS -no-cpp-precomp"
    LDOPTS="-dynamic -undefined suppress -flat_namespace $LDOPTS"
    AS_IF([! test -n "$SHLD" ], [ SHLD="$CC -dynamic -bundle -undefined suppress -flat_namespace $LDFLAGS" ])
    so="bundle"
    ;;
  *)
    AS_IF([! test -n "$SHLD"],[
      AS_IF([test "x$GCC" = xyes],[
	SHLD="$CC -shared"
      ],[
	SHLD="ld -Bdynamic -G"
      ])
    ])
    so="so"
    ;;
esac

dnl For .exe
dnl AC_EXEEX # obsolate

# Checks for libraries.
AC_CHECK_LIB(m,sqrt)
AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(dl,dlopen,lib_dl_opt=-ldl)
AC_CHECK_LIB(objc,NSLinkModule,lib_dl_opt=-lobjc) # Mac OS X need this.
AS_IF([test "x$VCPP" != "xyes" && test "x$BORLANDC" != "xyes" && test "x$WATCOM_C" != "xyes" && test "x$POCC" != "xyes"],[
  AC_CHECK_LIB(xpg4,setlocale) # Mac OS X (and maybe NetBSD) need this.
])
AC_CHECK_FUNCS(gethostbyname,,[ AC_CHECK_LIB(nsl,gethostbyname) ])
AC_PATH_XTRA

dnl Xft for trace window
AC_ARG_ENABLE(xft,
  AS_HELP_STRING([--enable-xft], [Enable use of Xft in X trace mode]))

AC_ARG_WITH(xawlib,
  [  --with-xawlib=lib     Try to link to these xaw widget libraries by the
                           order specified by the comma separated value list:
                             xaw: libXaw
                             xaw3d: Xaw3d
                             neXtaw: neXtaw
                             XawPlus: XawPlus
                             default is --with-xawlib=xaw3d,xaw],
  [ with_xawlib="$withval" ], [ with_xawlib="xaw3d,xaw" ])

# Checks for X
AS_IF([test "x$with_x" = xyes], [
  AS_IF([test "x$have_x" = xno], [
    AS_IF([test "x$x_config_flag" = xyes], [
      AC_MSG_ERROR(Could not configure X)
    ], [
      AC_MSG_WARN(Could not configure X)
    ])
  ])
])
AS_IF([test "x$with_x" = xyes -a "x$have_x" = xyes], [
  AS_IF([test "x$x_libraries" != x], [
    ldflags_x_opt="-L$x_libraries"
    LDFLAGS="$LDFLAGS $ldflags_x_opt"
    SHLDFLAGS="$SHLDFLAGS $ldflags_x_opt"
  ], [
    ldflags_x_opt=
  ])
  AS_IF([test "x$x_includes" != x], [
    CPPFLAGS="$CPPFLAGS -I$x_includes"
  ])

  AC_CHECK_LIB(X11,XOpenDisplay,
  AC_DEFINE(HAVE_LIBX11,1,Define to 1 if you have the ``X11'' library (-lX11).))
  AC_MSG_CHECKING(X11 version 6)
  AC_CACHE_VAL(timidity_cv_x11_version_6,
    AC_LINK_IFELSE([AC_LANG_PROGRAM(
     [[#include <X11/Xlib.h>]],
     [[
#if XlibSpecificationRelease < 6
fail;
#endif
     ]])],[timidity_cv_x11_version_6=yes],[timidity_cv_x11_version_6=no]))
  AS_IF([test "$timidity_cv_x11_version_6" = "yes"], [
    AC_MSG_RESULT(6 or newer)
    dnl AC_DEFINE(HAVE_X11R6)
  ], [
    AC_MSG_RESULT(before 6)
  ])

  dnl checking order required
  KEEPLIBS=$LIBS
  AC_CHECK_LIB(Xext,XShapeCombineMask,have_xext=yes; LIBS="-lXext $LIBS",have_xext=no)
  AC_CHECK_LIB(ICE,IceConnectionNumber)
  AC_CHECK_LIB(SM,SmcOpenConnection,have_xprelibs=yes; LIBS="-lSM $LIBS",have_xprelibs=no)
  AC_CHECK_LIB(Xt,XtVaAppInitialize,have_xt=yes; LIBS="-lXt $LIBS",have_xt=no)
  AC_CHECK_LIB(Xmu,XmuInternAtom,LIBS="-lXmu $LIBS")
  AC_CHECK_FUNCS(XmuRegisterExternalAgent)
  AS_IF([test "x$enable_xft" = "xyes"], [
    AC_CHECK_LIB(Xft,XftInit,
                 AC_DEFINE(HAVE_LIBXFT,1,Define to 1 if you have the ``Xft'' library.),
                 enable_xft=no)
  ])
  for i in `echo $with_xawlib | sed 's/,/ /g'`; do
    case "$i" in
    "xaw")
      AC_CHECK_LIB(Xaw,XawInitializeWidgetSet,have_xaw=yes,have_xaw=no)
      ;;
    "xaw3d")
      AC_CHECK_LIB(Xaw3d,XawInitializeWidgetSet,
        [ have_xaw=3d;
            AC_CHECK_HEADER(X11/Xaw3d/Tip.h,
            AC_DEFINE(HAVE_XAW3D_TIP,1,Define to 1 if you have the <X11/Xaw3d/Tip.h> header file.),
            )
        ],
        have_xaw=no
      )
      ;;
    "neXtaw")
      AC_CHECK_LIB(neXtaw,XawInitializeWidgetSet,have_xaw=next,have_xaw=no)
      ;;
    "XawPlus")
      AC_CHECK_LIB(Xpm,XpmCreatePixmapFromData)
      AC_CHECK_LIB(XawPlus,XawInitializeWidgetSet,have_xaw=plus,have_xaw=no)
      ;;
    *)
      have_xaw=no
      ;;
    esac
    AS_IF([test "x$have_xaw" != "xno"],[break;])
  done
  AC_CHECK_LIB(Xm,XmCreateForm,have_xm=yes,have_xm=no)
  AC_CHECK_FUNCS(XShmCreatePixmap)
  LIBS=$KEEPLIBS
])
dnl End of X configure

# Checks for header files.
AC_CHECK_INCLUDES_DEFAULT
AC_PROG_EGREP

#AC_HEADER_STDBOOL
AC_HEADER_SYS_WAIT
AS_IF([test "x$WATCOM_C" != xyes], [
  AC_CHECK_HEADERS_ONCE([sys/time.h])
])

AC_HEADER_DIRENT
AC_CHECK_HEADERS( \
  [arpa/inet.h \
  errno.h \
  getopt.h \
  glob.h \
  dlfcn.h \
  fcntl.h \
  inttypes.h \
  limits.h \
  machine/endian.h \
  malloc.h \
  memory.h \
  netdb.h \
  netinet/in.h \
  nlist.h \
  stddef.h \
  stdlib.h \
  stdint.h \
  string.h \
  strings.h \
  stropts.h \
  soundcard.h \
  alsa/asoundlib.h \
  sys/asoundlib.h \
  sys/audioio.h \
  sys/awe_voice.h\
  sys/ioctl.h \
  sys/ipc.h \
  sys/param.h \
  sys/shm.h \
  sys/socket.h \
  sys/soundcard.h \
  sys/param.h \
  sys/time.h \
  sys/types.h \
  sys/stat.h \
  sys/sysctl.h \
  termios.h \
  X11/Xlib.h])

AS_IF([test "x$DMC" != xyes], [
AC_CHECK_HEADERS([ \
  unistd.h \
  ])
])

AC_CHECK_HEADERS(\
  [X11/extensions/XShm.h X11/Xmu/ExtAgent.h],[],[],[
#ifdef HAVE_X11_XLIB_H
#include <X11/Xlib.h>
#endif
  ])
AC_CHECK_HEADER(string.h,, [ AC_DEFINE(NO_STRING_H,1,Define to 1 if you do not have <string.h>.)])

# Checks for typedefs, structures, and compiler characteristics.
AS_IF([test "x$WATCOM_C" != xyes],[
  AC_C_BIGENDIAN
])
AC_C_CHAR_UNSIGNED
AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE
AC_C_STRINGIZE
AC_C_PROTOTYPES
AC_STRUCT_TM
AS_IF([test "x$DMC" != xyes], [
  AC_TYPE_SIZE_T
])
AS_IF([test "x$POCC" != xyes], [
  AC_TYPE_OFF_T
  AC_TYPE_PID_T
])

# Older versions of MinGW do not define ssize_t in sys/types
AC_MSG_CHECKING([for ssize_t])
AC_CACHE_VAL(ac_cv_type_$1,
[AC_EGREP_CPP([ssize_t@<:@^a-zA-Z_0-9@:>@],
[#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#include <stddef.h>
#endif], [ac_cv_type_ssize_t=yes], [ac_cv_type_ssize_t=no])])

AC_MSG_RESULT([$ac_cv_type_ssize_t])
AS_IF([test $ac_cv_type_ssize_t = yes], [
  AC_DEFINE(HAVE_SSIZE_T, 1,
    [Define to 1 if the system has the type ``ssize_t''.])
])

dnl keyword "volatile" check
AC_CACHE_CHECK(volatile declaration,timidity_cv_type_volatile,
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM(, [[volatile int x]])],[timidity_cv_type_volatile=yes],[timidity_cv_type_volatile=no]))
AS_IF([test $timidity_cv_type_volatile = no], [
  AC_DEFINE(NO_VOLATILE,1,Define to 1 if you cannot use volatile keyword)
])

dnl union usenum check
AC_CACHE_CHECK(union semun declaration,timidity_cv_type_union_semun,
  AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/sem.h>
]], [[union semun x]])],[timidity_cv_type_union_semun=yes],[timidity_cv_type_union_semun=no]))
AS_IF([test $timidity_cv_type_union_semun = yes], [
  AC_DEFINE(HAVE_UNION_SEMUN,1,Define to 1 if you use semun keyword)
])

dnl Cygnus and Mingw memory struct optiontest
AS_IF([test "x$MSYS" = xyes], [
	case "x${CC}" in
	"xgcc"*)
		msnative_struct=''
		AC_MSG_CHECKING([how to get MSVC-compatible struct packing])
		AS_IF([test -z "$ac_cv_prog_CC"], [
			our_gcc="$CC"
		], [
			our_gcc="$ac_cv_prog_CC"
		])
		case `$our_gcc --version | sed -e 's,\..*,.,' -e q` in
			2.)
		AS_IF([$our_gcc -v --help 2>/dev/null | grep fnative-struct >/dev/null], [
			msnative_struct='-fnative-struct'
		])
		;;
			*)
		AS_IF([$our_gcc -v --help 2>/dev/null | grep ms-bitfields >/dev/null], [
			msnative_struct='-mms-bitfields'
		])
		;;
		esac
		AS_IF([test x"$msnative_struct" = x], [
			AC_MSG_RESULT([no way])
			AC_MSG_WARN([produced binary will be incompatible with windows' GUI ])
		], [
			CFLAGS="$CFLAGS $msnative_struct"
			CPPFLAGS="$CPPFLAGS $msnative_struct"
			AC_MSG_RESULT([${msnative_struct}])
		])
		;;
	*)
		;;
	esac
])
dnl Cygnus Mingw32 mmsystem check
AS_IF([test "x$MSYS" = xyes], [
  AC_CACHE_CHECK(Cygwin new mmsystem,timidity_cv_header_new_mmsystem,
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
#include <windows.h>
#include <mmsystem.h>
]], [[return WOM_OPEN != 0x3BB]])],[timidity_cv_header_new_mmsystem=yes],[timidity_cv_header_new_mmsystem=no]))
  AS_IF([test $timidity_cv_header_new_mmsystem = yes], [
    AC_DEFINE(HAVE_NEW_MMSYSTEM,1,Define to 1 if you have <mmsystem.h> file)
  ])
])

# Checks for library functions.
AC_FUNC_ERROR_AT_LINE
AS_IF([test "x$DMC" != xyes], [
  AC_FUNC_FORK
])
AC_FUNC_MEMCMP
AS_IF([test "x$DMC" != xyes], [
  AC_FUNC_MMAP
])
AS_IF([test "x$VCPP" != xyes && test "x$BORLANDC" != xyes && test "x$WATCOM_C" != "xyes" && test "x$POCC" != "xyes"], [
  AC_FUNC_VPRINTF
])
AC_CHECK_FUNCS( \
  [alarm \
  dup2 \
  floor \
  getcwd \
  gethostbyname \
  getopt \
  gettimeofday \
  getwd \
  isatty \
  memchr \
  memmove \
  memset \
  mkstemp \
  modf \
  munmap \
  popen \
  pow \
  select \
  signal \
  socket \
  sleep \
  vsnprintf \
  snprintf \
  sqrt \
  strchr \
  strdup \
  strstr \
  strerror \
  strcasecmp \
  strncasecmp \
  strrchr \
  strstr \
  strtol \
  strlcat \
  strlcpy \
  usleep])
AS_IF([test "x$VCPP" = xyes], [
  AC_DEFINE(HAVE_GETCWD,1)
])
AS_IF([test "x$POCC" = xyes], [
  AC_DEFINE(HAVE_GETCWD,1)
  AC_DEFINE(HAVE_GETHOSTBYNAME,1)
  AC_DEFINE(HAVE_POPEN,1)
  AC_DEFINE(HAVE_SELECT,1)
  AC_DEFINE(HAVE_SNPRINTF,1)
  AC_DEFINE(HAVE_STRDUP,1)
  AC_DEFINE(HAVE_STRERROR,1)
  AC_DEFINE(HAVE_STRCASECMP,1)
  AC_DEFINE(HAVE_STRSTR,1)
  AC_DEFINE(HAVE_SOCKET,1)
  AC_DEFINE(HAVE_VSNPRINTF,1)
  AC_DEFINE(HAVE_GETOPT,1)
  AC_DEFINE(TIMID_VERSION,[$(PACKAGE_VERSION)],[for windows gui])
])
AS_IF([test "x$VCPP" = xyes || test "x$BORLANDC" = xyes || test "x$WATCOM_C" = xyes], [
  AC_DEFINE(HAVE_GETHOSTBYNAME,1)
  AC_DEFINE(HAVE_POPEN,1)
  AC_DEFINE(popen,_popen,[for VC])
  AC_DEFINE(pclose,_pclose,[for VC])
  AC_DEFINE(HAVE_SELECT,1)
  AC_DEFINE(HAVE_SNPRINTF,1)
  AC_DEFINE(HAVE_STRDUP,1)
  AC_DEFINE(HAVE_STRERROR,1)
  AC_DEFINE(HAVE_STRNCASECMP,1)
  AC_DEFINE(HAVE_STRSTR,1)
  AC_DEFINE(snprintf,_snprintf,[for VC])
  AC_DEFINE(HAVE_SOCKET,1)
  AC_DEFINE(HAVE_VSNPRINTF,1)
dnl  AC_DEFINE(vsnprintf,_vsnprintf,[for VC])
  AC_DEFINE(TIMID_VERSION,[$(PACKAGE_VERSION)],[for windows gui])
])

AC_CHECK_FUNC(getopt_long,
	 AC_DEFINE([HAVE_GETOPT_LONG],1,[Define to 1 if you have ``getopt_long'' function])
	 tm_cv_needgetopt="no",
	 tm_cv_needgetopt="yes")
AM_CONDITIONAL([NEEDGETOPT], test "x$tm_cv_needgetopt" = "xyes")

AC_CHECK_FUNC(open_memstream, [
	 AC_DEFINE([HAVE_OPEN_MEMSTREAM],1,[Define to 1 if you have ``open_memstream'' function])
	 ])

dnl ***
dnl *** va_copy checks (from GLIB)
dnl ***

AC_CACHE_CHECK([for an implementation of va_copy()],lib_cv_va_copy,[
	AC_RUN_IFELSE([AC_LANG_SOURCE([[
	#include <stdarg.h>
	void f (int i, ...) {
	va_list args1, args2;
	va_start (args1, i);
	va_copy (args2, args1);
	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
	  exit (1);
	va_end (args1); va_end (args2);
	}
	int main() {
	  f (0, 42);
	  return 0;
	}]])],
	[lib_cv_va_copy=yes],
	[lib_cv_va_copy=no],[])
])

AC_CACHE_CHECK([for an implementation of __va_copy()],lib_cv___va_copy,[
	AC_RUN_IFELSE([AC_LANG_SOURCE([[
	#include <stdarg.h>
	void f (int i, ...) {
	va_list args1, args2;
	va_start (args1, i);
	__va_copy (args2, args1);
	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
	  exit (1);
	va_end (args1); va_end (args2);
	}
	int main() {
	  f (0, 42);
	  return 0;
	}]])],
	[lib_cv___va_copy=yes],
	[lib_cv___va_copy=no],[])
])

AS_IF([test "x$lib_cv_va_copy" = "xyes"], [
  va_copy_func=va_copy
], [test "x$lib_cv___va_copy" = "xyes"], [
  va_copy_func=__va_copy
])

AS_IF([test -n "$va_copy_func"], [
  AC_DEFINE_UNQUOTED(VA_COPY,$va_copy_func,[A 'va_copy' style function])
])

AC_CACHE_CHECK([whether va_lists can be copied by value],lib_cv_va_val_copy,[
	AC_RUN_IFELSE([AC_LANG_SOURCE([[
	#include <stdarg.h>
	void f (int i, ...) {
	va_list args1, args2;
	va_start (args1, i);
	args2 = args1;
	if (va_arg (args2, int) != 42 || va_arg (args1, int) != 42)
	  exit (1);
	va_end (args1); va_end (args2);
	}
	int main() {
	  f (0, 42);
	  return 0;
	}]])],
	[lib_cv_va_val_copy=yes],
	[lib_cv_va_val_copy=no],[])
])

AS_IF([test "x$lib_cv_va_val_copy" = "xno"], [
  AC_DEFINE(VA_COPY_AS_ARRAY,1, ['va_lists' cannot be copies as values])
])

# Checks on cygnus and MSYS
AS_IF([test "x$MSYS" = xyes], [
  case "$ac_cv_header_dirent_dirent_h$ac_cv_header_dirent_sys_ndir_h$ac_cv_header_dirent_sys_dir_h$ac_cv_header_dirent_ndir_h" in
  *yes*)
    AC_CHECK_FUNC(opendir,,
  [ EXTRADEFS="$EXTRADEFS -D__W32READDIR__"
    W32READDIR=yes ])
    ;;
  *)EXTRADEFS="$EXTRADEFS -D__W32READDIR__"
    W32READDIR=yes
    ;;
  esac
  AS_IF([test "x$VCPP" = xyes || test "x$BORLANDC" = xyes || test "x$WATCOM_C" = xyes || test "x$DMC" = xyes || test "x$POCC" = xyes], [
    EXTRALIBS="$EXTRALIBS  ws2_32.lib"
    EXTRADEFS="$EXTRADEFS -DWINSOCK"
  ], [
    AC_CHECK_FUNC(socket,,
     WAPI_CHECK_LIB(ws2_32,WSAStartup,
	   [#include <winsock.h>],
	   [WSAStartup(0,0);],
       [ EXTRALIBS="$EXTRALIBS -lws2_32"
        EXTRADEFS="$EXTRADEFS -DWINSOCK" ]
     )
    )
  ])
])

# Checks on extra paths

dnl tcltk paths
AC_ARG_WITH(tcl-includes,
  AS_HELP_STRING([--with-tcl-includes=DIR], [Tcl include file path]),
  [ AS_IF([test ! -d $withval], [
      AC_MSG_WARN($withval is not found.)
    ])
    tcl_include_dir="-I$withval"
  ])
AC_ARG_WITH(tcl-libs,
  AS_HELP_STRING([--with-tcl-libs=DIR], [Tcl library file path]),
  [ AS_IF([test ! -d $withval], [
      AC_MSG_WARN($withval is not found.)
    ])
    tcl_libdir="-L$withval" ])
AC_ARG_WITH(tk-includes,
  AS_HELP_STRING([--with-tk-includes=DIR], [Tk include file path]),
  [ AS_IF([test ! -d $withval], [
      AC_MSG_WARN($withval is not found.)
    ])
    tk_includes="-I$withval" ])
AC_ARG_WITH(tk-libs,
  AS_HELP_STRING([--with-tk-libs=DIR], [Tk library file path]),
  [ AS_IF([test ! -d $withval], [
      AC_MSG_WARN($withval is not found.)
    ])
    tk_libdir="-L$withval" ])

dnl offix paths
AC_ARG_WITH(offix-includes,
  AS_HELP_STRING([--with-offix-includes=DIR], [Offix include file path]),
  [ AS_IF([test ! -d $withval], [
      AC_MSG_WARN($withval is not found.)
    ])
    offix_include_dir="-I$withval" ])
AC_ARG_WITH(offix-libs,
  AS_HELP_STRING([--with-offix-libs=DIR], [Offix include file path]),
  [ AS_IF([test ! -d $withval], [
      AC_MSG_WARN($withval is not found.)
    ])
    offix_lib_dir="-L$withval" ])


#
# audio section
#
dnl default(d): auto selection
dnl oss(d):     OSS /dev/dsp
dnl alsa(d):    ALSA pcm device
dnl sun(d):     SunOS /dev/audio
dnl hpux(d):    HPUX /dev/audio
dnl irix(d):    IRIX audio
dnl mme(d):     OSF/1 MME
dnl sb_dsp(d):  BSD/OS 2.0 /dev/sb_dsp
dnl w32(d):     Windows MMS
dnl darwin(d):  Mac OS X pcm device
dnl alsa(s):    ALSA pcm device
dnl alib(A):    HPUX network audio (Alib)
dnl nas(n):     Network Audio System
dnl arts(R):	aRts
dnl esd(e):     EsounD
dnl portaudio(p) PortAudio
dnl npipe(N)   Windows named pipe;
dnl vorbis(v):  Ogg Vorbis
dnl flac(F):    FLAC / OggFLAC
dnl speex(S):   Ogg Speex
dnl gogo(g):    MP3 GOGO
dnl jack(j):    JACK
dnl ao(O):      Libao

audio_targets='default oss alsa sun hpux irix mme sb_dsp w32 alib nas arts esd vorbis flac gogo portaudio npipe jack ao'

AC_ARG_WITH(nas-library,
  AS_HELP_STRING([--with-nas-library=library], [NAS absolute library path(Don''t use -laudio)]))
AC_ARG_WITH(nas-includes,
  AS_HELP_STRING([--with-nas-includes=DIR], [NAS include files are in dir]))


AC_ARG_ENABLE(audio,
  [  --enable-audio[=mode_list] Enable audio (Specify comma separated mode list):
                              default:   Automatically select audio device.
                              oss:       OSS /dev/dsp
                              sun:       SunOS /dev/audio
                              hpux:      HPUX /dev/audio
                              irix:      IRIX audio library
                              mme:       OSF/1 MME
                              sb_dsp:    BSD/OS 2.0 /dev/sb_dsp
                              w32:       Windows MMS
                              darwin:    Darwin CoreAudio
                              alsa:      ALSA pcm device
                              alib:      HPUX network audio (Alib)
                              nas:       NAS - Network Audio System
                              arts:      aRts
                              esd:       EsounD - Enlightened Sound Daemon
                              portaudio: PortAudio
                              npipe:     Named Pipe(windows)
                              jack:      JACK
                              ao:        Libao
                              vorbis:    Ogg Vorbis
                              flac:      FLAC / OggFLAC
                              speex:     Ogg Speex
                              gogo:      MP3 GOGO (Only Windows is supported)
],
  [ enable_audio=$enableval
    have_audio_opt=yes ],
  [ enable_audio=yes
    have_audio_opt=no ])

dnl yes -> default
AS_IF([test "x$enable_audio" = xyes], [ enable_audio=default ])

AS_IF([test "x$enable_audio" != xno], [
  for i in `echo $enable_audio | sed 's/,/ /g'`; do
    eval "au_enable_$i=yes"
  done
])

dnl Turn on default output mode
DEFAULT_PLAYMODE=
AC_ARG_WITH(default-output,
  AS_HELP_STRING([--with-default-output=<mode>],
  [Specify default output mode (optional):
                                (default|alsa|alib|arts|nas|
                                esd|wav|au|aiff|list|vorbis|flac|speex|
                                gogo|portaudio|npipe|jack|ao)]),
  [ AS_IF([test "$enable_audio" != no], [
      DEFAULT_PLAYMODE=$withval
      eval "au_enable_$DEFAULT_PLAYMODE=yes"
    ] , [
      AC_MSG_WARN([--with-default-output=$withval: audio is not enabled])
    ])
  ])

dnl compatibility matters.
dnl AC_ARG_ENABLE(esd,
dnl   [  --enable-esd         EsounD (Obsoleted.  Use --enable-audio=esd)],
dnl   [ au_enable_esd=$enableval ])
dnl AC_ARG_ENABLE(nas,
dnl   [  --enable-nas         NAS  (Obsoleted.  Use --enable-audio=nas)],
dnl   [ au_enable_nas=$enableval ])
dnl AC_ARG_ENABLE(alsa,
dnl   [  --enable-alsa        ALSA   (Obsoleted.  Use --enable-audio=alsa)],
dnl   [ au_enable_alsa=$enableval ])

dnl target-specific defaults
AS_IF([test "x$au_enable_default" = xyes], [
  case "$target" in
  *-*-linux*|*-*-freebsd*)
    au_enable_oss=yes
    ;;
  *-*-bsdi2.0)
    au_enable_sb_dsp=yes
    ;;
  *-*-bsdi2.1|*-*-bsdi3.?|*-*-bsdi4.?)
    au_enable_oss=yes
    ;;
  *-*-hpux*)
    au_enable_hpux=yes
    ;;
  *-dec-*)
    au_enable_mme=yes
    ;;
  *irix*)
    au_enable_irix=yes
    ;;
  *-*-sunos4*)
    au_enable_sun=yes
    ;;
  *-*-solaris*)
    au_enable_sun=yes
    ;;
  *-*-netbsd*)
    au_enable_sun=yes
    ;;
  *-*-openbsd*)
    au_enable_sun=yes
    ;;
  *-*-cygwin*)
    au_enable_w32=yes
    ;;
  *-*-mingw*)
    au_enable_w32=yes
    ;;
  *-*-darwin*)
    au_enable_darwin=yes
    ;;
  *)
    AC_MSG_WARN(No --enable-audio=default audio for $target)
    ;;
  esac
])


# Each audio mode's configurations
dnl oss
AC_MSG_CHECKING(enable_audio=oss)
AS_IF([test "x$au_enable_oss" = xyes], [
  EXTRADEFS="$EXTRADEFS -DAU_OSS"
  SYSEXTRAS="$SYSEXTRAS oss_a.c"
  AS_IF([test "x$ac_cv_header_sys_soundcard_h" = xyes], [
    AC_MSG_RESULT(yes - <sys/soundcard.h>)
  ], [
    case "$target" in
      *linux*|*freebsd*)
        dnl <linux/soundcard.h> or <machine/soundcard.h>
        AC_MSG_RESULT(yes)
        ;;
      *)
        AS_IF([test "x$ac_cv_header_soundcard_h" = xyes], [
          AC_MSG_RESULT(yes - <soundcard.h>)
        ], [
          AC_MSG_WARN(<sys/soundcard.h> is not found)
        ])
	;;
    esac
  ])
  AC_CHECK_LIB(ossaudio,open)

  dnl Why OpenBSD use /dev/audio instead of /dev/dsp for OSS
  case "$target" in
    *openbsd*)
      AS_IF([test ! -e "/dev/dsp"], [
        oss_device=/dev/audio
      ])
      ;;
  esac
], [
  AC_MSG_RESULT(no)
])

dnl SunOS's
AC_MSG_CHECKING(enable_audio=sun)
AS_IF([test "x$au_enable_sun" = xyes], [
  case "$target" in
    *-*-sunos4*)
      AS_IF([test -f /usr/demo/SOUND/libaudio.a], [
        EXTRALIBS="$EXTRALIBS /usr/demo/SOUND/libaudio.a"
	AC_MSG_RESULT(yes)
      ], [
	AC_MSG_RESULT(Notice: libaudio.a is not found [(ignore)])
      ])
      ;;
    *-*-solaris*)
      AS_IF([test -f /usr/demo/SOUND/lib/libaudio.a], [
        EXTRALIBS="$EXTRALIBS /usr/demo/SOUND/lib/libaudio.a"
	AC_MSG_RESULT(yes)
      ], [
        AC_MSG_RESULT(Notice: libaudio.a is not found [(ignore)])
      ])
      ;;
    *)   AC_MSG_RESULT(yes)
      ;;
  esac
  EXTRADEFS="$EXTRADEFS -DAU_SUN"
  SYSEXTRAS="$SYSEXTRAS sun_a.c"
], [
  AC_MSG_RESULT(no)
])

dnl HP-UX's
AC_MSG_CHECKING(enable_audio=hpux)
AS_IF([test "x$au_enable_hpux" = xyes], [
  case "$target" in
    *-*-hpux*) AC_MSG_RESULT(yes) ;;
    *) AC_MSG_WARN(may not work on $target) ;;
  esac
  EXTRADEFS="$EXTRADEFS -DAU_HPUX_AUDIO"
  SYSEXTRAS="$SYSEXTRAS hpux_d_a.c"
], [
  AC_MSG_RESULT(no)
])

dnl Irix's
AC_MSG_CHECKING(enable_audio=irix)
AS_IF([test "x$au_enable_irix" = xyes], [
  case "$target" in
    *-sgi-irix5*|*-sgi-irix6.2)
      EXTRADEFS="$EXTRADEFS -DAU_AUDRIV -DSGI_OLDAL"
      AC_MSG_RESULT(yes)
      ;;
    *-sgi-irix6*)
      EXTRADEFS="$EXTRADEFS -DAU_AUDRIV -DSGI_NEWAL"
      AC_MSG_RESULT(yes)
      ;;
    *) AC_MSG_WARN(may not work on $target) ;;
  esac
  SYSEXTRAS="$SYSEXTRAS audriv_a.c audriv_al.c"
  EXTRALIBS="$EXTRASLIBS -laudio"
], [
  AC_MSG_RESULT(no)
])

dnl OSF/1 MME
AC_MSG_CHECKING(enable_audio=mme)
AS_IF([test "x$au_enable_mme" = xyes], [
  case "$target" in
    *-dec-*) AC_MSG_RESULT(yes) ;;
    *) AC_MSG_WARN(may not work on $target) ;;
  esac
  EXTRADEFS="$EXTRADEFS -DAU_DEC -DAU_AUDRIV"
  SYSEXTRAS="$SYSEXTRAS audriv_a.c audriv_mme.c"
  CPPFLAGS="$CPPFLAGS -I/usr/opt/MME210/include"
  EXTRALIBS="$EXTRALIBS /usr/opt/MME220/lib/libmme.a"
], [
  AC_MSG_RESULT(no)
])

dnl BSD/OS's sb_dsp
AC_MSG_CHECKING(enable_audio=sb_dsp)
AS_IF([test "x$au_enable_sb_dsp" = xyes], [
  case "$target" in
    *-*-bsdi2.0) AC_MSG_RESULT(yes) ;;
    *) AC_MSG_WARN(may not work on $target) ;;
  esac
  EXTRADEFS="$EXTRADEFS -DAU_BSDI -DDEFAULT_RATE=22500"
  SYSEXTRAS="$SYSEXTRAS bsd20_a.c"
], [
  AC_MSG_RESULT(no)
])

dnl Windows' MME
AC_MSG_CHECKING(enable_audio=w32)
AS_IF([test "x$au_enable_w32" = xyes], [
  case "$target" in
    *-*-cygwin*)
     AC_MSG_RESULT(yes)
     ;;
    *-*-mingw32)
     AC_MSG_RESULT(yes)
     ;;
    *)
     AC_MSG_WARN(may not work on $target)
     ;;
  esac
  SYSEXTRAS="$SYSEXTRAS w32_a.c"
  AS_IF([test "x$VCPP" = xyes || test "x$BORLANDC" = xyes || test "x$WATCOM_C" = xyes || test "x$DMC" = xyes || test "x$POCC" = xyes], [
	EXTRALIBS="$EXTRALIBS winmm.lib"
  ], [
    EXTRALIBS="$EXTRALIBS -lwinmm"
  ])
  EXTRADEFS="$EXTRADEFS -DAU_W32"
], [
  AC_MSG_RESULT(no)
])

dnl Mac OS X / darwin-x86
AC_MSG_CHECKING(enable_audio=darwin)
AS_IF([test "x$au_enable_darwin" = xyes], [
  EXTRADEFS="$EXTRADEFS -DAU_DARWIN"
  SYSEXTRAS="$SYSEXTRAS darwin_a.c"
  EXTRALIBS="$EXTRALIBS -framework CoreAudio"
  dnl just say yes or no :-P
  case "$target" in
    *-*-darwin*)
     AC_MSG_RESULT(yes);;
   *)
     AC_MSG_WARN(may not work on $target)
     ;;
  esac
], [
  AC_MSG_RESULT(no)
])


dnl alsa - Advanced Linux Sound Architecture
AC_MSG_CHECKING(enable_audio=alsa)
AS_IF([test "x$au_enable_alsa" = xyes], [
  AC_MSG_RESULT([yes, configuring alsa])
  KEEPCFLAGS=$CFLAGS
  KEEPLIBS=$LIBS
  KEEPLDFLAGS=$LDFLAGS
  AM_PATH_ALSA()
  AS_IF([test "x$alsa_found" = "xyes"], [
    dnl AC_MSG_RESULT(yes)
    EXTRADEFS="$EXTRADEFS -DAU_ALSA"
    SYSEXTRAS="$SYSEXTRAS alsa_a.c"
    EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$ALSA_CFLAGS)
    LIBS="$LIBS $ALSA_LIBS"
    AC_CHECK_FUNCS(snd_seq_port_info_set_timestamping)
  ], [
    AC_MSG_WARN(Couldn't configure alsa.)
    CFLAGS=$KEEPCFLAGS
    LIBS=$KEEPLIBS
    LDFLAGS=$KEEPLDFLAGS
  ])
], [
  AC_MSG_RESULT(no)
])

dnl HP-UX Alib
AC_MSG_CHECKING(enable_audio=alib)
AS_IF([test "x$au_enable_alib" = xyes], [
  case "$target" in
    *-*-hpux*) AC_MSG_RESULT(yes) ;;
    *) AC_MSG_WARN(may not work on $target) ;;
  esac
  SYSEXTRAS="$SYSEXTRAS hpux_a.c"
  EXTRADEFS="$EXTRADEFS -DAU_HPUX_ALIB"
  AS_IF([test -d /opt/audio/include], [
    CPPFLAGS="$CPPFLAGS -I/opt/audio/include"
  ])
  AS_IF([test -d /opt/audio/lib], [
    EXTRALIBS="$EXTRALIBS -L/opt/audio/lib"
  ])
  EXTRALIBS="$EXTRALIBS -lAlib"
], [
  AC_MSG_RESULT(no)
])

dnl nas
AC_MSG_CHECKING(enable_audio=nas)
AS_IF([test "x$au_enable_nas" = xyes], [
  AS_IF([test "x$with_x" != xyes], [
    AC_MSG_ERROR(nas: --with-x option must be specified)
  ])
  EXTRADEFS="$EXTRADEFS -DAU_NAS"
  SYSEXTRAS="$SYSEXTRAS nas_a.c"

  dnl -laudio conflicts another audio library,
  dnl so I specify NAS library with absolete path.

  AS_IF([test "x$with_nas_library" != x], [
    AC_MSG_RESULT($with_nas_library);
    EXTRALIBS="$EXTRALIBS $with_nas_library"
  ], [
    AC_MSG_RESULT()
    MY_SEARCH_LIBS(AuOpenServer,
	[$x_libraries/libaudio.a \
	 /usr/lib/libaudio.so \
	 /usr/lib/libaudio.a ],
	[ AC_MSG_RESULT(NAS: $timidity_cv_search_AuOpenServer)
	  EXTRALIBS="$EXTRALIBS $timidity_cv_search_AuOpenServer"],
	[AC_MSG_WARN(NAS library is not found.)])
  ])
  AS_IF([test "x$with_nas_includes" != x], [
    CPPFLAGS="$CPPFLAGS -I$with_nas_includes"
  ])
  lib_xt_opt=-lXt
  AS_IF([test "x$have_xext" = xyes], [
    lib_xext_opt=-lXext
  ])
  AS_IF([test "x$have_xprelibs" = xyes], [
    lib_xprelibs_opt='-lSM -lICE'
  ])
], [
  AC_MSG_RESULT(no)
])

dnl aRts of KDE
AC_MSG_CHECKING(enable_audio=arts)
AS_IF([test "x$au_enable_arts" = xyes], [
  AC_MSG_RESULT([yes, configuring aRts])
  dnl **** Check for aRts Sound Server ****
  AC_PATH_PROG(ARTSCCONFIG, artsc-config)
  AS_IF([test x$ARTSCCONFIG != x -a x$ARTSCCONFIG != x'"$ARTSCCONFIG"'], [
    ARTSC_CFLAGS=""
    for i in `$ARTSCCONFIG --cflags`
    do
      case "$i" in
        -I*) ARTSC_CFLAGS="$ARTSC_CFLAGS $i";;
      esac
    done
    ARTSC_LIBS=`$ARTSCCONFIG --libs`
    save_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS $ARTSC_CFLAGS"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <artsc.h>]], [[arts_stream_t stream;]])],[AC_SUBST(ARTSLIBS, $ARTSC_LIBS)
         AC_SUBST(ARTSINCL, $ARTSC_CFLAGS)
         AC_DEFINE(HAVE_ARTS, 1, [Define if you have ARTS sound server])
	 have_arts="yes"
         ],[])
    CFLAGS="$save_CFLAGS"
  ])

  AS_IF([test "$have_arts" = "yes"], [
    dnl AC_MSG_RESULT(aRts: Enabled)
    EXTRADEFS="$EXTRADEFS -DAU_ARTS"
    SYSEXTRAS="$SYSEXTRAS aRts_a.c"
    EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$ARTSC_CFLAGS)
    LIBS="$LIBS $ARTSC_LIBS"
  ], [
    AC_MSG_WARN(aRts: Couldn't configure)
  ])
], [
  AC_MSG_RESULT(no)
])

dnl EsounD
AC_MSG_CHECKING(enable_audio=esd)
AS_IF([test "x$au_enable_esd" = xyes], [
  AC_MSG_RESULT([yes, configuring esd])
  KEEPCFLAGS=$CFLAGS
  KEEPLIBS=$LIBS
  KEEPLDFLAGS=$LDFLAGS
  AM_PATH_ESD()
  CFLAGS=$KEEPCFLAGS
  LIBS=$KEEPLIBS
  LDFLAGS=$KEEPLDFLAGS
  AS_IF([test "x$no_esd" = x], [
    dnl AC_MSG_RESULT(EsounD: Enabled)
    EXTRADEFS="$EXTRADEFS -DAU_ESD"
    SYSEXTRAS="$SYSEXTRAS esd_a.c"
    EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$ESD_CFLAGS)
    LIBS="$LIBS $ESD_LIBS"
  ], [
    AC_MSG_WARN(EsounD: Couldn't configure)
  ])
], [
  AC_MSG_RESULT(no)
])

dnl portaudio
AC_MSG_CHECKING(enable_audio=portaudio)
AS_IF([test "x$au_enable_portaudio" = xyes], [
  AC_MSG_RESULT(yes)
  AS_IF([test "x$MSYS" = xyes], [
	SYSEXTRAS="$SYSEXTRAS portaudio_a.c w32_portaudio_dll.c"
	EXTRALIBS="$EXTRALIBS -lportaudio"
	EXTRADEFS="$EXTRADEFS -DAU_PORTAUDIO -DAU_PORTAUDIO_DLL"
  ], [
	SYSEXTRAS="$SYSEXTRAS portaudio_a.c"
	EXTRALIBS="$EXTRALIBS -lportaudio"
	EXTRADEFS="$EXTRADEFS -DAU_PORTAUDIO"
  ])
], [
  AC_MSG_RESULT(no)
])

dnl npipe (windows named pipe)
AC_MSG_CHECKING(enable_audio=npipe)
AS_IF([test "x$au_enable_npipe" = xyes], [
  AC_MSG_RESULT(yes)
	SYSEXTRAS="$SYSEXTRAS npipe_a.c"
	EXTRADEFS="$EXTRADEFS -DAU_NPIPE"
], [
  AC_MSG_RESULT(no)
])


dnl JACK
AC_MSG_CHECKING(enable_audio=jack)
AS_IF([test "x$au_enable_jack" = xyes], [
  AC_MSG_RESULT(yes)
  SYSEXTRAS="$SYSEXTRAS jack_a.c"
  EXTRALIBS="$EXTRALIBS $(pkg-config --libs jack)"
  EXTRADEFS="$EXTRADEFS -DAU_JACK $(pkg-config --cflags jack)"
], [
  AC_MSG_RESULT(no)
])

dnl AO
AC_MSG_CHECKING(enable_audio=ao)
AS_IF([test "x$au_enable_ao" = xyes], [
  AC_MSG_RESULT([yes, configuring ao])
  XIPH_PATH_AO()
  AS_IF([test "x$no_ao" = "x"], [
    # AC_MSG_RESULT(yes)
    EXTRADEFS="$EXTRADEFS -DAU_AO"
    SYSEXTRAS="$SYSEXTRAS ao_a.c"
    EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$AO_CFLAGS)
    LIBS="$LIBS $AO_LIBS"
  ], [
    AC_MSG_WARN(Couldn't configure libao.)
  ])
], [
  AC_MSG_RESULT(no)
])

dnl ogg's vorbis
AC_MSG_CHECKING(enable_audio=vorbis)
AS_IF([test "x$au_enable_vorbis" = xyes], [
  AC_MSG_RESULT([yes, configuring vorbis])
  AS_IF([test "x$MSYS" = "xyes" && test "x$MINGWGCC" != "xyes"], [
    AC_CHECK_HEADER(vorbis/vorbisenc.h,, [
    EXTRADEFS="-DAU_VORBIS_DLL $EXTRADEFS"
	SYSEXTRAS="$SYSEXTRAS w32g_vorbisenc_dll.c w32g_vorbis_dll.c w32g_ogg_dll.c"
    ])
  ], [
    XIPH_PATH_OGG([
      XIPH_PATH_VORBIS([
        have_vorbis=yes
        SYSEXTRAS="$SYSEXTRAS vorbis_a.c"
        EXTRADEFS="$EXTRADEFS -DAU_VORBIS $OGG_CFLAGS $VORBIS_CFLAGS"
        EXTRALIBS="$EXTRALIBS $VORBIS_LIBS $VORBISENC_LIBS $OGG_LIBS"
        AS_IF([test "x$MSYS" = "xyes" && test "x$MINGWGCC" = "xyes"], [
          EXTRADEFS="-DAU_VORBIS_DLL $EXTRADEFS"
          SYSEXTRAS="$SYSEXTRAS w32g_vorbisenc_dll.c w32g_vorbis_dll.c w32g_ogg_dll.c"
        ])
      ],[
        AC_MSG_WARN([Unable to configure vorbis, but ogg is there (???)])
      ])
    ],[
      AC_MSG_WARN(Unable to configure vorbis!)
      have_vorbis=no
    ])
  ])
], [
  AC_MSG_RESULT(no)
])

dnl libFLAC - Free Lossless Audio Codec
AS_IF([test "x$MSYS" = xyes], [
  AC_MSG_CHECKING(enable_audio=flac)
  AS_IF([test "x$au_enable_flac" = xyes], [
    AC_MSG_RESULT([yes, configuring flac])
    SYSEXTRAS="$SYSEXTRAS flac_a.c w32_libFLAC_dll.c"
    AC_CHECK_HEADER(FLAC/all.h, [
      EXTRADEFS="$EXTRADEFS -DAU_FLAC -DAU_FLAC_DLL"
    ])
  ], [
    AC_MSG_RESULT(no)
  ])
], [
  AC_MSG_CHECKING(enable_audio=flac)
  AS_IF([test "x$au_enable_flac" = xyes], [
    AC_MSG_RESULT([yes, configuring flac])
    SYSEXTRAS="$SYSEXTRAS flac_a.c"
    AM_PATH_LIBFLAC([
      EXTRADEFS="$EXTRADEFS -DAU_FLAC"
      EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$LIBFLAC_CFLAGS)
      LIBS="$LIBS $LIBFLAC_LIBS"
    ])
  ], [
    AC_MSG_RESULT(no)
  ])
])

dnl ogg's speex
AC_MSG_CHECKING(enable_audio=speex)
AS_IF([test "x$au_enable_speex" = xyes], [
  AC_CACHE_VAL(timidity_cv_have_speex,
  [AC_LINK_IFELSE([AC_LANG_PROGRAM([[
  #include <speex/speex.h>
  #include <ogg/ogg.h>
  ]], [[
    SpeexBits *dummy;
  ]])],[have_speex=yes],[have_speex=no])])
  AC_MSG_RESULT($have_speex)
  AS_IF([test "x$have_speex" = xyes], [
    SYSEXTRAS="$SYSEXTRAS speex_a.c"
    EXTRALIBS="$EXTRALIBS -lspeex -logg"
    EXTRADEFS="$EXTRADEFS -DAU_SPEEX"
  ])
], [
  AC_MSG_RESULT(no)
])

dnl Win32 Gogo-no-coder
AC_MSG_CHECKING(enable_audio=gogo)
AS_IF([test "x$au_enable_gogo" = xyes], [
  AS_IF([test "x$MSYS" = "xyes"], [
    AC_MSG_RESULT(yes, configuring gogo)
  ], [
    AC_MSG_WARN(May be gogo is not supported.  You need hack the gogo_a.c)
  ])
  AC_CHECK_HEADER(gogo/gogo.h, [
    have_gogo=yes
  ])
  SYSEXTRAS="$SYSEXTRAS gogo_a.c w32_gogo.c"
  EXTRADEFS="$EXTRADEFS -DAU_GOGO -DAU_GOGO_DLL"
dnl  EXTRALIBS="$EXTRALIBS -lgogo"
], [
  AC_MSG_RESULT(no)
])

dnl Pseudo audio device (Undocumented).
AS_IF([test "x$au_enable_none" = xyes], [
    EXTRADEFS="$EXTRADEFS -DAU_NONE -DAU_AUDRIV"
    SYSEXTRAS="$SYSEXTRAS audriv_a.c audriv_none.c"
])
dnl
dnl TIMIDITY_OUTPUT_ID
dnl
AC_MSG_CHECKING(default output mode)
AS_IF([test "x$DEFAULT_PLAYMODE" = x], [
  DEFAULT_PLAYMODE=`echo $enable_audio | sed 's/,.*//'`
])
case ".$DEFAULT_PLAYMODE" in
  .default)  TIMIDITY_OUTPUT_ID=d ;;
  .oss)      TIMIDITY_OUTPUT_ID=d ;;
  .alsa)     TIMIDITY_OUTPUT_ID=s ;;
  .sun)      TIMIDITY_OUTPUT_ID=d ;;
  .hpux)     TIMIDITY_OUTPUT_ID=d ;;
  .irix)     TIMIDITY_OUTPUT_ID=d ;;
  .mme)      TIMIDITY_OUTPUT_ID=d ;;
  .sb_dsp)   TIMIDITY_OUTPUT_ID=d ;;
  .darwin)   TIMIDITY_OUTPUT_ID=d ;;
  .w32)      TIMIDITY_OUTPUT_ID=d ;;
  .alib)     TIMIDITY_OUTPUT_ID=A ;;
  .nas)      TIMIDITY_OUTPUT_ID=n ;;
  .arts)     TIMIDITY_OUTPUT_ID=R ;;
  .esd)      TIMIDITY_OUTPUT_ID=e ;;
  .portaudio)      TIMIDITY_OUTPUT_ID=p ;;
  .npipe)    TIMIDITY_OUTPUT_ID=N ;;
  .wav)      TIMIDITY_OUTPUT_ID=w ;;
  .au)       TIMIDITY_OUTPUT_ID=u ;;
  .aiff)     TIMIDITY_OUTPUT_ID=a ;;
  .list)     TIMIDITY_OUTPUT_ID=l ;;
  .vorbis)   TIMIDITY_OUTPUT_ID=v ;;
  .flac)     TIMIDITY_OUTPUT_ID=F ;;
  .speex)    TIMIDITY_OUTPUT_ID=S ;;
  .gogo)     TIMIDITY_OUTPUT_ID=g ;;
  .jack)     TIMIDITY_OUTPUT_ID=j ;;
  .ao)       TIMIDITY_OUTPUT_ID=O ;;
  *)         TIMIDITY_OUTPUT_ID= ;;
esac
AC_MSG_RESULT($DEFAULT_PLAYMODE/$TIMIDITY_OUTPUT_ID)


#
# Interface Section
#

interface_targets='dynamic ncurses slang motif tcltk emacs vt100 xaw xskin gtk alsaseq winsyn winsyng portmidisyng npsyn'

AC_ARG_ENABLE(interface,
  AS_HELP_STRING([--enable-interface=[interface_list]], [Comma separated interface list]),
  [ for i in `echo $enableval | sed 's/,/ /g'`; do
      eval "enable_$i=yes"
    done ])

#  Dynamic link configuration
AC_ARG_ENABLE(dynamic,
  AS_HELP_STRING([--enable-dynamic], [Enable dynamic link interface (default is no)])
  AS_HELP_STRING([--enable-dynamic=dynamic_list] [Comma separated dynamic interface list]),
  [ dnl --enable-dynamic=yes to --enable-dynamic=dynamic
    AS_IF([test "x$enable_dynamic" = xyes], [
      enable_dynamic=dynamic
    ], [test "x$enable_dynamic" != xno], [
      for i in `echo $enableval | sed 's/,/ /g'`; do
	eval "enable_$i=dynamic"
      done
    ])
])

join_targets=
for i in $interface_targets; do
  eval "join_targets=$join_targets\$enable_$i"
done

case ".$join_targets" in
.*dynamic*) NEEDDLOPEN=yes;;
*)	    NEEDDLOPEN=no;;
esac

dnl check -fpic option for gcc
AS_IF([test "x$GCC" = xyes],[ SHCFLAGS="$SHCFLAGS -fPIC" ])
case "x$enable_ump" in xyes|xdynamic) EXTRACFLAGS="$EXTRACFLAGS -DXP_UNIX $SHCFLAGS";; esac

dnl Which type of dynamic loader?
AS_IF([test "$NEEDDLOPEN" = "yes"], [
  have_dl=no

  WAPI_CHECK_FUNC(LoadLibrary,,[LoadLibrary(0);],have_dl=w32)
  AS_IF([test $wapi_cv_func_LoadLibrary = yes], [
    have_dl=w32
  ])
  AS_IF([test "$have_dl" = "no"], [
    AC_CHECK_FUNC(shl_load,have_dl=hpux)
  ])
  AS_IF([test "$have_dl" = "no"], [
    dnl darwin has both dyld and libdl: in case user installed dlcompat.
    dnl dyld is recommended because libdl is a wrapper for dyld.
    AC_CHECK_FUNC(NSLinkModule,have_dl=dyld)
  ])
  AS_IF([test "$have_dl" = "no" -a "x$ac_cv_lib_dl_dlopen" = xyes], [
    have_dl=dlopen
  ])
  AS_IF([test "$have_dl" = "no"], [
    AC_CHECK_FUNC(dlopen,have_dl=dlopen)
  ])
  AS_IF([test "$have_dl" = "no"], [
    AC_CHECK_FUNC(dld_init,have_dl=dld)
  ])
  AS_IF([test "$have_dl" = "no"], [
    AC_CHECK_LIB(dld,dld_init,have_dl=dld;lib_dl_opt=-ldld)
  ])

  AC_MSG_CHECKING(dynamic link method)
  case "$have_dl" in
    dlopen)
      AC_MSG_RESULT(use dl_dlopen.c)
      SYSEXTRAS="$SYSEXTRAS dl_dlopen.c"
      CHECK_DLSYM_UNDERSCORE(AC_DEFINE(DLSYM_NEEDS_UNDERSCORE,1,Define to 1 if you have to add "_" to every identifiers.))
      ;;
    dld)
      AC_MSG_RESULT(use dl_dld.c)
      SYSEXTRAS="$SYSEXTRAS dl_dld.c"
      ;;
    hpux)
      AC_MSG_RESULT(use dl_hpux.c)
      SYSEXTRAS="$SYSEXTRAS dl_hpux.c"
      LDFLAGS="$LDFLAGS -Wl,-E $LDFLAGS"
      ;;
    w32)
      AC_MSG_RESULT(use dl_w32.c)
      SYSEXTRAS="$SYSEXTRAS dl_w32.c"
      ;;
    dyld)
      AC_MSG_RESULT(use dl_dyld.c)
      SYSEXTRAS="$SYSEXTRAS dl_dyld.c"
      ;;
    *)
      NEEDDLOPEN="no"
      AC_MSG_WARN(no method to open a shared object)
      ;;
  esac
])

AS_IF([test "$NEEDDLOPEN" = "yes"], [
  MY_DEFINE(IA_DYNAMIC)
  AC_DEFINE_UNQUOTED(SHARED_LIB_EXT,".$so", shared library extention)
  dnl needless?
  dnl EXTRADEFS="$EXTRADEFS \$(DEF_SHLIB_DIR)"
  AS_IF([test "x$GCC" = xyes], [
    AS_IF([test "x$timidity_cv_ccoption_rdynamic" = xyes], [
      timidity_LDFLAGS="-rdynamic"
    ], [
      timidity_LDFLAGS="-Wl,--export-dynamic"
    ])
  ])
])

AM_CONDITIONAL(NEEDDLOPEN, test "$NEEDDLOPEN" = "yes")

dnl xdnd support
AC_ARG_ENABLE(xdnd,
  AS_HELP_STRING([--enable-xdnd], [Enable xdnd support             (default is no)]),
  [ AS_IF([test "$enableval" = "yes"], [
      AC_DEFINE(XDND,1,Define to 1 if you want xdnd support.)
      XDND_SRCS="xdnd.c"
      enable_xdnd=yes
    ])
  ])
AM_CONDITIONAL(ENABLE_XDND, test "x$enable_xdnd" = "xyes")

dnl
dnl Each interface section
dnl

dnl ncurses
AM_CONDITIONAL(ENABLE_NCURSES, false)
CONFIG_INTERFACE(ncurses,NCURSES,n,
  AS_HELP_STRING([--enable-ncurses], [Enable ncurses interface        (default is no)]),
  [ AC_CHECK_HEADERS(ncurses.h ncurses/curses.h curses.h)

dnl #include <ncurses/curses.h> is failure on Plamo Linux 1.3/ncurses 1.9.9e
dnl because <ncurses/curses.h> includes <unctrl.h>:
dnl /usr/include/ncurses/curses.h:34: unctrl.h: No such file or directory
dnl But surely there is unctl.h at /usr/include/ncurses/unctrl.h.
dnl configure must check ncurses header with -I/usr/include/ncurses option.

  case "$ac_cv_header_curses_h$ac_cv_header_ncurses_curses_h$ac_cv_header_ncurses_h" in
    *yes*);;
    *)	for i in /usr/include /usr/local/include; do
	  AS_IF([test -f "$i/ncurses/curses.h" -a -f "$i/ncurses/unctrl.h"], [
	    AC_MSG_WARN(ncurses test is failure.  Please check config.h and common.makefile later)
	    CPPFLAGS="$CPPFLAGS -I$i/ncurses"
	    break
	  ])
	done
	;;
    esac

    AC_CHECK_LIB(ncurses,initscr,lib_curses_opt=-lncurses,
      [ dnl checking pdcurses
	AC_CHECK_LIB(curses,PDC_set_ctrl_break,
          [ lib_curses_opt=-lcurses
	    AC_DEFINE(USE_PDCURSES,1,Define to 1 if you use PDcurses)
	    lib_user32_opt="$lib_user32_test"
	    AC_CHECK_LIB(curses, vwprintw,
	      AC_DEFINE(HAVE_VWPRINTW, 1,
	        [Define to 1 if you have the ``vwprintw'' function.]))
	  ],
	  [ dnl checking libpdcurses
	    AC_CHECK_LIB(pdcurses,PDC_set_ctrl_break,
	    [ lib_curses_opt=-lpdcurses
	      AC_DEFINE(USE_PDCURSES,1,Define to 1 if you use PDcurses)
	      lib_user32_opt="$lib_user32_test"
	      AC_CHECK_LIB(pdcurses, vwprintw,
	        AC_DEFINE(HAVE_VWPRINTW, 1,
	          [Define to 1 if you have the ``vwprintw'' function.]))
	    ],
	    [ dnl OpenBSD use -lcurses instead of -lncurses.
	      case "$target" in
		*openbsd*)
		  AC_CHECK_LIB(curses,initscr,lib_curses_opt=-lcurses,
		    [ AC_MSG_WARN(ncurses interface is not enabled)
		      enable_ncurses=no ])
		  ;;
		*)
		  AS_IF([test "x$VCPP" = xyes || test "x$BORLANDC" = xyes || test "x$WATCOM_C" = xyes || test "x$DMC" = xyes || test "x$POCC" = xyes], [
		    lib_curses_opt=libpdcurses.lib
		    AC_DEFINE(USE_PDCURSES,1,Define to 1 if you use PDcurses)
		    AC_CHECK_LIB(pdcurses, vwprintw,
		      AC_DEFINE(HAVE_VWPRINTW, 1,
		        [Define to 1 if you have the ``vwprintw'' function.]))
		  ], [
		    AC_MSG_WARN(ncurses interface is not enabled)
		    enable_ncurses=no
		  ])
		  ;;
	      esac
	    ])
	],
	$lib_user32_test)
      ])
  ],
  [ LIBS="$LIBS $lib_curses_opt"
    case "$target" in
       *-*-freebsd[123]*)
         EXTRALIBS="$EXTRALIBS -lmytinfo"
         ;;
     esac
    INTERFACE_SRCS="$INTERFACE_SRCS ncurs_c.c"
  ],
  [ n_so_libs="$lib_curses_opt"
    case "$target" in
       *-*-freebsd[123]*)
         EXTRALIBS="$EXTRALIBS -lmytinfo"
         ;;
     esac])

dnl slang
AM_CONDITIONAL(ENABLE_SLANG, false)
CONFIG_INTERFACE(slang,SLANG,s,
  AS_HELP_STRING([--enable-slang], [Enable slang interface          (default is no)]),
  [ AC_CHECK_LIB(slang,SLang_init_tty,:,
    [ enable_slang=no
      AC_MSG_WARN(slang interface is not enabled)
    ])
    AC_CHECK_HEADERS(slang/slang.h slang.h)
  ],
  [ case "$target" in
       *openbsd*)
        AC_CHECK_LIB(termcap,initscr,
                     [ LIBS="$LIBS -lslang -ltermcap"
                       INTERFACE_SRCS="$INTERFACE_SRCS slang_c.c"
                     ]
                     [ AC_MSG_WARN(slang interface is not enabled)
                       enable_slang=no
                     ])
        ;;
       *)
        LIBS="$LIBS -lslang"
        INTERFACE_SRCS="$INTERFACE_SRCS slang_c.c"
       ;;
    esac
  ],
  [ s_so_libs="-lslang"
    AC_CHECK_LIB(termcap,initscr,s_so_libs="$s_so_libs -ltermcap")
  ])

dnl Motif
AM_CONDITIONAL(ENABLE_MOTIF, false)
CONFIG_INTERFACE(motif,MOTIF,m,
  AS_HELP_STRING([--enable-motif], [Enable motif interface          (default is no)]),
  [ AS_IF([test "x$with_x" != xyes], [
	AC_MSG_ERROR(motif: --with-x option must be specified)
    ])
    AS_IF([test "x$have_xm" != xyes], [
      AC_MSG_WARN(Motif library is not found.)
      enable_motif=no
    ])
  ],
  [ lib_xm_opt=-lXm
    lib_xt_opt=-lXt
    lib_xext_opt=-lXext
    AS_IF([test "x$have_xprelibs" = xyes], [
	lib_xprelibs_opt='-lSM -lICE'
    ])
    INTERFACE_SRCS="$INTERFACE_SRCS motif_c.c motif_i.c motif_p.c"
  ],
  [ AS_IF([test x$have_xprelibs = xyes], [
      m_so_libs="-lXext -lSM -lICE"
    ])
    m_so_libs="$ldflags_x_opt -lXm -lXt $m_so_libs -lX11"
  ])

dnl Tcl/Tk
AM_CONDITIONAL(ENABLE_TCLTK, false)
CONFIG_INTERFACE(tcltk,TCLTK,k,
  AS_HELP_STRING([--enable-tcltk], [Enable tcltk interface          (default is no)]),
  [ AS_IF([test "x$with_x" != xyes], [
	AC_MSG_ERROR(tcltk: --with-x option must be specified)
    ])

    dnl save flags
    KEEPCPPFLAGS=$CPPFLAGS
    KEEPLDFLAGS=$LDFLAGS
    KEEPLIBS=$LIBS

    CPPFLAGS="$tcl_include_dir $tk_includes $CPPFLAGS"
    LDFLAGS="$tcl_libdir $tk_libdir $LDFLAGS"
    LIBS="$LIBS $lib_dl_opt"

    tcl_lib=
    tk_lib=
    for l in tcl tcl8.6 tcl8.5 tcl8.4 tcl84 tcl8.3 tcl8.0jp tcl7.6jp tcl80jp tcl76jp tcl8.0 tcl7.6 tcl80 tcl76; do
      case "x$tcl_lib" in x) AC_CHECK_LIB($l,Tcl_Init,tcl_lib=-l$l);; esac
    done
    LIBS="$LIBS $tcl_lib"
    for l in tk tk8.6 tk8.5 tk8.4 tcl84 tk8.3 tk8.0jp tk4.2jp tk80jp tk42jp tk8.0 tk4.2 tk80 tk42; do
      case "x$tk_lib" in x) AC_CHECK_LIB($l,Tk_Init,tk_lib=-l$l);; esac
    done

    LIBS=$KEEPLIBS
    AS_IF([test "x$tcl_lib" = x -o "x$tk_lib" = x], [
      CPPFLAGS=$KEEPCPPFLAGS
      LDFLAGS=$KEEPLDFLAGS
      enable_tcltk=no
      AC_MSG_WARN(tcl/tk is not enable)
    ], [
      tcltk_dep='tclIndex'
    ])
  ],
  [ LIBS="$tk_lib $tcl_lib -lX11 $LIBS"
    case "$target" in
      *-*-bsdi*)
	EXTRALIBS="$EXTRALIBS -lipc"
	;;
    esac
    INTERFACE_SRCS="$INTERFACE_SRCS tk_c.c"
  ],
  [ k_so_libs="$tcl_libdir $tk_libdir $tcl_lib $tk_lib $lib_dl_opt"
    case "$target" in
      *-*-bsdi*)
	k_so_libs="$k_so_libs -lipc"
	;;
    esac
    k_so_libs="$k_so_libs -lX11 -lm"
  ])
AM_CONDITIONAL(ENABLE_DYNAMIC_TCLTK, test "x$enable_tcltk" = "xdynamic")

dnl Emacs
AM_CONDITIONAL(ENABLE_EMACS, false)
CONFIG_INTERFACE(emacs,EMACS,e,
  AS_HELP_STRING([--enable-emacs], [Enable emacs interface          (default is no)]),
  ,
  [ ELFILES="$ELFILES timidity.el"
    INTERFACE_SRCS="$INTERFACE_SRCS emacs_c.c"
  ],
  [ AM_CONDITIONAL(ENABLE_EMACS, true)
    ELFILES="$ELFILES timidity.el" ])

dnl VT100
AM_CONDITIONAL(ENABLE_VT100, false)
CONFIG_INTERFACE(vt100,VT100,T,
  AS_HELP_STRING([--enable-vt100], [Enable VT100 interface          (default is no)]),
  ,
  [ INTERFACE_SRCS="$INTERFACE_SRCS vt100_c.c vt100.c" ])

dnl X Athena Widget
AM_CONDITIONAL(ENABLE_XAW, false)
CONFIG_INTERFACE(xaw,XAW,a,
  AS_HELP_STRING([--enable-xaw], [Enable athena interface         (default is no)]),
  [ AS_IF([test "x$with_x" != xyes], [
	AC_MSG_ERROR(xaw: --with-x option must be specified)
    ])
    AS_IF([test "x$have_xaw" = "xno"], [
      AC_MSG_WARN(X Athena Widget library is not found.)
      enable_xaw=no
    ])
  ],
  [ dnl Add -lXext -lSM -lICE -lXmu -lXt {-lXaw|-lXaw3d}
    AS_IF([test "x$have_xext" = xyes], [
      lib_xext_opt=-lXext
    ])
    AS_IF([test "x$have_xprelibs" = xyes], [
      lib_xprelibs_opt='-lSM -lICE'
    ])
    lib_xmu_opt=-lXmu
    lib_xt_opt=-lXt
    AS_IF([test "x$enable_xft" = "xyes" && test "x$have_xaw" != "xno"], [
      XFT_CFLAGS="$(pkg-config --cflags xft)";
      EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$XFT_CFLAGS)
      lib_xft_opt="-lXft";
    ])
    case "$have_xaw" in
      "yes")
        lib_xaw_opt=-lXaw
	;;
      "3d")
        AC_DEFINE(XAW3D,1,Define to 1 if you use libXaw3d.)
        lib_xaw_opt=-lXaw3d
	;;
      "plus")
        AC_DEFINE(XAWPLUS,1,Define to 1 if you use libXawPlus.)
        lib_xaw_opt="-lXpm -lXawPlus"
	;;
      "next")
        AC_DEFINE(NEXTAW,1,Define to 1 if you use libneXtaw.)
        lib_xaw_opt=-lneXtaw
	;;
    esac
    INTERFACE_SRCS="$INTERFACE_SRCS xaw_c.c xaw_i.c x_trace.c $XDND_SRCS"
  ],
  [ AS_IF([test "x$have_xext" = xyes], [
      a_so_libs="-lXext -lX11"
    ], [
      a_so_libs="-lX11"
    ])
    case "$target" in
      *darwin*)
	a_so_libs="$a_so_libs -lcc_dynamic"
	;;
    esac
    AS_IF([test "x$have_xprelibs" = xyes], [
      a_so_libs="-lSM -lICE $a_so_libs"
    ])
    case "$have_xaw" in
      "yes")
        a_so_libs="-lXaw -lXmu -lXt $a_so_libs"
	;;
      "3d")
        AC_DEFINE(XAW3D,1,Define to 1 if you use libXaw3d.)
        a_so_libs="-lXaw3d -lXmu -lXt $a_so_libs"
	;;
      "plus")
        AC_DEFINE(XAWPLUS,1,Define to 1 if you use libXawPlus.)
        a_so_libs="-lXawPlus -lXpm -lXmu -lXt $a_so_libs"
	;;
      "next")
        AC_DEFINE(NEXTAW,1,Define to 1 if you use libneXtaw.)
        a_so_libs="-lneXtaw -lXmu -lXt $a_so_libs"
	;;
    esac
    AS_IF([test "x$enable_xft" = "xyes" && test "x$have_xaw" != "xno"], [
      XFT_CFLAGS="$(pkg-config --cflags xft)";
      EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$XFT_CFLAGS)
      a_so_libs="$a_so_libs -lXft";
    ])
    a_so_libs="$ldflags_x_opt $a_so_libs"
  ])
AM_CONDITIONAL(ENABLE_DYNAMIC_XAW, test "x$enable_xaw" = "xdynamic")

dnl X skin
AM_CONDITIONAL(ENABLE_XSKIN, false)
CONFIG_INTERFACE(xskin,XSKIN,i,
  AS_HELP_STRING([--enable-xskin], [Enable X skin interface         (default is no)]),
  [ AS_IF([test "x$with_x" != xyes], [
	AC_MSG_ERROR(xskin: --with-x option must be specified)
    ])
  ],
  [ INTERFACE_SRCS="$INTERFACE_SRCS xskin_c.c xskin_i.c xskin_loadBMP.c xskin_spectrum.c" ],
  [ i_so_libs="$ldflags_x_opt -lX11" ])

dnl GTK+
AM_CONDITIONAL(ENABLE_GTK, false)
CONFIG_INTERFACE(gtk, GTK, g,
  AS_HELP_STRING([--enable-gtk], [Enable GTK+ interface           (default is no)]),
  [ AM_PATH_GTK_2_0(2.0.0,
    [AC_DEFINE(HAVE_GTK_2,1,Define to 1 if you have GTK+ 2.x)],
    [AM_PATH_GTK(1.1.3,,enable_gtk=no)]) ],
  [ LIBS="$LIBS $GTK_LIBS"
    EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$GTK_CFLAGS)
    INTERFACE_SRCS="$INTERFACE_SRCS gtk_c.c gtk_i.c gtk_p.c"
  ],
  [ AS_IF([test "x$GCC" = xyes], [
	dnl Do not include -rdynamic option in $g_so_libs.
	for i in $GTK_LIBS; do
	    case "x$i" in
		x-rdynamic) ;;
		*) g_so_libs="$g_so_libs $i" ;;
	    esac
	done
    ], [
	g_so_libs="$GTK_LIBS"
    ])
    EXTRACT_CPPFLAGS(CPPFLAGS,CFLAGS,$GTK_CFLAGS) ])

dnl TiMidity Network MIDI Server
AM_CONDITIONAL(ENABLE_SERVER, false)
CONFIG_INTERFACE(server,SERVER,r,
  AS_HELP_STRING([--enable-server], [Enable server interface         (default is no)]),
  ,
  [ INTERFACE_SRCS="$INTERFACE_SRCS server_c.c"
    AC_CHECK_HEADERS(sys/soundcard.h)
  ])

dnl TiMidity ALSA sequencer server
AM_CONDITIONAL(ENABLE_ALSASEQ, false)
CONFIG_INTERFACE(alsaseq,ALSASEQ,A,
  AS_HELP_STRING([--enable-alsaseq], [Enable ALSA sequencer server interface
                                                          (default is no)]),
  [ INTERFACE_SRCS="$INTERFACE_SRCS alsaseq_c.c"
  ],
  [ AM_PATH_ALSA
  ],
  [ MY_DEFINE(IA_ALSASEQ)
  ])

dnl TiMidity Windows synthesizer server
AM_CONDITIONAL(ENABLE_WINSYN, false)
CONFIG_INTERFACE(winsyn,WINSYN,W,
  AS_HELP_STRING([--enable-winsyn], [Enable Windows Synthesizer interface
                                                          (default is no)]),
  ,
  [ WINSYN="yes"; INTERFACE_SRCS="$INTERFACE_SRCS winsyn_c.c rtsyn_common.c rtsyn_winmm.c" ])

dnl TiMidity PortMIDI synthesizer server
AM_CONDITIONAL(ENABLE_PORTMIDISYN, false)
CONFIG_INTERFACE(portmidisyn,PORTMIDISYN,P,
  AS_HELP_STRING([--enable-portmidisyn], [Enable PortMIDI Synthesizer interface
                                                          (default is no)]),
  ,
  [ INTERFACE_SRCS="$INTERFACE_SRCS portmidisyn_c.c rtsyn_common.c rtsyn_portmidi.c" ])

dnl TiMidity Windows synthesizer server
AM_CONDITIONAL(ENABLE_NPSYN, false)
CONFIG_INTERFACE(npsyn,NPSYN,W,
  AS_HELP_STRING([--enable-npsyn], [Enable Windows Named Pipe Synthesizer interface
                                                          (default is no)]),
  ,
  [ NPSYN="yes"; INTERFACE_SRCS="$INTERFACE_SRCS npsyn_c.c rtsyn_common.c rtsyn_npipe.c" ])



dnl TiMidity Windows GUI synthesizer server
AM_CONDITIONAL(ENABLE_W32G_SYN, false)
CONFIG_INTERFACE(winsyng,W32G_SYN,W,
  AS_HELP_STRING([--enable-winsyng], [Enable Windows GUI Synthesizer interface
                                                          (default is no)]),
  ,
  [
    W32G_GUI=yes
    AS_IF([test "x$VCPP" = xyes || test "x$BORLANDC" = xyes || test "x$WATCOM_C" = xyes || test "x$DMC" = xyes || test "x$POCC" = xyes], [
      INTERFACE_SRCS="$INTERFACE_SRCS w32g_ini.c w32g_pref.c w32g_syn.c w32g_utl.c winsyn_c.c rtsyn_common.c rtsyn_winmm.c"
      lib_w32gui_opt='gdi32.lib comctl32.lib comdlg32.lib ole32.lib'
      lib_user32_opt='user32.lib'
      AS_IF([test "x$VCPP" = xyes], [
        VCPP_LDFLAGS="$VCPP_LDFLAGS -subsystem:windows "
      ])
      AS_IF([test "x$BORLANDC" = xyes], [
        BORLANDC_START='C0W32.OBJ'
        CFLAGS="$CFLAGS -tW"
        lib_w32gui_opt="-aa $lib_w32gui_opt"
      ])
      AS_IF([test "x$WATCOM_C" = xyes], [
       CFLAGS="$CFLAGS -bw"
       WATCOM_LDFLAGS="$WATCOM_LDFLAGS SYS nt_win"
      ])
      AS_IF([test "x$DMC" = xyes], [
        DLLFLAG="-WA"
        lib_w32gui_opt="$lib_w32gui_opt -L/exet:nt/su:windows:4.0"
      ])
      AS_IF([test "x$POCC" = xyes], [
        POCC_LDFLAGS="$POCC_LDFLAGS -subsystem:windows "
      ])
    ], [
      lib_w32gui_opt='-lgdi32 -lcomctl32 -lcomdlg32 -lole32'
      lib_user32_opt='-luser32'
      LDFLAGS="-mwindows $LDFLAGS"
      INTERFACE_SRCS="$INTERFACE_SRCS w32g_ini.c w32g_pref.c w32g_syn_escaped.c w32g_utl.c winsyn_c.c rtsyn_common.c rtsyn_winmm.c"
    ])
  ])


dnl Windows GUI
AM_CONDITIONAL(ENABLE_W32GUI, false)
CONFIG_INTERFACE(w32gui, W32GUI, w,
  AS_HELP_STRING([--enable-w32gui], [Enable Windows GUI interface    (default is no)]),
  [], [
    W32G_GUI=yes
    AS_IF([test "x$VCPP" = xyes || test "x$BORLANDC" = xyes || test "x$WATCOM_C" = xyes || test "x$DMC" = xyes || test "x$POCC" = xyes], [
      INTERFACE_SRCS="$INTERFACE_SRCS w32g_c.c w32g_ini.c w32g_i.c w32g_playlist.c w32g_utl.c w32g_pref.c w32g_subwin.c w32g_subwin2.c w32g_subwin3.c w32g_ut2.c w32g_dib.c  wrdt_w32g.c w32g_mag.c"
      lib_w32gui_opt='gdi32.lib comctl32.lib comdlg32.lib ole32.lib'
      lib_user32_opt='user32.lib'
      AS_IF([test "x$VCPP" = xyes],[
        VCPP_LDFLAGS="$VCPP_LDFLAGS -subsystem:windows "
      ])
      AS_IF([test "x$BORLANDC" = xyes], [
        BORLANDC_START='C0W32.OBJ'
        CFLAGS="$CFLAGS -tW"
        lib_w32gui_opt="-aa $lib_w32gui_opt"
      ])
      AS_IF([test "x$WATCOM_C" = xyes], [
        CFLAGS="$CFLAGS -bw"
        WATCOM_LDFLAGS="$WATCOM_LDFLAGS SYS nt_win"
      ])
      AS_IF([test "x$DMC" = xyes], [
        lib_w32gui_opt="$lib_w32gui_opt -L/SU:window"
        DLLFLAG="-WA"
      ])
      AS_IF([test "x$POCC" = xyes], [
        POCC_LDFLAGS="$POCC_LDFLAGS -subsystem:windows "
      ])
    ], [
      lib_w32gui_opt='-lgdi32 -lcomctl32 -lcomdlg32 -lole32'
      lib_user32_opt='-luser32'
      LDFLAGS="-mwindows $LDFLAGS"
      INTERFACE_SRCS="$INTERFACE_SRCS w32g_c.c w32g_ini.c w32g_i.c w32g_playlist.c w32g_utl.c w32g_pref.c w32g_subwin_escaped.c w32g_subwin2.c w32g_subwin3.c w32g_ut2.c w32g_dib.c  wrdt_w32g.c w32g_mag.c"
    ])
  ])

dnl UMP configuration
AM_CONDITIONAL(ENABLE_PLUGIN, false)
CONFIG_INTERFACE(ump, PLUGIN, p,
  AS_HELP_STRING([--enable-ump], [UMP configuration               (default is no)]),
  [ AS_IF([test ! -d ump], [
	AC_MSG_ERROR(UMP Package is not exists.  Can't configure it.)
    ])
    AC_CHECK_HEADER(X11/xpm.h,,AC_MSG_ERROR([UMP Package needs xpm.h[,] but could not find it.]))
    AC_CHECK_LIB(Xpm,XpmCreatePixmapFromData,:,AC_MSG_ERROR([UMP Package needs libXpm.a[,] but could not find it.]))
    AS_IF([test "x$have_xext" = xyes], [
      lib_xext_opt=-lXext
    ])
    AS_IF([test "x$have_xprelibs" = xyes], [
      lib_xprelibs_opt='-lSM -lICE'
    ])
    lib_xmu_opt=-lXmu
    lib_xt_opt=-lXt
  ])

dnl Window Driver interface
AC_ARG_ENABLE(windrv,
  AS_HELP_STRING([--enable-windrv], [Windows Driver interface(requires winsyn) ]),
  [ AS_IF([test "$enableval" = "yes"], [
      AS_IF([test "x$VCPP" != "xyes" && test "x$MINGWGCC" != "xyes" && test "x$BORLANDC" != "xyes" && test "x$WATCOM_C" != "xyes" && test "x$DMC" != "xyes" && test "x$POCC" != "xyes"], [
	AC_MSG_ERROR(windrv: Only Support VC++ or Mingw or Borland C or Open Watcom PellesC and Digital Mars)
      ],[test "x$WINSYN" != "xyes"], [
	AC_MSG_ERROR(windrv: Driver must have winsyn interface)
      ], [
        AC_DEFINE(WINDRV,1,Define to 1 if you cpmpile windos driver.)
        WINDRV=yes
        AS_IF([test "x$WATCOM_C" = "xyes"], [DLLFLAG="-bd" ])
        AS_IF([test "x$DMC" = "xyes"], [ DLLFLAG="-WD" ])
        CFLAGS="$CFLAGS -DANOTHER_MAIN "
      ])
    ])
  ])
CFLAGS="$CFLAGS $DLLFLAG "

dnl Offix support
dnl this rely on  CFLAGS and LIBS
AC_ARG_ENABLE(offix,
  AS_HELP_STRING([--enable-offix], [Enable offix support            (default is no)]),
  [ AS_IF([test "$enableval" = "yes"], [
      KEEPCPPFLAGS=$CPPFLAGS
      KEEPLIBS=$LIBS
      KEEPLDFLAGS=$LDFLAGS
      CPPFLAGS="$CPPFLAGS $offix_include_dir"
      LDFLAGS="$LDFLAGS $offix_lib_dir"
      LIBS="$LIBS $lib_xmu_opt $lib_xt_opt $lib_xprelibs_opt $lib_xext_opt -lX11"
      AC_CHECK_LIB(Dnd,DndInitialize,[
	LIBS=$KEEPLIBS
	lib_offix_opt="-lDnd"
	AC_DEFINE(OFFIX,1,Define to 1 if you need offix support)
      ],
      [ LDFLAGS=$KEEPLDFLAGS
	CPPFLAGS=$KEEPCPPFLAGS
	LIBS=$KEEPLIBS
      ])
    ])
  ])

dnl Network section
AC_ARG_ENABLE(network,
  AS_HELP_STRING([--enable-network], [Enable network support          (default is no)]),
  [ AS_IF([test "$enableval" = "yes"], [
      AC_DEFINE(SUPPORT_SOCKET,1,Define to 1 if you need network support)
    ])
  ])
AM_CONDITIONAL(ENABLE_NETWORK, test "x$enable_network" = "xyes")

dnl Sound Spectrogram Viewer
AC_ARG_ENABLE(spectrogram,
  AS_HELP_STRING([--enable-spectrogram], [Enable Sound Spectrogram Viewer (default is no)]),
  [ AS_IF([test "$enableval" = "yes"], [
      AS_IF([test "x$with_x" != xyes], [
	AC_MSG_ERROR(spectrogram: --with-x option must be specified)
      ])
      AC_DEFINE(SUPPORT_SOUNDSPEC,1,Define to 1 if you need spectrogram vewer.)
    ])
  ])
AM_CONDITIONAL(ENABLE_SOUND_SPEC, test "x$enable_spectrogram" = "xyes")

dnl Wave Spline Interpolations
AC_ARG_ENABLE(spline,
  AS_HELP_STRING([--enable-spline=[method]],
    [Specify spline method.  one of no,linear,cubic,lagrange,newton,gauss (default is linear)]),
  [ case "x$enableval" in
      xlinear)
        AC_DEFINE(DEFAULT_RESAMPLATION,resample_linear,Define resampler.)
	;;
      xcubic)
        AC_DEFINE(DEFAULT_RESAMPLATION,resample_cspline,Define resampler.)
	;;
      xlagrange)
        AC_DEFINE(DEFAULT_RESAMPLATION,resample_lagrange,Define resampler.)
	;;
      xnewton)
        AC_DEFINE(DEFAULT_RESAMPLATION,resample_newton,Define resampler.)
	;;
      xgauss)
        AC_DEFINE(DEFAULT_RESAMPLATION,resample_gauss,Define resampler.)
	;;
      xno)
        AC_DEFINE(DEFAULT_RESAMPLATION,resample_none,Define resampler.)
	;;
      *)
	AC_MSG_ERROR(Invalid method of --enable-spline)
	;;
    esac ])

dnl WRD interface
AC_ARG_ENABLE(wrd,
  AS_HELP_STRING([--enable-wrd], [Enable WRD interface for X      (default is no)]),
  [ AS_IF([test "$enableval" = "yes"], [
      AS_IF([test "x$with_x" = xyes], [
        LIBS="-lX11 $LIBS"
      ], [
	AC_MSG_ERROR(wrd: --with-x option must be specified)
      ])
      AC_DEFINE(WRDT_X,1,Define to 1 if you need wrd support for X.)
      enable_sherry_wrd=yes
      AC_CHECK_LIB(z,zlibVersion,:,enable_sherry_wrd=no)
      AC_CHECK_HEADER(png.h,,enable_sherry_wrd=no)
      AC_CHECK_LIB(png,png_init_io,:,enable_sherry_wrd=no,-lz)
      AS_IF([test "$enable_sherry_wrd" = yes], [
	AC_DEFINE(ENABLE_SHERRY,1,Define to 1 if you enable Sherry WRD)
	lib_zip_opt=-lz
	lib_png_opt=-lpng
      ], [
	 AC_MSG_WARN([Sherry WRD is disabled: png.h, libpng.a, libz.a are required])
      ])
      AS_IF([test "x$have_xext" = xyes], [
	lib_xext_opt=-lXext
      ])
    ])
  ])


dnl end of interfaces


#
# Finish up
#

AM_CONDITIONAL(ENABLE_WRD, test "x$enable_wrd" = "xyes")
AM_CONDITIONAL(W32G_GUI, test "x$W32G_GUI" = xyes)
AM_CONDITIONAL(WINDRV, test "x$WINDRV" = xyes)
AM_CONDITIONAL(MSYS, test "x$MSYS" = xyes)
AM_CONDITIONAL(VCPP, test "x$VCPP" = xyes)
AM_CONDITIONAL(POCC, test "x$POCC" = xyes)
AM_CONDITIONAL(BORLANDC, test "x$BORLANDC" = xyes)
AM_CONDITIONAL(WATCOM_C, test "x$WATCOM_C" = xyes)
AM_CONDITIONAL(DMC, test "x$DMC" = xyes)
AM_CONDITIONAL(MINGWGCC, test "x$MINGWGCC" = xyes)

AM_CONDITIONAL(W32READDIR, test "x$W32READDIR" = "xyes")

SET_UNIQ_WORDS(LDFLAGS,$LDFLAGS)
SET_UNIQ_WORDS(SHLDFLAGS,$SHLDFLAGS)
SET_UNIQ_WORDS(CFLAGS,$EXTRACFLAGS $CFLAGS)
SET_UNIQ_WORDS(CPPFLAGS,$CPPFLAGS $EXTRADEFS)

AS_IF([test "x$oss_device" != x], [
  AC_DEFINE_UNQUOTED(OSS_DEVICE,"$oss_device", oss device name)
])

AS_IF([test "x$TIMIDITY_OUTPUT_ID" != x],[
  AC_DEFINE_UNQUOTED(TIMIDITY_OUTPUT_ID,"$TIMIDITY_OUTPUT_ID", the output specification)
])

AS_IF([test "x$au_enable_nas"      = "xyes" -o \
            "x$enable_motif"       = "xyes" -o \
            "x$enable_tcltk"       = "xyes" -o \
            "x$enable_xaw"         = "xyes" -o \
            "x$enable_xskin"       = "xyes" -o \
            "x$enable_spectrogram" = "xyes"], [
  dnl Order of X-library is: -lXdnd -lXm -lXaw -lXft -lXmu -lXt -lSM -lICE -lXext -lX11
  LIBS="$lib_offix_opt $lib_xm_opt $lib_xaw_opt $lib_xft_opt $lib_xmu_opt $lib_xt_opt $lib_xprelibs_opt $lib_xext_opt -lX11 $LIBS"
])
LIBS="$LIBS $lib_dl_opt $lib_png_opt $lib_zip_opt $lib_user32_opt $lib_w32gui_opt $EXTRALIBS"
SHLD="$SHLD $SHLDFLAGS"

AC_SUBST(BORLANDC_START)
AC_SUBST(BORLANDC_LDFLAGS)
AC_SUBST(SHELL)
AC_SUBST(timidity_LDFLAGS)
AC_SUBST(WATCOM_LDFLAGS)
AC_SUBST(DMC_LDFLAGS)
AC_SUBST(VCPP_LDFLAGS)
AC_SUBST(POCC_LDFLAGS)
AC_SUBST(SYSEXTRAS)
AC_SUBST(EXTRALIBS)
AC_SUBST(NETSRCS)
AC_SUBST(ELFILES)
AC_SUBST(SHLD)
AC_SUBST(SHCFLAGS)
AC_SUBST(dynamic_targets)
AC_SUBST(so)
AC_SUBST(LN_S)
AC_SUBST(TCLSH)
AC_SUBST(tcltk_dep)
AC_SUBST(program_transform_name)
AC_SUBST(INTERFACE_SRCS)
AC_SUBST(pkgdatadir)
AC_SUBST(pkglibdir)

AC_CONFIG_FILES([
  Makefile
  autoconf/Makefile
  common.makefile
  configs/Makefile
  doc/Makefile
  doc/C/Makefile
  doc/ja_JP.eucJP/Makefile
  interface/Makefile
  interface/motif_bitmaps/Makefile
  interface/bitmaps/Makefile
  interface/pixmaps/Makefile
  libarc/Makefile
  libunimod/Makefile
  timidity/Makefile
  windrv/Makefile
  utils/Makefile
  script/Makefile
])
AC_OUTPUT
