dnl Process this file with autoconf to produce a configure script.
dnl
dnl Copyright (c) by Jaroslav Kysela <perex@suse.cz>

AC_INIT(acore/sound.patch)
AC_PREFIX_DEFAULT(/usr)
CONFIG_SND_VERSION="0.9.6"

dnl Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_INSTALL

dnl the following should be checked, but they are not used...
AR=ar
AS=as
AC_SUBST(AR)
AC_SUBST(AS)

dnl Checks for header files.
AC_HEADER_STDC
AC_CONFIG_HEADER(include/config.h include/config1.h include/version.h)
dnl AC_CHECK_HEADERS(linux/fs.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_HEADER_TIME

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL

dnl Check for current directory
AC_MSG_CHECKING(for current directory)
SRCDIR=`/bin/pwd`
AC_SUBST(SRCDIR)
AC_MSG_RESULT($SRCDIR)

dnl Check for cross compile...
AC_MSG_CHECKING(cross compile)
AC_ARG_WITH(cross,
  [  --with-cross=dir        give the cross-compile prefix],
  crossprefix="$withval",
  crossprefix="")
CROSS_COMPILE="$crossprefix"
AC_SUBST(CROSS_COMPILE)
AC_MSG_RESULT($CROSS_COMPILE)

if test "$crossprefix"; then
# modify CC, CPP and maybe some other variables. CC is set to
# e.g. /usr/local/bin/gcc by autoconf - this is then modified 
# to arm-linux-/usr/local/bin/gcc in Makefile.conf - that is bad - so
# cut the path out (but save optional params - e.g. gcc -E for CPP) 
echo $CC | grep ' ' >/dev/null && CC_save=`echo "$CC" | cut -d' ' -f2-` 
CC="`basename $CC` $CC_save"

echo $CPP | grep ' ' >/dev/null && CPP_save=`echo "$CPP" | cut -d' ' -f2-`
CPP="`basename $CPP` $CPP_save"
fi

dnl Check for directory with kernel source...
AC_MSG_CHECKING(for directory with kernel source)
AC_ARG_WITH(kernel,
  [  --with-kernel=dir       give the directory with kernel sources]
  [                        [/usr/src/linux]],
  kerneldir="$withval",
  if test -d "/lib/modules/`uname -r`/build" -o -L "/lib/modules/`uname -r`/build"; then
    kerneldir="/lib/modules/`uname -r`/build"
  else
    kerneldir="/usr/src/linux"
  fi
)
AC_DEFINE_UNQUOTED(CONFIG_SND_KERNELDIR, "$kerneldir")
CONFIG_SND_KERNELDIR="$kerneldir"
AC_SUBST(CONFIG_SND_KERNELDIR)
AC_MSG_RESULT($kerneldir)

dnl Check for kernel version...
AC_MSG_CHECKING(for kernel version)
if ! test -r $CONFIG_SND_KERNELDIR/include/linux/version.h; then
  cat << EOF
The file $CONFIG_SND_KERNELDIR/include/linux/version.h does not exist.
Please, install the package with full kernel sources for your distribution
or use --with-kernel=dir option to specify another directory with kernel
sources (default is /usr/src/linux).
EOF
  exit 1
fi
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_CACHE_VAL(kaversion,
[AC_TRY_RUN([
#include <stdio.h>
#include <ctype.h>
#include "$CONFIG_SND_KERNELDIR/include/linux/version.h"
int main()
{
 FILE *f;
 char kversion[128];
 char kpatchlevel[128];
 char ksublevel[128];
 char kextra[128];
 char *ptr, *dptr;
#ifdef UTS_RELEASE
 f=fopen("./conftestdata","w");
 if (f) {
   for (ptr = UTS_RELEASE, dptr = kversion; *ptr != '\0' && isdigit(*ptr); ptr++, dptr++)
     *dptr = *ptr;
   *dptr = '\0';
   if (*ptr == '.')
     ptr++;
   for (dptr = kpatchlevel; *ptr != '\0' && isdigit(*ptr); ptr++, dptr++)
     *dptr = *ptr;
   *dptr = '\0';
   if (*ptr == '.')
     ptr++;
   for (dptr = ksublevel; *ptr != '\0' && isdigit(*ptr); ptr++, dptr++)
     *dptr = *ptr;
   *dptr = '\0';
   for (dptr = kextra; *ptr != '\0'; ptr++, dptr++)
     *dptr = *ptr;
   *dptr = '\0';   
   fprintf(f,"%s:%s:%s:%s\n",kversion,kpatchlevel,ksublevel,kextra);
   fclose(f);
   }
 exit(0);
#else
 exit(1);
#endif
}],kaversion=`cat conftestdata`,
kaversion="",
kaversion="")])
CFLAGS="$ac_save_CFLAGS"
kversion=`echo $kaversion | cut -d : -f 1`
kpatchlevel=`echo $kaversion | cut -d : -f 2`
ksublevel=`echo $kaversion | cut -d : -f 3`
kextraversion=`echo $kaversion | cut -d : -f 4`
kversion=`expr $kversion + 0`
kpatchlevel=`expr $kpatchlevel + 0`
ksublevel=`expr $ksublevel + 0`
if test -z "$kversion" || test -z "$kpatchlevel" || test -z "$ksublevel"; then
  echo "failed (probably missing $CONFIG_SND_KERNELDIR/include/linux/version.h)"
  exit 1
fi
kaversion="$kversion.$kpatchlevel.$ksublevel$kextraversion"
AC_SUBST(kaversion)
AC_SUBST(kversion)
AC_SUBST(kpatchlevel)
AC_SUBST(ksublevel)
AC_SUBST(kextraversion)
AC_MSG_RESULT($kaversion)

dnl Check for GCC version...
dnl AC_MSG_CHECKING(for GCC version)
dnl ac_save_CFLAGS="$CFLAGS"
dnl CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
dnl AC_CACHE_VAL(kernel_gcc,
dnl [AC_TRY_RUN([
dnl #include <stdio.h>
dnl #include <ctype.h>
dnl #include "$CONFIG_SND_KERNELDIR/include/linux/compile.h"
dnl int main()
dnl {
dnl  FILE *f;
dnl  char compiler[128];
dnl  char *ptr, *dptr;
dnl #ifdef LINUX_COMPILER
dnl  f=fopen("./conftestdata","w");
dnl  if (f) {
dnl    for (ptr = LINUX_COMPILER, dptr = compiler; *ptr != '\0' && *ptr != ' ' && *ptr != '\t'; ptr++, dptr++)
dnl      *dptr = *ptr;
dnl    if (*ptr != '\0' && (*ptr == ' ' || *ptr == '\t'))
dnl      ptr++;
dnl    if (!strncmp(ptr, "version", 7))
dnl 	ptr += 7;
dnl    if (*ptr != '\0' && (*ptr == ' ' || *ptr == '\t'))
dnl      ptr++;
dnl    *dptr++ = ' ';
dnl    for (; *ptr != '\0' && *ptr != '\n'; ptr++, dptr++)
dnl      *dptr = *ptr;
dnl    *dptr = '\t';
dnl    *dptr = '\0';
dnl    fprintf(f,"%s\n",compiler);
dnl    fclose(f);
dnl    }
dnl  exit(0);
dnl #else
dnl  exit(1);
dnl #endif
dnl }],kernel_compiler=`cat conftestdata`,
dnl kernel_compiler="",
dnl kernel_compiler="")])
dnl CFLAGS="$ac_save_CFLAGS"
dnl my_compiler=`$CROSS_COMPILE$CC --version | head -n 1`
dnl
dnl Test section, uncomment any of these double lines to verify the bellow code:
dnl
dnl kernel_compiler="gcc-Version 3.3"
dnl my_compiler="gcc (GCC) 3.3"
dnl 
dnl kernel_compiler="gcc 3.2"
dnl my_compiler="gcc (GCC) 3.2"
dnl
dnl kernel_compiler="gcc 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)"
dnl my_compiler="gcc-3.2.2 (GCC) 3.2.2 (Mandrake Linux 9.1 3.2.2-3mdk)"
dnl
dnl kernel_compiler="gcc egcs-2.91.66 19990314/Linux (egcs-1.1.2 release)"
dnl my_compiler="egcs-2.91.66"
dnl
dnl kernel_compiler="gcc 2.95.3 20010315 (release)"
dnl my_compiler="2.95.3"
dnl

AC_DEFUN(CHECK_COMPILER, [
  typevar=$2
  versionvar=$3
  ac_compiler_type=""
  ac_compiler_version=""
  for i in $1; do
    case $i in
    gcc-[[0-9]]*|*-gcc-[[0-9]]*)
      if test -z "$ac_compiler_type"; then
        ac_compiler_type=gcc
      fi
      if test -z "$ac_compiler_version"; then
        ac_compiler_version=`echo $i | sed -e 's/^.*gcc-\([0-9.]\+\).*$/\1/'`
      fi
      ;;
    *gcc*)
      if test -z "$ac_compiler_type"; then
        ac_compiler_type=gcc
      fi
      ;;
    egcs-*)
      ac_compiler_type=egcs
      if test -z "$ac_compiler_version"; then
        ac_compiler_version=`echo $i | sed -e 's/egcs-\(.\+\)$/\1/'`
      fi
      ;;
    *cc*)
      if test -z "$ac_compiler_type"; then
        ac_compiler_type=cc
      fi
      ;;
    [[0-9]].[[0-9]]*)
      if test -z "$ac_compiler_version"; then
        ac_compiler_version="$i"
      fi
      ;;
    esac
  done
  eval $typevar="$ac_compiler_type"
  eval $versionvar="$ac_compiler_version"
])

