dnl Process this file with autoconf to produce a configure script.
AC_INIT(isdnctrl.c)
AC_PREFIX_DEFAULT(/usr)

I4LCONFDIR=`eval echo ${CONFIG_I4LCONFDIR:-"/etc/isdn"}`
I4LCONFFILE=`eval echo ${CONFIG_CONFFILE:-"/etc/isdn"}`
I4LVERSION=${I4LVERSION:-"?.?"}
CONFIG_KERNELDIR=${CONFIG_KERNELDIR:-"/usr/src/linux"}
CONFIG_SBINDIR=${CONFIG_SBINDIR:-"/sbin"}
CONFIG_MANDIR=${CONFIG_MANDIR:-"/usr/man"}
CONFIG_ISDNCTRL_CONF=${CONFIG_ISDNCTRL_CONF:-"n"}
CONFIG_ISDNCTRL_TIMRU=${CONFIG_ISDNCTRL_TIMRU:-"n"}
CONFIG_ISDNCTRL_DWABC_UDP_INFO=${CONFIG_ISDNCTRL_DWABC_UDP_INFO:-"n"}
MANDATE=`grep CHECKIN isdnctrl.man.in | awk '{print $4}'`

dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_CC

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(sys/ioctl.h unistd.h)

dnl Find current kernel source
AC_FIND_KERNEL
AC_CHECK_FILE($CONFIG_KERNELDIR/include/linux/isdn.h,,
	AC_MSG_ERROR("$CONFIG_KERNELDIR/include/linux/isdn.h missing. Kernel installed?")
)
AC_CHECK_FILE($CONFIG_KERNELDIR/include/linux/isdnif.h,,
	AC_MSG_ERROR("$CONFIG_KERNELDIR/include/linux/isdnif.h missing. Kernel installed?")
)
dnl Check for triggercps and ciscok depend on CONFIG_KERNELDIR,
dnl so AC_FIND_KERNEL must be called before.
AC_CHECK_TRIGGERCPS
AC_CHECK_CISCOK
AC_CHECK_TIMRU

dnl Checks for typedefs, structures, and compiler characteristics.

dnl Checks for library functions.
AC_CHECK_LIB(dbm, dbm_open, DBMLIB=-ldbm; AC_DEFINE(HAVE_LIBDBM),
  AC_CHECK_LIB(gdbm, gdbm_open, DBMLIB=-lgdbm; AC_DEFINE(HAVE_LIBGDBM),
  	AC_CHECK_LIB(db, dbm_open, DBMLIB=-ldb; AC_DEFINE(HAVE_LIBDB))))
AC_TYPE_SIGNAL

dnl Optional sbin directory
AC_ARG_WITH(sbin,
	[  --with-sbin=DIR         Set dir where binary is istalled. [/sbin]],
	CONFIG_SBINDIR="${withval}"
	AC_DEFINE(CONFIG_SBINDIR,"${withval}"),
)

dnl Optional man directory
AC_ARG_WITH(man,
	[  --with-man=DIR          Set manpage dir. [/usr/man]],
	CONFIG_MANDIR="${withval}"
	AC_DEFINE(CONFIG_MANDIR,"${withval}"),
)

dnl Optional config-file-option
AC_ARG_ENABLE(cfile,
	[  --enable-cfile          Enable configfile option [no]],
	CONFIG_ISDNCTRL_CONF=y
	AC_DEFINE(CONFIG_ISDNCTRL_CONF,y),
)

dnl Optional timru-option
AC_ARG_ENABLE(timru,
	[  --enable-timru          Enable dynamic timeout rules [no]],
	CONFIG_ISDNCTRL_TIMRU=y
	AC_DEFINE(CONFIG_ISDNCTRL_TIMRU,y),
)

AC_SUBST(INSTALL)
AC_SUBST(DBMLIB)
AC_SUBST(MANDATE)
AC_SUBST(I4LCONFDIR)
AC_SUBST(I4LCONFFILE)
AC_SUBST(I4LVERSION)
AC_SUBST(CONFIG_ISDNCTRL_CONF)
AC_SUBST(CONFIG_ISDNCTRL_TIMRU)
AC_SUBST(CONFIG_ISDNCTRL_DWABC_UDP_INFO)
AC_SUBST(CONFIG_KERNELDIR)
AC_SUBST(CONFIG_SBINDIR)
AC_SUBST(CONFIG_MANDIR)
AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile isdnctrl.man .isdnctrl_conf.man .isdnctrl_timru.man)
