dnl Process this file with autoconf to produce a configure script.
AC_INIT(auth.c)
AC_CONFIG_HEADER(config.h)

I4LVERSION=${I4LVERSION:-"?.?"}
MANDATE=`grep CHECKIN ipppd.man.in | awk '{print $4}'`
CONFIG_MANDIR=`eval echo ${CONFIG_MANDIR:-"/usr/man"}`
CONFIG_SBINDIR=`eval echo ${CONFIG_SBINDIR:-"/sbin"}`
CONFIG_RUNDIR=`eval echo ${CONFIG_RUNDIR:-"/var/run"}`
CONFIG_KERNELDIR=`eval echo ${CONFIG_KERNELDIR:-"/usr/src/linux"}`
CONFIG_IPPPD_MSCHAP=${CONFIG_IPPPD_MSCHAP:-"n"}
CONFIG_IPPPD_RADIUS=${CONFIG_IPPPD_RADIUS:-"n"}
CONFIG_RADIUS_WTMP_LOGGING=${CONFIG_RADIUS_WTMP_LOGGING:-"n"}
RADIUS_CLIENT_CONFIG_FILE=`eval echo ${RADIUS_CLIENT_CONFIG_FILE:-"/usr/local/lib/radiusclient/radiusclient.conf"}`
dnl Checks for programs.
AC_PROG_INSTALL
AC_PROG_CC

dnl Check for kernel
AC_FIND_KERNEL

dnl Checks for libraries.
AC_CHECK_LIB(bsd, daemon,HAVE_LIBBSD=1; AC_DEFINE(HAVE_LIBBSD),
	AC_MSG_WARN(Could not find libbsd, build disabled))
dnl Replace `main' with a function in -lcrypt:
AC_CHECK_LIB(crypt, main,HAVE_LIBCRYPT=1; AC_DEFINE(HAVE_LIBCRYPT))
AC_CHECK_LIB(des, des_ecb_encrypt, HAVE_LIBDES=1; AC_DEFINE(HAVE_LIBDES))

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h limits.h paths.h sys/file.h sys/ioctl.h sys/time.h syslog.h unistd.h)
AC_CHECK_HEADER(shadow.h, HAVE_SHADOW_H=1; AC_DEFINE(HAVE_SHADOW_H))
AC_CHECK_HEADER(linux/isdn_lzscomp.h, HAVE_LZSCOMP_H=1; AC_DEFINE(HAVE_LZSCOMP_H))

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

dnl Checks for library functions.
AC_TYPE_GETGROUPS
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(gethostname gettimeofday select socket strdup strerror strtol strtoul uname)

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

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

dnl Optional /var/run directory
AC_ARG_WITH(sbin,
	[  --with-varrun=DIR       Set directory for .pid files. [/var/run]],
	CONFIG_RUNDIR="${withval}"
	AC_DEFINE(CONFIG_RUNDIR,"${withval}"),
)

dnl Optional MSCHAP
AC_ARG_ENABLE(mschap,
	[  --enable-mschap         Enable Microsoft chap authentication [no]],
	CONFIG_IPPPD_MSCHAP="y"
	AC_DEFINE(CONFIG_IPPPD_MSCHAP,"y"),
)

dnl Optional RADIUS
AC_ARG_ENABLE(radius,
	[  --enable-radius         Enable RADIUS authentication [no]],
	CONFIG_IPPPD_RADIUS="y"
	AC_DEFINE(CONFIG_IPPPD_RADIUS,"y"),
)

dnl Optional radiusclient config file
AC_ARG_WITH(radiusclient_config,
	[  --with-radiusclient=FILE Set filename for radiusclient configuration],
	RADIUS_CLIENT_CONFIG_FILE="${withval}"
	AC_DEFINE(RADIUS_CLIENT_CONFIG_FILE,"${withval}"),
)

dnl Optional RADIUS_WTMP_LOGGING
AC_ARG_ENABLE(radius_wtmp_logging,
	[  --enable-radius-wtmp       Enable RADIUS_WTMP_LOGGING authentication [no]],
	CONFIG_IPPPD_RADIUS_WTMP_LOGGING="y"
	AC_DEFINE(CONFIG_IPPPD_RADIUS_WTMP_LOGGING,"y"),
)

dnl Optional DEBUGGING
AC_ARG_ENABLE(debug,
	[  --enable-debug          Enable debugging [no]],
	CONFIG_IPPPD_DEBUGFLAGS="-DDEBUGALL"
	AC_DEFINE(CONFIG_IPPPD_DEBUGFLAGS,"-DDEBUGALL"),
)

AC_SUBST(I4LVERSION)
AC_SUBST(MANDATE)
AC_SUBST(HAVE_LIBDES)
AC_SUBST(HAVE_LIBCRYPT)
AC_SUBST(HAVE_LIBBSD)
AC_SUBST(HAVE_SHADOW_H)
AC_SUBST(HAVE_LZSCOMP_H)
AC_SUBST(CONFIG_RUNDIR)
AC_SUBST(CONFIG_SBINDIR)
AC_SUBST(CONFIG_MANDIR)
AC_SUBST(CONFIG_IPPPD_MSCHAP)
AC_SUBST(CONFIG_IPPPD_RADIUS)
AC_SUBST(RADIUS_CLIENT_CONFIG_FILE)
AC_SUBST(CONFIG_RADIUS_WTMP_LOGGING)
AC_SUBST(CONFIG_IPPPD_DEBUGFLAGS)
AC_OUTPUT(Makefile ipppd.man pathnames.h)