CHECK_COMPILER($kernel_compiler, kernel_compiler_type, kernel_compiler_version)
CHECK_COMPILER($my_compiler, my_compiler_type, my_compiler_version)
if test -z "$my_compiler_type"; then
  my_compiler_type="gcc"
fi
AC_MSG_RESULT(Kernel compiler: $kernel_compiler Used compiler: $my_compiler);
if test -z "$kernel_compiler"; then
  echo
  echo "*** NO PREDEFINED KERNEL COMPILER IS DETECTED"
  echo "*** Assuming the same compiler is used with the current system compiler."
  echo
  echo "*** Please make sure that the same compiler version was used for building kernel."
  echo
else
if test "$my_compiler_type" != "$kernel_compiler_type"; then
  echo "Fatal error: Compiler type does not match"
  echo "Decoded kernel compiler: type=$kernel_compiler_type version=$kernel_compiler_version"
  echo "Decoded used compiler: type=$my_compiler_type version=$my_compiler_version"
  echo "Please, send ./configure output to <alsa-devel@alsa-project.org>"
  exit 1
fi
if test "$my_compiler_type" = "gcc" ; then
  kernel_major=`echo $kernel_compiler_version | cut -d '.' -f 1`
  my_major=`echo $kernel_compiler_version | cut -d '.' -f 1`
  if test $kernel_major -eq 2 -a $my_major -eq 3 ; then
    echo "Fatal error: Kernel is compiled with GCC 2.x and you are trying to use GCC 3.x."
    echo "             These two version of GCC are incompatible for binary code."
    exit 1
  fi
  if test $kernel_major -eq 3 -a $my_major -eq 2 ; then
    echo "Fatal error: Kernel is compiled with GCC 3.x and you are trying to use GCC 2.x."
    echo "             These two version of GCC are incompatible for binary code."
    exit 1
  fi
fi
fi
dnl compiler version check

AC_DEFUN(CHECK_KERNEL_HEADER, [
  AC_MSG_CHECKING(for kernel $1)
  if test -f "$CONFIG_SND_KERNELDIR/include/$1"; then
    AC_MSG_RESULT("yes")
    if test -f include/$1; then
      echo "Removing a dummy $1."
      rm -f include/$1
    fi
  else
    AC_MSG_RESULT("no")
    if test ! -f include/$1; then
      if test -z "$2" ; then
        echo "Creating a dummy <$1>..."
        mkdir -p include/linux
        touch include/$1
      else
        echo "Creating <$1>..."
        mkdir -p include/linux
        echo "$2" > include/$1
      fi
    fi
  fi
])

