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

AC_ARG_WITH(ksrc,[  --with-ksrc=DIR	  Linux Kernel source directory],
            KTOPDIR=$with_ksrc, KTOPDIR=/usr/src/linux)

CONFIG=.config
rm -f $CONFIG

cp /dev/null $CONFIG

WithKernel()
{
  TMP=/tmp/_tmp_ul_kcf.$$
  cp $1/Makefile $TMP
  chmod u+w $TMP
  cat << 'END' >> $TMP

check_ul_kcf:
	@echo "CC="\"$(CC)\"
	@echo "LD="\"$(LD)\"
	@echo "GENKSYMS=$(GENKSYMS)"
	@echo "CFLAGS_KMODULE="\"$(CFLAGS) $(MODFLAGS)\"
END
  make -f $TMP -C $1 check_ul_kcf | grep -v ^make > $CONFIG
  if `cat $CONFIG | grep -q __SMP__`
  then
      echo "KSYMPFIX="\"-p smp_\" >> $CONFIG
  fi
  rm -f $TMP
  /lib/cpp -I$1/include << 'END' | /bin/sh -s >> $CONFIG
#include <linux/version.h>
echo "KVER="UTS_RELEASE
echo "KSYMVER="`echo UTS_RELEASE | sed "s/[[-_]].*$//"`
END
  if test -d "$KTOPDIR"
  then
      KTOPDIR=`cd $KTOPDIR; pwd`
  else
      KTOPDIR=/usr/src/linux
  fi

  echo "KTOPDIR=$KTOPDIR" >> $CONFIG
}

WithKernel $KTOPDIR

. $CONFIG

if test -z $ARCH 
then
	ARCH=`uname -m | sed -e s/i.86/i386/`
fi

KMODDIR=/lib/modules/$KVER

AC_SUBST(CFLAGS)
AC_SUBST(CFLAGS_KMODULE)
AC_SUBST(CC)
AC_SUBST(LD)
AC_SUBST(GENKSYMS)
AC_SUBST(KSYMPFIX)
AC_SUBST(KVER)
AC_SUBST(KTOPDIR)
AC_SUBST(KSYMVER)
AC_SUBST(KMODDIR)
AC_SUBST(ARCH)
AC_PREFIX_DEFAULT("/usr")

AC_ARG_ENABLE(smp, \
  --enable-smp		SMP kernel,\
	have_smp=$enableval,have_smp="no")

if test "$have_smp" = "yes"
then
  SMP=1
  AC_SUBST(SMP)
fi

AC_ARG_ENABLE(modversions, \
  --enable-modversions		Modules with version,\
	have_modver=$enableval,have_modver="no")

if test "$have_modver" = "yes"
then
  if test -f $KTOPDIR/include/linux/modversions.h
  then
    MODVERSIONS=1
    AC_SUBST(MODVERSIONS)
  fi
fi

if test -f $ARCH/Makefile.in ; then
	OUTFILES="Makefile ${ARCH}/Makefile"
else
	OUTFILES="Makefile"
fi

AC_OUTPUT(${OUTFILES})
