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

I4LVERSION=${I4LVERSION:-"?.?"}
CONFIG_DATADIR=${CONFIG_DATADIR:-"/usr/lib/isdn/eicon"}
CONFIG_SBINDIR=${CONFIG_SBINDIR:-"/sbin"}
CONFIG_MANDIR=${CONFIG_MANDIR:-"/usr/man"}
CONFIG_EICONCTRL_DEBUG=${CONFIG_EICONCTRL_DEBUG:-"n"}
CONFIG_KERNELDIR=`eval echo ${CONFIG_KERNELDIR:-"/usr/src/linux"}`
MANDATE=`grep CHECKIN eiconctrl.man.in | awk '{print $4}'`

dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_CC

dnl Checks for libraries.
AC_CHECK_LIB(ncurses, newpad,,
	AC_CHECK_LIB(curses, newpad,,
		AC_MSG_ERROR("Missing ncurses library")))

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h sys/ioctl.h unistd.h)
AC_CHECK_HEADERS(ncurses.h,,
	AC_CHECK_HEADERS(ncurses/curses.h,,
		AC_CHECK_HEADERS(curses/ncurses.h,,
			AC_CHECK_HEADERS(curses.h,,
				AC_MSG_ERROR("Missing \(n\)curses.h")))))

dnl Find current kernel source
AC_FIND_KERNEL
AC_CHECK_HEADER($CONFIG_KERNELDIR/include/linux/isdn.h,,
	AC_MSG_ERROR("$CONFIG_KERNELDIR/include/linux/isdn.h missing. Kernel installed?")
)
AC_CHECK_HEADER($CONFIG_KERNELDIR/drivers/isdn/eicon/eicon.h,,
	AC_MSG_ERROR("$CONFIG_KERNELDIR/drivers/isdn/eicon/eicon.h missing. Kernel installed?")
)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_XLOG
AC_CHECK_NPCI
AC_CHECK_TRACE

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MMAP

dnl Optional firmware directory
AC_ARG_WITH(firmware,
	[  --with-firmware=DIR     Set dir where firmware istalled. [/usr/lib/isdn]],
	CONFIG_DATADIR="${withval}"
	AC_DEFINE(CONFIG_DATADIR,"${withval}"),
)

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 kernel directory
AC_ARG_WITH(kernel,
	[  --with-kernel=DIR          Set kernel dir. [/usr/src/linux]],
	CONFIG_KERNELDIR="${withval}"
	AC_DEFINE(CONFIG_KERNELDIR,"${withval}"),
)

dnl Check, if user wants dump option for debugging
AC_ARG_ENABLE(dump,
	[  --enable-dump           Enable dump feature for debugging [no]],
	CONFIG_EICONCTRL_DEBUG="y"
)

AC_SUBST(INSTALL)
AC_SUBST(MANDATE)
AC_SUBST(CONFIG_EICONCTRL_DEBUG)
AC_SUBST(CONFIG_DATADIR)
AC_SUBST(CONFIG_KERNELDIR)
AC_SUBST(CONFIG_SBINDIR)
AC_SUBST(CONFIG_MANDIR)
AC_SUBST(I4LVERSION)
AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile eiconctrl.man)