dnl Check kernel configurations
AC_DEFUN(CHECK_KERNEL_CONFIG, [
  boolvar=$1
  AC_MSG_CHECKING(for $2)
  ac_save_CFLAGS="$CFLAGS"
  CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
  boolchk=""
  AC_TRY_RUN([
#include "$CONFIG_SND_KERNELDIR/include/linux/autoconf.h"
int main( void ) {
#ifndef $boolvar
  exit(1);
#else
  exit(0);
#endif
}
],
    AC_MSG_RESULT("yes");boolchk="y",
    AC_MSG_RESULT("no");boolchk="",
    AC_MSG_RESULT("unknown");boolchk=""
  )
  CFLAGS="$ac_save_CFLAGS"
  eval $boolvar="$boolchk"
])

dnl Check kernel headers for 2.2
CHECK_KERNEL_HEADER(linux/compiler.h)
CHECK_KERNEL_HEADER(linux/pm.h)
CHECK_KERNEL_HEADER(linux/spinlock.h)
CHECK_KERNEL_HEADER(linux/irq.h)
CHECK_KERNEL_HEADER(linux/threads.h)
CHECK_KERNEL_HEADER(linux/rwsem.h)
CHECK_KERNEL_HEADER(linux/gameport.h)
CHECK_KERNEL_HEADER(linux/devfs_fs_kernel.h)
CHECK_KERNEL_HEADER(linux/highmem.h)
CHECK_KERNEL_HEADER(linux/workqueue.h)
if test ! -f include/linux/workqueue.h; then
  if test "$kversion.$kpatchlevel.$ksublevel" = "2.4.20"; then
    CHECK_KERNEL_CONFIG(RED_HAT_LINUX_KERNEL, [redhat kernel])
    if test $RED_HAT_LINUX_KERNEL = y; then
      echo "It looks like you're using a RedHat 9 kernel."
      echo "Disabling their incomplete workqueue.h modification."
      mkdir -p include/linux
      touch include/linux/workqueue.h
    fi
  fi
fi
CHECK_KERNEL_HEADER(asm/hw_irq.h)
CHECK_KERNEL_HEADER(linux/jiffies.h, [#include <linux/sched.h>
])
CHECK_KERNEL_HEADER(linux/compat.h, [#include \"compat_64.h\"
])
dnl PPC headers (for 2.2 kernels)
CHECK_KERNEL_HEADER(linux/adb.h, [#include <asm/adb.h>
])
CHECK_KERNEL_HEADER(linux/cuda.h, [#include <asm/cuda.h>
])
CHECK_KERNEL_HEADER(linux/pmu.h, [#include <asm/pmu.h>
])

dnl Check for modversions...
CHECK_KERNEL_CONFIG(CONFIG_MODVERSIONS, [kernel module symbol versions])
CONFIG_SND_MVERSION=$CONFIG_MODVERSIONS
AC_SUBST(CONFIG_SND_MVERSION)
GENKSYMS="/sbin/genksyms -k $kversion.$kpatchlevel.$ksublevel"

dnl Check for PCI support...
CHECK_KERNEL_CONFIG(CONFIG_PCI, [PCI support in kernel])
AC_SUBST(CONFIG_PCI)

dnl Check for SGI/MIPS (HAL2) support...
AC_MSG_CHECKING(for SGI/MIPS (HAL2) architecture)
CONFIG_SGI=""
if test -r "$CONFIG_SND_KERNELDIR/include/asm/sgi/sgihpc.h"; then
  CONFIG_SGI="y"
fi
if test "$CONFIG_SGI" = "y"; then
  AC_MSG_RESULT("yes")
else
  AC_MSG_RESULT("no")
fi
AC_SUBST(CONFIG_SGI)


dnl Directory for modules
AC_MSG_CHECKING(for directory to store kernel modules)
AC_ARG_WITH(moddir,
  [  --with-moddir=/path     give the path for the alsa driver kernel modules]
  [                        [/lib/modules/<KVER>/misc]],
  moddir="$withval", 
  moddir_tree=
  modsubdir="misc"
# Special test for RH 5.1
  if test -d /lib/modules/preferred; then
    moddir="/lib/modules/preferred/misc"
  else
    if test -d /lib/modules/$kaversion/kernel; then
      modsubdir="kernel/sound"
      moddir="/lib/modules/$kaversion/$modsubdir"
      moddir_tree=y
    else
      moddir="/lib/modules/$kaversion/misc"
    fi
  fi
)
AC_SUBST(moddir)
AC_SUBST(modsubdir)
AC_SUBST(moddir_tree)
AC_MSG_RESULT($moddir)

dnl Verbose printk
AC_MSG_CHECKING(for verbose printk)
AC_ARG_ENABLE(verbose-printk,
  [  --enable-verbose-printk  enables verbose printk (file + line number)],
  verbose_printk="$enableval", verbose_printk="yes")
case "$verbose_printk" in
  yes)
    AC_DEFINE(CONFIG_SND_VERBOSE_PRINTK)
    AC_MSG_RESULT(on)
    ;;
  *)
    AC_MSG_RESULT(off)
    ;;
esac


dnl Debug level
AC_MSG_CHECKING(for debug level)
AC_ARG_WITH(debug,
  [  --with-debug=level      give the debug level (none,basic,memory,full,detect)],
  debug="$withval", debug="none")
case "$debug" in
  basic)
    AC_MSG_RESULT(basic)
    AC_DEFINE(CONFIG_SND_DEBUG)
    ;;
  memory)
    AC_MSG_RESULT(memory)
    AC_DEFINE(CONFIG_SND_DEBUG)
    AC_DEFINE(CONFIG_SND_DEBUG_MEMORY)
    ;;
  full)
    AC_MSG_RESULT(full)
    AC_DEFINE(CONFIG_SND_DEBUG)
    AC_DEFINE(CONFIG_SND_DEBUG_MEMORY)
    AC_DEFINE(CONFIG_SND_DEBUG_FULL)
    ;;    
  detect)
    AC_MSG_RESULT(detect)
    AC_DEFINE(CONFIG_SND_DEBUG)
    AC_DEFINE(CONFIG_SND_DEBUG_MEMORY)
    AC_DEFINE(CONFIG_SND_DEBUG_FULL)
    AC_DEFINE(CONFIG_SND_DEBUG_DETECT)
    ;;
  *)
    AC_MSG_RESULT(none)
    ;;
