dnl Process this file with autoconf to produce a configure script.

AC_INIT(kernel/sound.c)
AC_PREFIX_DEFAULT(/usr)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_RANLIB
AC_PROG_INSTALL

dnl Checks for header files.
AC_HEADER_STDC
AC_CONFIG_HEADER(include/config.h)
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 Major number
AC_MSG_CHECKING(for default major number for the alsa driver)
AC_ARG_WITH(major,
  [  --with-major=number     give the default major number for the alsa driver],
  majornumber="$withval", majornumber="14")
AC_DEFINE_UNQUOTED(SNDCFG_MAJOR, $majornumber)
SNDCFG_MAJOR="$majornumber"
AC_SUBST(SNDCFG_MAJOR)
AC_MSG_RESULT($majornumber)

dnl Check for kernel version...
AC_MSG_CHECKING(for kernel version)
kversion=`cat /usr/src/linux/Makefile | grep -E "^VERSION =" | cut -d = -f 2`
kpatchlevel=`cat /usr/src/linux/Makefile | grep -E "^PATCHLEVEL =" | cut -d = -f 2`
ksublevel=`cat /usr/src/linux/Makefile | grep -E "^SUBLEVEL =" | cut -d = -f 2`
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 /usr/src/linux/Makefile)"
  exit 1
fi
kaversion="$kversion.$kpatchlevel.$ksublevel"
AC_SUBST(kversion)
AC_SUBST(kpatchlevel)
AC_SUBST(ksublevel)
AC_MSG_RESULT($kaversion)

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/$kaversion/misc]],
  moddir="$withval", moddir="/lib/modules/$kaversion/misc")
AC_SUBST(moddir)
AC_MSG_RESULT($moddir)

dnl Debug level
AC_MSG_CHECKING(for debug level)
AC_ARG_WITH(debug,
  [  --with-debug=level      give the debug level (none,basic,memory,full)],
  debug="$withval", debug="none")
case "$debug" in
  basic)
    AC_MSG_RESULT(basic)
    AC_DEFINE(SNDCFG_DEBUG)
    ;;
  memory)
    AC_MSG_RESULT(memory)
    AC_DEFINE(SNDCFG_DEBUG)
    AC_DEFINE(SNDCFG_DEBUG_MEMORY)
    ;;
  full)
    AC_MSG_RESULT(full)
    AC_DEFINE(SNDCFG_DEBUG)
    AC_DEFINE(SNDCFG_DEBUG_MEMORY)
    AC_DEFINE(SNDCFG_DEBUG_FULL)
    ;;    
  detect)
    AC_MSG_RESULT(detect)
    AC_DEFINE(SNDCFG_DEBUG)
    AC_DEFINE(SNDCFG_DEBUG_MEMORY)
    AC_DEFINE(SNDCFG_DEBUG_FULL)
    AC_DEFINE(SNDCFG_DEBUG_DETECT)
    ;;
  *)
    AC_MSG_RESULT(none)
    ;;
esac
AC_SUBST(moddir)

dnl Check pro processor type...
AC_MSG_CHECKING(for processor type)
AC_ARG_WITH(processor,
  [  --with-processor=cpu    give the processor type]
  [                        (i386,i486,i586,i686,alpha,ppc,auto)],
  processor="$withval", processor="auto")
if test "$processor" = "auto"; then
  CPUID=`cat /proc/cpuinfo | grep cpu | grep -v "cpu family" | grep -v cpuid | cut -d : -f 2 | colrm 1 1 | head -n 1`
  if test "$CPUID""x" = "x"; then
    CPUID=`cat /proc/cpuinfo | grep "cpu family" | cut -d : -f 2 | colrm 1 1 | head -n 1`
    if test "$CPUID" != "alpha" && test "$CPUID" != "Alpha"; then
      CPUID="i""$CPUID""86"
    fi
  else
    if test "$CPUID" != "alpha" && test "$CPUID" != "Alpha"; then
      CPUID="i""$CPUID"
    fi
  fi
  processor="$CPUID"
fi
c_opts=""
case "$processor" in
  i386)
    c_opts="-m386"
    AC_MSG_RESULT(i386)    
    ;;
  i486)
    c_opts="-m486"
    AC_MSG_RESULT(i486)    
    ;;
  i586)
    c_opts="-m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2"
    AC_MSG_RESULT(i586)    
    ;;
  i686)
    c_opts="-m486 -malign-loops=2 -malign-jumps=2 -malign-functions=2"
    AC_MSG_RESULT(i686)    
    ;;
  alpha|Alpha)
    c_opts="-fno-strength-reduce -mno-fp-regs"
    AC_MSG_RESULT(alpha)
    processor="alpha"
    ;;
  ppc)
    AC_MSG_RESULT(ppc)
    ;;
  *)
    AC_MSG_RESULT(unknown)
    processor="unknown"
    ;;
esac
c_opts="-O2 $c_opts"
AC_SUBST(c_opts)
AC_SUBST(processor)

dnl Check for SMP...
AC_MSG_CHECKING(for SMP)
AC_ARG_WITH(smp,
  [  --with-smp=yes,no,auto  driver will (not) be compiled with SMP support],
  smp="$withval", smp="auto")
msmp=""
if test "$smp" = "auto"; then
  CPUNUM=`cat /proc/ksyms | grep apic | wc -l`
  CPUNUM=`expr $CPUNUM + 0`
  if test $CPUNUM -gt 0; then
    msmp="1"
  else
    CPUNUM=`cat /proc/ksyms | grep Rsmp_ | wc -l`
    CPUNUM=`expr $CPUNUM + 0`
    if test $CPUNUM -gt 0; then
      msmp="1"
    fi
  fi
fi
if test "$smp" = "yes"; then
  msmp="1"
fi
if test "$msmp" = "1"; then
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi
AC_SUBST(msmp)

dnl Check for Tom Lees PnP driver...
AC_MSG_CHECKING(for Tom Lees PnP driver)
AC_ARG_WITH(pnp,
  [  --with-pnp=yes,no,auto  driver will (not) be compiled with PnP support],
  pnp="$withval", pnp="auto")
mpnp=""
if test "$pnp" = "auto"; then
  if test -f /proc/sys/pnp; then
    mpnp="1"
  fi
else
  if test "$pnp" = "yes"; then
    mpnp="1"
  fi
fi
if test "$mpnp" = "1"; then
  AC_DEFINE(SNDCFG_PNP)
  AC_MSG_RESULT(yes)
else
  AC_MSG_RESULT(no)
fi

dnl Check for version...
AC_MSG_CHECKING(for driver version)
SND_VERSION=`cat $srcdir/version`
AC_DEFINE_UNQUOTED(SND_VERSION, "$SND_VERSION")
AC_SUBST(SND_VERSION)
AC_MSG_RESULT($SND_VERSION)

AC_OUTPUT(Makefile.conf snddevices utils/alsadriver.spec)

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