esac

dnl Check for PCI support (for 2.4 kernel)...
if test $kpatchlevel -ge 3; then
CHECK_KERNEL_CONFIG(CONFIG_ISA, [ISA support in kernel])
else
CONFIG_ISA=probe
fi

dnl Check processor type...
AC_MSG_CHECKING(for processor type)
CONFIG_X86=
CONFIG_ALPHA=
CONFIG_L3=
CONFIG_ARM=
CONFIG_PPC=
CONFIG_SND_BIT32_EMUL=
processor=""
rm -f processor.id
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_RUN([
#include <stdio.h>
#include "$CONFIG_SND_KERNELDIR/include/linux/autoconf.h"
int main(void) {
	FILE *file = fopen("processor.id", "w+");
	if (file == NULL)
		exit(1);
#if defined(CONFIG_M386)
	fprintf(file, "i386");
#elif defined(CONFIG_M486)
	fprintf(file, "i486");
#elif defined(CONFIG_M586)
	fprintf(file, "i586");
#elif defined(CONFIG_M586TSC)
	fprintf(file, "i586tsc");
#elif defined(CONFIG_M586MMX)
	fprintf(file, "i586mmx");
#elif defined(CONFIG_M686) || defined(CONFIG_MPENTIUMIII) || defined(CONFIG_MPENTIUM4)
	fprintf(file, "i686");
#elif defined(CONFIG_MK6)
	fprintf(file, "k6");
#elif defined(CONFIG_MK7)
	fprintf(file, "k7");
#elif defined(CONFIG_MCRUSOE)
	fprintf(file, "crusoe");
#elif defined(CONFIG_MWINCHIPC6) || defined(CONFIG_MWINCHIP2) || defined(CONFIG_MWINCHIP3D)
	fprintf(file, "mwinchip");
#elif defined(CONFIG_MCYRIXIII)
	fprintf(file, "mcyrixiii");
#elif defined(CONFIG_IA64)
	fprintf(file, "ia64");
#elif defined(CONFIG_ALPHA_GENERIC)
	fprintf(file, "alpha_generic");
#elif defined(CONFIG_ALPHA_SX164)
	fprintf(file, "alpha_sx164");
#elif defined(CONFIG_ALPHA_PYXIS)
	fprintf(file, "alpha_pyxis");
#elif defined(CONFIG_ALPHA_POLARIS)
	fprintf(file, "alpha_polaris");
#elif defined(CONFIG_EV4) || defined(CONFIG_ALPHA_EV4)
	fprintf(file, "alpha_ev4");
#elif defined(CONFIG_EV5) || defined(CONFIG_ALPHA_EV5)
	fprintf(file, "alpha_ev5");
#elif defined(CONFIG_EV6) || defined(CONFIG_ALPHA_EV6)
	fprintf(file, "alpha_ev6");
#elif defined(CONFIG_ALPHA_NONAME) || defined(CONFIG_ALPHA)
	fprintf(file, "alpha_noname");
#elif defined(CONFIG_PPC64)
	fprintf(file, "ppc64");
#elif defined(CONFIG_PPC)
	fprintf(file, "ppc");
#elif defined(CONFIG_CPU_R3000) || defined(CONFIG_CPU_R6000)
	fprintf(file, "mips");
#elif defined(CONFIG_CPU_R4300) || defined(CONFIG_CPU_R4X00)
	fprintf(file, "mips");
#elif defined(CONFIG_CPU_R5000) || defined(CONFIG_CPU_NEVADA)
	fprintf(file, "mips");
#elif defined(CONFIG_CPU_R8000) || defined(CONFIG_CPU_R10000)
	fprintf(file, "mips");
#elif defined(CONFIG_SPARC32)
	fprintf(file, "sparc");
#elif defined(CONFIG_SPARC64)
	fprintf(file, "sparc64");
#elif defined(CONFIG_X86_64)
	fprintf(file, "x86_64");
#elif defined(CONFIG_ARCH_SA1100)
	fprintf(file, "sa1100");
#elif defined(CONFIG_ARCH_PXA)
	fprintf(file, "pxa");
#elif defined(CONFIG_PARISC)
	fprintf(file, "parisc");
#else
	fclose(file);
	exit(1);
#endif
	fclose(file);
	exit(0);
}
],
  processor=`cat processor.id`;AC_MSG_RESULT($processor),
  AC_MSG_RESULT("unknown");processor="",
  AC_MSG_RESULT("unknown");processor=""
)
CFLAGS="$ac_save_CFLAGS"
rm -f processor.id
c_opts=""
LD=ld
case "$processor" in
  i386*)
    c_opts="-march=i386"
    ;;
  i486*)
    c_opts="-march=i486"
    ;;
  i586* | mwinchip)
    c_opts="-march=i586"
    ;;
  i686*)
    c_opts="-march=i686"
    ;;
  k6)
    if $CC -march=k6  -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then
      c_opts="-march=k6"
    else
      c_opts="-march=i586"
    fi
    ;;
  k7)
    if $CC -march=athlon -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then
      c_opts="-march=athlon"
    else
      if $CC -falign-functions=0 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then
        c_opts="-march=i686 -falign-functions=4"
      else
	c_opts="-march=i686 -malign-functions=4"
      fi
    fi
    ;;
  crusoe)
    if $CC -falign-functions=0 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then
      c_opts="-march=i686 -falign-functions=0 -falign-jumps=0 -falign-loops=0"
    else
      c_opts="-march=i686 -malign-functions=0 -malign-jumps=0 -malign-loops=0"
    fi
    ;;
  mcyrixiii)
    if $CC -march=c3 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then
      c_opts="-march=c3"
    else
      c_opts="-march=i486"
    fi
    if $CC -falign-functions=0 -falign-jumps=0 -falign-loops=0 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then
      c_opts="$c_opts -falign-functions=0 -falign-jumps=0 -falign-loops=0"
    else
      c_opts="$c_opts -malign-functions=0 -malign-jumps=0 -malign-loops=0"
    fi
    ;;
  ia64)
    c_opts="-Wa,-x -ffixed-r13 -mfixed-range=f10-f15,f32-f127 -funwind-tables -falign-functions=32"
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    CONFIG_IA64=y
    ;;
  alpha*)
    c_opts="-mno-fp-regs -ffixed-8"
    if $CC -mcpu=pca56 -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then
      have_pca56=yes
    fi
    if $CC -mcpu=ev5 -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then
      case "$processor" in
      alpha_generic)
        c_opts="$c_opts -mcpu=ev5"
        ;;
      alpha_sx164|alpha_polaris)
	if test x$have_pca56 = xyes; then
          c_opts="$c_opts -mcpu=pca56"
	else
          c_opts="$c_opts -mcpu=ev56"
        fi
	;;
      alpha_pyxis)
        c_opts="$c_opts -mcpu=ev56"
        ;;
      alpha_ev4)
        c_opts="$c_opts -mcpu=ev4"
        ;;
      alpha_ev6)
        if $CC -mcpu=ev6 -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then
	  c_opts="$c_opts -mcpu=ev6"
	elif test x$have_pca56 = xyes; then
	  c_opts="$c_opts -mcpu=pca56"
        else
	  c_opts="$c_opts -mcpu=ev56"
        fi
        ;;
      esac
    fi
    c_opts="$c_opts -Wa,-mev6"
    processor="alpha"
    CONFIG_ALPHA=y
    ;;
  ppc)
    c_opts="-D__powerpc__ -fsigned-char -fno-builtin -msoft-float -ffixed-r2 -Wno-uninitialized -mmultiple -mstring"
    CONFIG_PPC=y
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  ppc64)
    c_opts="-D__powerpc__ -fsigned-char -msoft-float -Wno-uninitialized -mminimal-toc -fno-builtin"
    CONFIG_SND_BIT32_EMUL=m
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  mips*)
    c_opts="-mcpu=r4600 -G 0 -mips2 -fno-pic -mno-abicalls -mlong-calls"
    processor="mips"
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  sparc)
    IS_EGCS=n
    NEW_GAS=n
    test $CC -m32 -S -o /dev/null -xc /dev/null >/dev/null 2>&1 && IS_EGCS=y
    test $LD --version 2>&1 | grep 'elf64_sparc' > /dev/null && NEW_GAS=y
    if test $NEW_GAS = y; then
      LD="$LD -m elf32_sparc"
    fi
    if test $IS_EGCS = y; then
      c_opts="-mno-fpu -fcall-used-g5 -fcall-used-g7"
    else
      c_opts="-m32 -mno-fpu -fcall-used-g5 -fcall-used-g7"
    fi
    processor="sparc";
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  sparc64)
    CC=gcc
    test gcc -m64 -S -o /dev/null -xc /dev/null >/dev/null 2>&1 || CC=sparc64-linux-gcc
    NEW_GCC=n
    NEW_GAS=n
    CC_UNDECL=""
    $CC -m64 -mcmodel=medlow -S -o /dev/null -xc /dev/null >/dev/null 2>&1 && NEW_GCC=y
    $LD --version 2>&1 | grep 'elf64_sparc' > /dev/null && NEW_GAS=y
    $CC -c -x assembler /dev/null -Wa,--help | grep undeclared-regs > /dev/null || CC_UNDECL="-Wa,--undeclared-regs"
    if test $NEW_GAS != y; then
      LD=sparc64-linux-ld
    else
      LD="$LD -m elf64_sparc"
    fi
    if test $NEW_GCC=y; then
      c_opts="-m64 -mno-fpu -mcpu=ultrasparc -mcmodel=medlow -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare $CC_UNDECL"
    else
      c_opts="-mno-fpu -mtune=ultrasparc -mmedlow -ffixed-g4 -fcall-used-g5 -fcall-used-g7 -Wno-sign-compare"
    fi
    processor="sparc64"
    CONFIG_SND_BIT32_EMUL=m
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  x86_64)
    LD="ld -m elf_x86_64 -e stext"
    c_opts="-mno-red-zone -mcmodel=kernel -fno-reorder-blocks -fno-strength-reduce -finline-limit=2000"
    CONFIG_SND_BIT32_EMUL=m
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  sa1100)
    c_opts="-march=armv4 -mtune=strongarm1100 -msoft-float"
    CONFIG_ARM=y
    CONFIG_L3=y
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  pxa)
    c_opts="-O2 -mapcs-32 -march=armv4 -Wa,-mxscale -mtune=strongarm -mshort-load-bytes -msoft-float"
    CONFIG_ARM=y
    CONFIG_L3=y
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  parisc)
    c_opts="-mno-space-regs -mfast-indirect-calls -mschedule=7200 -mdisable-fpregs"
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
  *)
    processor="unknown"
    test "$CONFIG_ISA" = "probe" && CONFIG_ISA=
    ;;
esac

dnl set ia32 (X86)
case "$processor" in
  i?86*|k?|crusoe|mcyrixiii|mwinchip)
    if $CC -mpreferred-stack-boundary=2 -S -o /dev/null -xc /dev/null >/dev/null 2>&1; then
      c_opts="-mpreferred-stack-boundary=2 $c_opts"
      CONFIG_X86=y
    fi
    if test -d $CONFIG_SND_KERNELDIR/include/asm-i386/mach-default; then
	AC_MSG_CHECKING(for i386 machine type)
	machine="default"
	ac_save_CFLAGS="$CFLAGS"
	CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
	rm -f machine.id
	AC_TRY_RUN([
#include <stdio.h>
#include "$CONFIG_SND_KERNELDIR/include/linux/autoconf.h"
int main(void) {
	FILE *file = fopen("machine.id", "w+");
	if (file == NULL)
		exit(1);
#if defined(CONFIG_X86_VOYAGER)
	fprintf(file, "voyager");
#elif defined(CONFIG_X86_VISWS)
	fprintf(file, "visws");
#elif defined(CONFIG_X86_NUMAQ)
	fprintf(file, "numaq");
#elif defined(CONFIG_X86_BIGSMP)
	fprintf(file, "bigsmp");
#elif defined(CONFIG_X86_SUMMIT)
	fprintf(file, "summit");
#elif defined(CONFIG_X86_PC9800)
	fprintf(file, "pc9800");
#else
	fprintf(file, "default");
#endif
	fclose(file);
	exit(0);
}
],      
	machine=`cat machine.id`;AC_MSG_RESULT($machine))
	CFLAGS="$ac_save_CFLAGS"
	rm -f machine.id
	c_opts="$c_opts -I\$(CONFIG_SND_KERNELDIR)/include/asm-i386/mach-$machine"
    fi
    ;;
esac

dnl ia32 and alpha
test "$CONFIG_ISA" = "probe" && CONFIG_ISA=y

c_opts="-O2 $c_opts"
AC_SUBST(processor)
AC_SUBST(LD)
AC_SUBST(CONFIG_X86)
AC_SUBST(CONFIG_ALPHA)
AC_SUBST(CONFIG_L3)
AC_SUBST(CONFIG_ARM)
AC_SUBST(CONFIG_PPC)
AC_SUBST(CONFIG_ISA)
AC_SUBST(CONFIG_PARISC)
AC_SUBST(CONFIG_SND_BIT32_EMUL)
test "$CONFIG_ISA" = "y" && AC_DEFINE(CONFIG_SND_ISA)
test "$CONFIG_SND_BIT32_EMUL" = "m" && AC_DEFINE(CONFIG_SND_BIT32_EMUL_MODULE)

dnl Check for SMP...
CHECK_KERNEL_CONFIG(CONFIG_SMP, [SMP])
if test "$CONFIG_SMP" = "y"; then
  GENKSYMS="$GENKSYMS -p smp_"
  c_opts="$c_opts -D__SMP__ -DCONFIG_SMP"
  msmp=1
else
  msmp=""
fi
AC_SUBST(msmp)

dnl Check for ISA PnP driver in kernel...
AC_MSG_CHECKING(for ISA PnP driver in kernel)
CONFIG_ISAPNP_KERNEL=
if test -r $CONFIG_SND_KERNELDIR/include/linux/isapnp.h; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(CONFIG_ISAPNP_KERNEL)
  CONFIG_ISAPNP_KERNEL=y
else
  AC_MSG_RESULT(no)  
fi
AC_SUBST(CONFIG_ISAPNP_KERNEL)

dnl Check for PnP layer (2.5+) in kernel...
AC_MSG_CHECKING(for PnP driver in kernel)
CONFIG_PNP_KERNEL=
if test -r $CONFIG_SND_KERNELDIR/include/linux/pnp.h; then
  AC_MSG_RESULT(yes)
  AC_DEFINE(CONFIG_PNP_KERNEL)
  CONFIG_PNP_KERNEL=y
else
  AC_MSG_RESULT(no)  
fi
AC_SUBST(CONFIG_PNP_KERNEL)

dnl Check for ISA PnP support...
if test "$CONFIG_ISAPNP_KERNEL" = y; then
  CHECK_KERNEL_CONFIG(CONFIG_ISAPNP, [Kernel ISA-PnP support])
  if test "$CONFIG_ISAPNP" != "y"; then
    CHECK_KERNEL_CONFIG(CONFIG_ISAPNP_MODULE, [Kernel ISA-PnP module support])
    if test "$CONFIG_ISAPNP_MODULE" = "y"; then
      CONFIG_ISAPNP=y
    fi
  fi
else
  AC_MSG_CHECKING(for ISA PnP support)
  AC_ARG_WITH(isapnp,
    [  --with-isapnp=yes,no,auto  driver will (not) be compiled with ISA PnP support],
    pnp="$withval", pnp="yes")
  if test "$pnp" = "auto"; then
    if test -f /proc/isapnp; then
      pnp=yes
    fi
  fi
  if test "$pnp" = "yes"; then
    CONFIG_ISAPNP=y
    AC_MSG_RESULT(yes)
  else
    CONFIG_ISAPNP=
    AC_MSG_RESULT(no)
  fi
fi

AC_SUBST(CONFIG_ISAPNP)
if test "$CONFIG_ISAPNP" = "y"; then
  AC_DEFINE(CONFIG_ISAPNP)
  CONFIG_PNP=$CONFIG_ISAPNP
  AC_DEFINE(CONFIG_PNP)
fi

dnl Check for strlcpy...
AC_MSG_CHECKING(for strlcpy)
strlcpy="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="-Wall -Werror $CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_COMPILE([
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#include "$CONFIG_SND_KERNELDIR/include/linux/kernel.h"
],[
  char buf[128];
  strlcpy(buf, "abcd", sizeof(buf));
],
    AC_MSG_RESULT("yes");strlcpy="1",
    AC_MSG_RESULT("no");strlcpy="0",
    AC_MSG_RESULT("unknown");strlcpy="0"
)
CFLAGS=$ac_save_CFLAGS
CONFIG_HAVE_STRLCPY=$strlcpy
dnl AC_SUBST(CONFIG_HAVE_STRLCPY)
if test "$CONFIG_HAVE_STRLCPY" = "1"; then
  AC_DEFINE(CONFIG_HAVE_STRLCPY)
fi

dnl Check for snprintf...
AC_MSG_CHECKING(for snprintf)
snprintf="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="-Wall -Werror $CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_COMPILE([
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#include "$CONFIG_SND_KERNELDIR/include/linux/kernel.h"
],[
  char buf[128];
  snprintf(buf, sizeof(buf), "abcd");
],
    AC_MSG_RESULT("yes");snprintf="1",
    AC_MSG_RESULT("no");snprintf="0",
    AC_MSG_RESULT("unknown");snprintf="0"
)
CFLAGS=$ac_save_CFLAGS
CONFIG_HAVE_SNPRINTF=$snprintf
dnl AC_SUBST(CONFIG_HAVE_SNPRINTF)
if test "$CONFIG_HAVE_SNPRINTF" = "1"; then
  AC_DEFINE(CONFIG_HAVE_SNPRINTF)
fi

dnl Check for vmalloc_to_page...
AC_MSG_CHECKING(for vmalloc_to_page)
vmalloc_to_page="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_COMPILE([
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#include "$CONFIG_SND_KERNELDIR/include/linux/time.h"
#include "$CONFIG_SND_KERNELDIR/include/linux/slab.h"
],[
  struct page * (*func)(void*);
  func = vmalloc_to_page;
],
    AC_MSG_RESULT("yes");vmalloc_to_page="1",
    AC_MSG_RESULT("no");vmalloc_to_page="0",
    AC_MSG_RESULT("unknown");vmalloc_to_page="0"
)
CFLAGS=$ac_save_CFLAGS
CONFIG_HAVE_VMALLOC_TO_PAGE=$vmalloc_to_page
dnl AC_SUBST(CONFIG_HAVE_VMALLOC_TO_PAGE)
if test "$CONFIG_HAVE_VMALLOC_TO_PAGE" = "1"; then
  AC_DEFINE(CONFIG_HAVE_VMALLOC_TO_PAGE)
fi

dnl Check for old kmod...
AC_MSG_CHECKING(for old kmod)
old_kmod="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -Wall -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_COMPILE([
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#include "$CONFIG_SND_KERNELDIR/include/linux/module.h"
],[
	kmod("abcd", "def", "ixj");
],
    AC_MSG_RESULT("yes");old_kmod="1",
    AC_MSG_RESULT("no");old_kmod="0",
    AC_MSG_RESULT("unknown");old_kmod="0"
)
CFLAGS=$ac_save_CFLAGS
CONFIG_HAVE_OLD_REQUEST_MODULE=$old_kmod
dnl AC_SUBST(CONFIG_HAVE_OLD_REQUEST_MODULE)
if test "$CONFIG_HAVE_OLD_REQUEST_MODULE" = "1"; then
  AC_DEFINE(CONFIG_HAVE_OLD_REQUEST_MODULE)
fi

dnl check only on 2.2 kernel..
if test $kpatchlevel -le 2; then

dnl Check for old kill_fasync...
AC_MSG_CHECKING(for old kill_fasync)
oldkfasync="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_COMPILE([
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#ifdef __alpha__ /* it's required (at least for 2.2.18) */
#include "$CONFIG_SND_KERNELDIR/include/asm/current.h"
#endif
#include "$CONFIG_SND_KERNELDIR/include/linux/fs.h"
],[
 struct fasync_struct *fa;
 int sig;
 kill_fasync(fa, sig);
],
    AC_MSG_RESULT("yes");oldkfasync="1",
    AC_MSG_RESULT("no");oldkfasync="0",
    AC_MSG_RESULT("unknown");oldkfasync="0"
)
CFLAGS=$ac_save_CFLAGS
CONFIG_OLD_KILL_FASYNC=$oldkfasync
dnl AC_SUBST(CONFIG_OLD_KILL_FASYNC)
if test "$CONFIG_OLD_KILL_FASYNC" = "1"; then
  AC_DEFINE(CONFIG_OLD_KILL_FASYNC)
fi

dnl Check for dma_addr_t
AC_MSG_CHECKING(for dma_addr_t)
dma_addr_t="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_COMPILE([
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#include "$CONFIG_SND_KERNELDIR/include/asm/types.h"
],[
 dma_addr_t addr;
],
    AC_MSG_RESULT("yes");dma_addr_t="1",
    AC_MSG_RESULT("no");dma_addr_t="0",
    AC_MSG_RESULT("unknown");dma_addr_t="0"
)
CFLAGS=$ac_save_CFLAGS
CONFIG_HAVE_DMA_ADDR_T=$dma_addr_t
dnl AC_SUBST(CONFIG_HAVE_DMA_ADDR_T)
if test "$CONFIG_HAVE_DMA_ADDR_T" = "1"; then
  AC_DEFINE(CONFIG_HAVE_DMA_ADDR_T)
fi

dnl Check for MUTEX macros
AC_MSG_CHECKING(for MUTEX macros)
have_mutex_macros="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_COMPILE([
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#include "$CONFIG_SND_KERNELDIR/include/asm/semaphore.h"
],[
#ifndef init_MUTEX
#error not defined
#endif
exit(0);
],
    AC_MSG_RESULT("yes");have_mutex_macros="1",
    AC_MSG_RESULT("no");have_mutex_macros="0",
    AC_MSG_RESULT("unknown");have_mutex_macros="0"
)
CFLAGS=$ac_save_CFLAGS
CONFIG_HAVE_MUTEX_MACROS=$have_mutex_macros
dnl AC_SUBST(CONFIG_HAVE_MUTEX_MACROS)
if test "$CONFIG_HAVE_MUTEX_MACROS" = "1"; then
  AC_DEFINE(CONFIG_HAVE_MUTEX_MACROS)
fi

fi
dnl 2.2 kernel

if test "$CONFIG_ISAPNP_KERNEL" = "y"; then
  if test -f include/linux/isapnp.h; then
    echo "Removing local linux/isapnp.h."
    rm include/linux/isapnp.h
  fi
else
  if test ! -f include/linux/isapnp.h; then
    echo "Symlinking <linux/isapnp.h>..."
    mkdir -p include/linux
    ln -sf ../../support/isapnp/isapnp.h include/linux/isapnp.h
  fi
fi

if test "$CONFIG_PNP_KERNEL" = "y"; then
  if test -f include/linux/pnp.h; then
    echo "Removing local linux/pnp.h."
    rm include/linux/pnp.h
  fi
else
  if test ! -f include/linux/pnp.h; then
    echo "Symlinking <linux/pnp.h>..."
    mkdir -p include/linux
    ln -sf ../../support/pnp/pnp.h include/linux/pnp.h
  fi
fi

dnl Check for version...
AC_MSG_CHECKING(for driver version)
AC_DEFINE_UNQUOTED(CONFIG_SND_VERSION, "$CONFIG_SND_VERSION")
AC_SUBST(CONFIG_SND_VERSION)
CONFIG_SND_DATE=""
AC_DEFINE_UNQUOTED(CONFIG_SND_DATE, "$CONFIG_SND_DATE")
AC_SUBST(CONFIG_SND_DATE)
AC_MSG_RESULT($CONFIG_SND_VERSION)

dnl Check for sequencer support...
AC_MSG_CHECKING(for sequencer support)
AC_ARG_WITH(sequencer,
  [  --with-sequencer=yes,no  driver will (not) be compiled with sequencer support],
  sequencer="$withval", sequencer="yes")
CONFIG_SND_SEQUENCER=""
if test "$sequencer" = "yes"; then
  CONFIG_SND_SEQUENCER="m"
fi
AC_SUBST(CONFIG_SND_SEQUENCER)
if test "$CONFIG_SND_SEQUENCER" = "m"; then
  AC_DEFINE(CONFIG_SND_SEQUENCER)
  AC_DEFINE(CONFIG_SND_SEQ_DUMMY_MODULE)
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

dnl Check for OSS/Free emulation...
AC_MSG_CHECKING(for OSS/Free emulation)
AC_ARG_WITH(oss,
  [  --with-oss=no,yes       driver will (not) be compiled with OSS/Free emulation],
  ossemul="$withval", ossemul="yes")
CONFIG_SND_OSSEMUL=""
if test "$ossemul" = "yes"; then
  CONFIG_SND_OSSEMUL="y"
fi
AC_SUBST(CONFIG_SND_OSSEMUL)
if test "$CONFIG_SND_OSSEMUL" = "y"; then
  AC_DEFINE(CONFIG_SND_OSSEMUL)
  AC_DEFINE(CONFIG_SND_MIXER_OSS)
  AC_DEFINE(CONFIG_SND_PCM_OSS)
  if test "$CONFIG_SND_SEQUENCER" = "m"; then
    AC_DEFINE(CONFIG_SND_SEQUENCER_OSS)
  fi
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

dnl Check for RTC timer support...
AC_MSG_CHECKING(for RTC callback support in kernel)
rtcsup="0"
ac_save_CFLAGS="$CFLAGS"
CFLAGS="$CFLAGS -I$CONFIG_SND_KERNELDIR/include"
AC_TRY_RUN([
#include "$CONFIG_SND_KERNELDIR/include/linux/autoconf.h"
#if defined(__alpha__) || (!defined(CONFIG_RTC) && !defined(CONFIG_RTC_MODULE))
int main(void) { exit(1); }
#else
#define __KERNEL__
#include "$CONFIG_SND_KERNELDIR/include/linux/version.h"
#include "$CONFIG_SND_KERNELDIR/include/linux/config.h"
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 2, 12)	/* FIXME: which 2.2.x kernel? */
#include "$CONFIG_SND_KERNELDIR/include/linux/rtc.h"
#else
#include "$CONFIG_SND_KERNELDIR/include/linux/mc146818rtc.h"
#endif
int main(void)
{
  rtc_task_t *cb = 0;
  exit(0);
}
#endif
],
  AC_MSG_RESULT("yes");rtcsup="m",
  AC_MSG_RESULT("no");rtcsup="",
  AC_MSG_RESULT("unknown");rtcsup=""
)
CFLAGS="$ac_save_CFLAGS"
CONFIG_SND_RTCTIMER=$rtcsup
AC_SUBST(CONFIG_SND_RTCTIMER)
test "$CONFIG_SND_RTCTIMER" = "m" && AC_DEFINE(CONFIG_SND_RTCTIMER_MODULE)
CONFIG_RTC=$CONFIG_SND_RTCTIMER
AC_SUBST(CONFIG_RTC)

dnl Check for USB
CHECK_KERNEL_CONFIG(CONFIG_USB, [USB support])
if test "$CONFIG_USB" != "y"; then
  CHECK_KERNEL_CONFIG(CONFIG_USB_MODULE, [USB module support])
  CONFIG_USB=$CONFIG_USB_MODULE
fi
AC_SUBST(CONFIG_USB)

dnl PCMCIA stuff
AC_ARG_WITH(pcmcia,
  [  --with-pcmcia=kernel,external   support kernel PCMCIA driver or external PCMCIA driver],
  pcmcia="$withval", pcmcia="kernel")
AC_ARG_WITH(pcmcia_root,
  [  --with-pcmcia-root=dir  specify the root directory of external PCMCIA source-tree],
  pcmciaroot="$withval", pcmciaroot="")
EXTRA_INCLUDES=""
if test "$pcmcia" = "kernel"; then
  echo "checking for kernel PCMCIA"
  CHECK_KERNEL_CONFIG(CONFIG_PCMCIA, [PCMCIA support])
  if test "$CONFIG_PCMCIA" != "y"; then
    CHECK_KERNEL_CONFIG(CONFIG_PCMCIA_MODULE, [PCMCIA module support])
    CONFIG_PCMCIA=$CONFIG_PCMCIA_MODULE
  fi
else
  echo "checking for external PCMCIA"
  if test "$pcmciaroot" = ""; then
    AC_MSG_ERROR(Please set the PCMCIA root directory via --with-pcmcia-root option)
  fi
  if test ! -d "$pcmciaroot"; then
    AC_MSG_ERROR(PCMCIA root $pcmciaroot is not a directory)
  fi
  echo "PCMCIA root directory is $pcmciaroot"
  EXTRA_INCLUDES="-I$pcmciaroot/include"
  CONFIG_PCMCIA=y
fi
  
AC_SUBST(CONFIG_PCMCIA)

dnl Check for PC98 architecture support...
CHECK_KERNEL_CONFIG(CONFIG_X86_PC9800, [PC9800 support in kernel])
AC_SUBST(CONFIG_X86_PC9800)

dnl Check for which cards to compile driver for...
ALSA_TOPLEVEL_INIT
ALSA_TOPLEVEL_SELECT

dnl Some late substitutes...
c_opts="$c_opts -DLINUX"
m_opts=""
if test -r /etc/asound/make_opts; then
  m_opts="$m_opts `cat /etc/asound/make_opts`"
fi
AC_SUBST(c_opts)
AC_SUBST(m_opts)
AC_SUBST(GENKSYMS)
AC_SUBST(EXTRA_INCLUDES)

dnl Output files...
AC_OUTPUT(version Makefile.conf snddevices utils/alsa-driver.spec utils/buildrpm toplevel.config)

dnl Make right rights for scripts
chmod 755 $srcdir/snddevices
