dnl process this file with GNU autoconf to produce a configure script.
dnl
dnl $Id: configure.in,v 1.74 2004/09/24 20:19:52 papowell Exp $

dnl ----------------------------------------------------------------------------
dnl ----------------- START OF GENERAL CONFIGURATION ---------------------------
AC_INIT(Makefile.in)


PACKAGE=LPRng
VERSION=3.8.28


AC_CONFIG_AUX_DIR(.)
AC_CANONICAL_SYSTEM
AC_CONFIG_HEADER(config.h)

AC_DEFINE_UNQUOTED(PACKAGE, "$PACKAGE", [package])
AC_DEFINE_UNQUOTED(VERSION, "$VERSION", [version])
AC_SUBST(PACKAGE)
AC_SUBST(VERSION)
ALL_LINGUAS="fr"

if test -z "$LOCALEDIR" ; then
    LOCALEDIR='${prefix}/share/locale'
fi;
WITH_LOCALEDIR dnl
export LOCALEDIR

WITH_CCOPTS dnl
WITH_CPPOPTS dnl
WITH_LDOPTS dnl

AC_PREFIX_DEFAULT(/usr/local)
AC_SUBST(INSTALL)
AC_SUBST(INSTALL_MAN)
AC_SUBST(SHELL)
AC_SUBST(CPP)
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(LDFLAGS)
AC_SUBST(LDCC)


dnl check for awk
AC_PROG_AWK
AC_SUBST(AWK)
AC_PATH_PROG(SED,sed)dnl
AC_SUBST(SED)dnl
AC_PATH_PROG(PERL,perl)dnl
AC_SUBST(PERL)dnl
AC_PATH_PROG(CHOWN,chown)dnl
AC_SUBST(CHOWN)dnl
AC_PATH_PROG(CHGRP,chgrp)dnl
AC_SUBST(CHGRP)dnl
AC_PATH_PROG(PRUTIL,pr)dnl
AC_SUBST(PRUTIL)dnl
AC_PATH_PROG(OPENSSL,openssl)dnl
AC_SUBST(OPENSSL)dnl
AC_PATH_PROG(PGP_PATH,pgp)dnl
AC_SUBST(PGP_PATH)dnl
AC_DEFINE_UNQUOTED(PGP_PATH, "$PGP_PATH",[pgp path])


dnl ----------------------------------------------------------------------------
dnl ----------- XXXXXX START OF OPTIONS ----------------------------------------

dnl Unix socket pathname
AC_MSG_CHECKING(unix socket pathname)
AC_ARG_WITH(unix_socket_path,
[  --with-unix_socket_path=DIR       unix socket path (default /var/run/lprng)],
UNIXSOCKETPATH=$withval,
UNIXSOCKETPATH=/var/run/lprng
)
AC_MSG_RESULT($UNIXSOCKETPATH)
AC_SUBST(UNIXSOCKETPATH)

CONFIG_SUBDIR=lpd
AC_MSG_CHECKING(configuration information subdirectory)
AC_ARG_WITH(config_subdir,
[  --with-config_subdir=CONFIG_SUBDIR configuration subdirectory (default 'lpd')],
CONFIG_SUBDIR=$withval,
)
AC_MSG_RESULT($CONFIG_SUBDIR)
AC_SUBST(CONFIG_SUBDIR)


dnl check to see if setuid is suppressed
AC_MSG_CHECKING(if installing clients setuid)
AC_ARG_ENABLE( setuid,
[  --disable-setuid                  do not install client executables setuid root],
[
if test "$enableval" = "yes" ; then
	PERMS=SUID_ROOT_PERMS
else
	PERMS=NORM_PERMS
fi
],
[
	PERMS=SUID_ROOT_PERMS
],
)
AC_MSG_RESULT($PERMS)
AC_SUBST(PERMS)

dnl check to see if priv ports required
AC_MSG_CHECKING(require connections from priviledged ports)
AC_ARG_ENABLE( priv_ports,
[  --enable-priv_ports               require connections from privileged ports],
[
if test "$enableval" = "yes" ; then
	v=yes;  PRIV_PORTS="";
else
	v=no; PRIV_PORTS="#";
fi
],
[
	v=no; PRIV_PORTS="#";
]
)
AC_MSG_RESULT($v);dnl
AC_SUBST(PRIV_PORTS)

dnl check to see if force_localhost is suppressed
AC_MSG_CHECKING(disable force_localhost default)
AC_ARG_ENABLE( force_localhost,
[  --disable-force_localhost         disable force_localhost default],
[
if test "$enableval" = "yes" ; then
	v=enabled;  FORCE_LOCALHOST=1;
else
	v=disabled; FORCE_LOCALHOST=0;
fi
],
[
	v=enabled;  FORCE_LOCALHOST=1;
]
)
AC_MSG_RESULT($v)
AC_DEFINE_UNQUOTED(FORCE_LOCALHOST,"$FORCE_LOCALHOST",[Force Localhost (force_localhost)])

dnl check to see if clients require lpd.conf and printcap
AC_MSG_CHECKING(require_configfiles default)
AC_ARG_ENABLE( require_configfiles,
[  --disable-require_configfiles     client programs require lpd.conf, printcap],
[
if test "$enableval" = "yes" ; then
	v=yes;  REQUIRE_CONFIGFILES=1;
else
	v=no; REQUIRE_CONFIGFILES=0;
fi
],
[
	v=yes;  REQUIRE_CONFIGFILES=1;
]
)
AC_MSG_RESULT($v)
AC_SUBST(REQUIRE_CONFIGFILES)

dnl check to see if kerberos is disabled
AC_MSG_CHECKING(if Kerberos authentication is enabled)
AC_ARG_ENABLE( kerberos,
[  --enable-kerberos                 enable kerberos support],
[
if test "$enableval" = "yes" ; then
	v=enabled;  KERBEROS=1;AC_DEFINE_UNQUOTED(KERBEROS,"$KERBEROS",[kerberos])
else
	v=disabled; KERBEROS=;
fi
],
[
	v=disabled; KERBEROS=;
]
)
AC_MSG_RESULT($v (KERBEROS $KERBEROS));dnl
AC_SUBST(KERBEROS)

dnl check to see if MIT Kerberos 4 support is enabled
AC_MSG_CHECKING(if MIT Kerberos4 is enabled)
AC_ARG_ENABLE( mit_kerberos4,
[  --enable-mit_kerberos4            enable MIT Kerberos 4 support],
[
if test "$enableval" = "yes" ; then
	v=enabled; MIT_KERBEROS4=1;AC_DEFINE_UNQUOTED(MIT_KERBEROS4,"$MIT_KERBEROS4",[kerberos 4 support])
else
	v=disabled; MIT_KERBEROS4=;
fi
],
[
	v=disabled; MIT_KERBEROS4=;
]
)
AC_MSG_RESULT($v (MIT_KERBEROS4 $MIT_KERBEROS4));dnl
AC_SUBST(MIT_KERBEROS4)

dnl find kerberos libraries
AC_MSG_CHECKING(if Kerberos libraries are to located and other checks)
AC_ARG_ENABLE( --disable-kerberos_checks,
[  --disable-kerberos_checks         disable kerberos library location and checking for support],
[
if test "$enableval" = "yes" ; then
	v=enabled; KERBEROS_CHECKS=1;
else
	v=disabled; KERBEROS_CHECKS=;
fi
],
[
	v=enabled; KERBEROS_CHECKS=1;
]
)
AC_MSG_RESULT($v (KERBEROS_CHECKS $KERBEROS_CHECKS));dnl

dnl Specify install dir for lpd
AC_MSG_CHECKING(where to install the lpd binary)
AC_ARG_WITH(lpddir,
[  --with-lpddir=DIR                 lpd executable directory (default \${sbindir})],
LPD_DIR=$withval,
LPD_DIR=\${sbindir}
)
AC_MSG_RESULT($LPD_DIR)
AC_SUBST(LPD_DIR)

dnl  lpd.conf location
AC_MSG_CHECKING(lpd.conf location)
AC_ARG_WITH(lpd_conf_path,
[  --with-lpd_conf_path=PATH         path of lpd.conf (default: \${sysconfdir}/${CONFIG_SUBDIR}/lpd.conf)],
LPD_CONF_PATH=$withval,
LPD_CONF_PATH=\${sysconfdir}/${CONFIG_SUBDIR}/lpd.conf,
)
AC_MSG_RESULT($LPD_CONF_PATH)
AC_SUBST(LPD_CONF_PATH)

dnl  lpd.perms location
dnl
AC_MSG_CHECKING(lpd.perms location)
AC_ARG_WITH(lpd_perms_path,
[  --with-lpd_perms_path=PATH        path of lpd.perms (default: \${sysconfdir}/${CONFIG_SUBDIR}/lpd/lpd.perms)],
LPD_PERMS_PATH=$withval,
LPD_PERMS_PATH=\${sysconfdir}/${CONFIG_SUBDIR}/lpd.perms,
)
AC_MSG_RESULT($LPD_PERMS_PATH)
AC_SUBST(LPD_PERMS_PATH)

dnl  printcap location
dnl
AC_MSG_CHECKING(printcap location)
AC_ARG_WITH(printcap_path,
[  --with-printcap_path=PATH         path of printcap (default \${sysconfdir}/printcap)],
PRINTCAP_PATH=$withval,
PRINTCAP_PATH=\${sysconfdir}/printcap,
)
AC_MSG_RESULT($PRINTCAP_PATH)
AC_SUBST(PRINTCAP_PATH)

dnl  lpd_printcap location
dnl
AC_MSG_CHECKING(lpd_printcap location)
AC_ARG_WITH(lpd_printcap_path,
[  --with-lpd_printcap_path=PATH     path of lpd_printcap (default \${sysconfdir}/${CONFIG_SUBDIR}/lpd_printcap)],
LPD_PRINTCAP_PATH=$withval,
LPD_PRINTCAP_PATH=\${sysconfdir}/${CONFIG_SUBDIR}/lpd_printcap,
)
AC_MSG_RESULT($LPD_PRINTCAP_PATH)
AC_SUBST(LPD_PRINTCAP_PATH)
dnl  startup file location
dnl
AC_MSG_CHECKING(startup (initialization) file location)
AC_ARG_WITH(initpath,
[  --with-initpath=PATH              path of lpd startup file (default /usr/local/etc/rc.d/lprng.sh)
                                       use 'no' to disable installation and lpd startup],
INIT=$withval,
INIT=,
)
AC_MSG_RESULT($INIT)
AC_SUBST(INIT)

dnl  lockfile PATH value
dnl
AC_MSG_CHECKING(lockfile PATH value)
AC_ARG_WITH(lockfile,
[  --with-lockfile=PATH              lockfile PATH, default /var/run/lpd ],
LOCKFILE="$withval", LOCKFILE="/var/run/lpd",
)
AC_MSG_RESULT("$LOCKFILE")
AC_SUBST(LOCKFILE)


dnl  default SPOOL directory value (:sd)
dnl
AC_MSG_CHECKING(default spool directory, :sd=SPOOLDIR/%P)
AC_ARG_WITH(spooldir,
[  --with-spooldir=PATH              default spool directory, default /var/spool/lpd ],
SD_DEFAULT="$withval", SD_DEFAULT="/var/spool/lpd",
)
AC_MSG_RESULT("$SD_DEFAULT")
AC_SUBST(SD_DEFAULT)

dnl  LD_LIBRARY_PATH value
dnl
AC_MSG_CHECKING(LD_LIBRARY_PATH value)
AC_ARG_WITH(ld_library_path,
[  --with-ld_libary_path=PATH        LD_LIBRARY_PATH value, default /lib:/usr/lib:/usr/local/lib ],
LD_LIBRARY_PATH="$withval",
LD_LIBRARY_PATH="/lib:/usr/lib:/usr/local/lib"
)
AC_MSG_RESULT("$LD_LIBRARY_PATH")
AC_SUBST(LD_LIBRARY_PATH)

dnl  filter PATH value
dnl
AC_MSG_CHECKING(filter PATH value)
AC_ARG_WITH(filter_path,
[  --with-filter_path=PATH           filter PATH value, default /bin:/usr/bin:/usr/local/bin ],
FILTER_PATH="$withval",
FILTER_PATH="/bin:/usr/bin:/usr/local/bin"
)
AC_MSG_RESULT("$FILTER_PATH")
AC_SUBST(FILTER_PATH)

dnl  user name
dnl
AC_MSG_CHECKING(run lpd as userid)
AC_ARG_WITH(userid,
[  --with-userid=NAME                run LPRng software as this userid, default daemon ],
USERID="$withval", USERID="daemon",
)
AC_MSG_RESULT("$USERID")
AC_SUBST(USERID)

dnl  group value
dnl
AC_MSG_CHECKING(run lpd as groupid)
AC_ARG_WITH(groupid,
[  --with-groupid=NAME               run LPRng software as this groupid, default daemon ],
GROUPID="$withval", GROUPID="daemon",
)
AC_MSG_RESULT("$GROUPID")
AC_SUBST(GROUPID)


dnl  done_jobs value
dnl
AC_MSG_CHECKING(retain status for N jobs)
AC_ARG_WITH(done_jobs,
[  --with-done_jobs=N                retain last N job status, default 1],
DONE_JOBS="$withval", DONE_JOBS="1",
)
AC_MSG_RESULT("$DONE_JOBS")
AC_SUBST(DONE_JOBS)


dnl  done_jobs_max_age value
dnl
AC_MSG_CHECKING(retain status for jobs less than N seconds old, default 0 - no expiry)
AC_ARG_WITH(done_jobs_max_age,
[  --with-done_jobs_max_age=N        retain job status N seconds, default 0 - no expiry],
DONE_JOBS_MAX_AGE="$withval", DONE_JOBS_MAX_AGE="0",
)
AC_MSG_RESULT("$DONE_JOBS_MAX_AGE")
AC_SUBST(DONE_JOBS_MAX_AGE)

dnl  chooser routine
dnl
AC_MSG_CHECKING(load balance queue chooser routine name)
AC_ARG_WITH(chooser_routine,
[  --with-chooser_routine=NAME       load balance queue chooser routine name in user object file ],
[
CHOOSER_ROUTINE="$withval"
AC_DEFINE_UNQUOTED(CHOOSER_ROUTINE,$CHOOSER_ROUTINE,[Chooser routine])
]
)
AC_MSG_RESULT("$CHOOSER_ROUTINE")

dnl  queue order routine
dnl
AC_MSG_CHECKING(queue order routine name)
AC_ARG_WITH(order_routine,
[  --with-order_routine=NAME         queue order routine name in user object file ],
[
ORDER_ROUTINE="$withval"
AC_DEFINE_UNQUOTED(ORDER_ROUTINE,"$ORDER_ROUTINE",[job order routine])
]
)
AC_MSG_RESULT("$ORDER_ROUTINE")

dnl  user specified object files
dnl
AC_MSG_CHECKING(user specified object file)
AC_ARG_WITH(user_objs,
[  --with-user_objs=NAME             user specified object file ],
USER_OBJS="$withval"
)
AC_MSG_RESULT("$USER_OBJS")
AC_SUBST(USER_OBJS)

dnl  user specified include files
dnl
AC_MSG_CHECKING(user specified include file for user object files)
AC_ARG_WITH(user_include,
[  --with-user_include=NAME          include file with function prototypes for user object file ],
[
USER_INCLUDE="$withval"
AC_DEFINE_UNQUOTED(USER_INCLUDE,"$USER_INCLUDE",[user specified include files])
]
)
AC_MSG_RESULT("$USER_INCLUDE")

dnl  clear program
dnl
AC_MSG_CHECKING(terminal screen clear program)
if test -z "$CLEAR" ; then
  AC_PATH_PROG(CLEAR,clear)dnl
fi
if test -z "$CLEAR" ; then
 AC_MSG_WARN([Program 'clear' is not found. Set environment CLEAR=no if you do not want to use it]);
 exit 1
fi
if test "$CLEAR" = "no" ; then CLEAR= ; fi
if test -n "$CLEAR" ; then
	AC_DEFINE_UNQUOTED(CLEAR,"$CLEAR",[screen clear program])
fi

dnl  ps -what options
dnl
AC_MSG_CHECKING(ps options for displaying all processes)
if test -z "$PSHOWALL" ; then
  if ps -ax >/dev/null 2>/dev/null; then
  	PSHOWALL="-ax"
  elif ps -e >/dev/null 2>/dev/null;  then
  	PSHOWALL="-e"
  else
  	AC_MSG_WARN(ps not available or -ax AND -e options do not work)
  	AC_MSG_WARN(specify options in the PSHOWALL environment variable);
	exit 1
  fi
fi
AC_MSG_RESULT("using ${PSHOWALL}")
AC_SUBST(PSHOWALL)

dnl ----------------------------------------------------------------------------
dnl ----------- XXXXXX END OF OPTIONS ------------------------------------------
AC_MSG_CHECKING(filter directory)
AC_ARG_WITH(filterdir,
[  --with-filterdir=DIR              filter directory (default \${libexecdir}/filters)],
FILTER_DIR=$withval,
FILTER_DIR=\${libexecdir}/filters,
)
AC_MSG_RESULT($FILTER_DIR)
AC_SUBST(FILTER_DIR)

dnl default use -Werror
AC_MSG_CHECKING(disable -Werror flag)
AC_ARG_ENABLE( werror,
[  --disable-werror                  disable -Werror compile flag],
[
if test "$enableval" = "yes" ; then
	v=yes;  werror=" -Werror ";
else
	v=no; werror="";
fi
],
[
	v=yes;  werror=" -Werror ";
]
)
AC_MSG_RESULT($v)

dnl default strip binaries 
AC_MSG_CHECKING(disable stripped binaries)
AC_ARG_ENABLE( strip,
[  --disable-strip                   disable stripping binaries by default],
[
if test "$enableval" = "yes" ; then
	v=yes;  STRIP_OPTION=" -s ";
else
	v=no; STRIP_OPTION="";
fi
],
[
	v=yes;  STRIP_OPTION=" -s ";
]
)
AC_MSG_RESULT($v)
AC_SUBST(STRIP_OPTION)

dnl ----------------------------------------------------------------------------
dnl ------------   OS Checks  --------------------------------------------------
changequote(, )dnl
release=`uname -r 2>/dev/null; exit 0`;
version=`echo $target_os | sed -e 's/[^0-9][^0-9]*//' -e 's/\./X/' -e 's/\.//g' -e 's/X/./' \
	| awk '{ v=$1+0; if( v > 0 ){ while( v < 100 || int(v) != v ){v = v * 10;}}; print v; }' `;
if test "$version" -eq 0 ; then
	version=`echo $release | sed -e 's/-.*//' -e 's/\.//g' \
	| awk '{ v=$1+0; if( v > 0 ){ while( v < 100 || int(v) != v ){v = v * 10;}}; print v; }' `;
fi
osword=`echo $target_os | sed -e 's/[0-9].*//'`; export osword
changequote([, ])dnl
AC_MSG_RESULT([Target is $target, arch $target_cpu, os $target_os, release $release, version $version])

AC_DEFINE_UNQUOTED(TARGETARCHITECTURE,"$target_cpu",[target CPU])
AC_DEFINE_UNQUOTED(OSNAME,"$osword",[OS name])
AC_DEFINE_UNQUOTED(OSVERSION,$version,[OS version])
OSNAME=$osword
OSVERSION=$version
AC_SUBST(OSNAME)dnl
AC_SUBST(OSVERSION)dnl


dnl ----------------------------------------------------------------------------
dnl -----------   C compiler checks    -----------------------------------------

AC_PROG_CPP
AC_PROG_CC

AC_AIX
AC_ISC_POSIX
AC_MINIX


if test "$ac_cv_prog_gcc" = yes; then
	cat >conftest.c <<EOF
#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5)
yes
#endif
EOF
    if ${CC-cc} -E conftest.c | egrep yes >/dev/null 2>&1; then
        gcc -v
		echo "WARNING: gcc -O (version 2.4.5 and below) produces incorrect code"
		echo "  for lpd.c and other large routines. Update your GCC compiler"
		exit 1
	fi;
fi;

LDCC="$CC"

AC_DISABLE_SHARED
AM_PROG_LIBTOOL

AC_C_CONST
AC_C_INLINE
AC_C_VOLATILE

AC_HEADER_STDC
AC_HEADER_DIRENT
AC_HEADER_SYS_WAIT
AC_HEADER_TIME

dnl typedefs:
AC_TYPE_SIGNAL
AC_TYPE_UID_T
AC_TYPE_SIZE_T
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T


AC_CHECK_TYPES( fd_set,,,[
#include <sys/types.h>
#include <sys/time.h>
#include <sys/unistd.h>
] )

AC_CHECK_TYPES( socklen_t,,,[
#include <sys/types.h>
#include <sys/socket.h>
] )

AC_CACHE_CHECK(checking for long long,
ac_cv_long_long,
[
AC_TRY_COMPILE([
#include <stdio.h>
#include <sys/types.h>
], [printf("%d",sizeof(long long));],
ac_cv_long_long=yes, ac_cv_long_long=no)
])
if test $ac_cv_long_long = yes; then
  AC_DEFINE(HAVE_LONG_LONG,1,[have long long])
fi

AC_CACHE_CHECK(checking for long double,
ac_cv_long_double,
[
AC_TRY_COMPILE([
#include <stdio.h>
#include <sys/types.h>
], [printf("%d",sizeof(long double));],
ac_cv_long_double=yes, ac_cv_long_double=no)
])
if test $ac_cv_long_double = yes; then
  AC_DEFINE(HAVE_LONG_DOUBLE,1,[have long double])
fi

AC_CACHE_CHECK(checking for quad_t,
ac_cv_quad_t,
[
AC_TRY_COMPILE([
#include <stdio.h>
#include <sys/types.h>
], [printf("%d",sizeof(quad_t));],
ac_cv_quad_t=yes, ac_cv_quad_t=no)
])
if test $ac_cv_quad_t = yes; then
  AC_DEFINE(HAVE_QUAD_T,1,[have quad_t])
fi


dnl ----------------------------------------------------------------------------
dnl OS dependency checks
checklibs=
case $target_os in
	 *linux* )
		no_resolv_lib=yes;
		case $release in
changequote(, )dnl
		2.2.1[0-5]* )
changequote([, ])dnl
			AC_DEFINE(SETUID_CHECK,1,[run setuid check])
			AC_MSG_WARN([Kernel may have SETUID compromise.  Update kernel])
			;;
		esac
		CPPFLAGS="$CPPFLAGS -D_FILE_OFFSET_BITS=64"
		CFLAGS="$CFLAGS -D_FILE_OFFSET_BITS=64"
		;;
	 *bsdi* )
		LDCC=shlicc
		dnl BSDI uses this for setproctitle
		AC_CHECK_LIB(util, setproctitle, [LIBS="-lutil $LIBS"])
		;;
	 *bsd* )
		dnl *BSD uses this for setproctitle
		AC_CHECK_LIB(util, setproctitle, [LIBS="-lutil $LIBS"])
		;;
	 *unicos* )
		checklibs=no
		;;
	 *irix6* )
		checklibs=no
		AC_DEFINE_UNQUOTED(IRIX,$version,[IRIX version])
		;;
	 *irix5* )
		checklibs=no
		AC_DEFINE(HAVE_BROKEN_TIOCEXCL,1,[IRIX broken TIOCEXL])
		AC_DEFINE(SVR4,1,[SVR4])
		AC_DEFINE_UNQUOTED(IRIX,$version,[IRIX version])
		;;
	 *irix* )
		checklibs=no
		AC_DEFINE_UNQUOTED(IRIX,$version,[IRIX version])
		;;
	*solaris* )
		AC_DEFINE(SVR4,1,[SVR4])
		AC_DEFINE_UNQUOTED(SOLARIS,$version,[Solaris version])
		no_resolv_lib=yes;
		;;
	*hpux* )
		AC_DEFINE(_HPUX_SOURCE,1,[_HPUX_SOURCE])
		CPPFLAGS="$CPPFLAGS -D_HPUX_SOURCE=1"
		CFLAGS="$CFLAGS -D_HPUX_SOURCE=1"
		AC_DEFINE_UNQUOTED(HPUX,$version,[HPUX version])
		;;
	*sunos* )
		AC_DEFINE_UNQUOTED(SUNOS,$version,[Sun OS])
		;;
	osf* )
		AC_DEFINE_UNQUOTED(DECALPHA,$version,[DEC Alpha])
		if test "$ac_cv_prog_gcc" != yes; then
			CPPFLAGS="$CPPFLAGS -std";
			CFLAGS="$CFLAGS -std";
        else
            CPPFLAGS="$CPPFLAGS -DAES_SOURCE"
            CFLAGS="$CFLAGS -DAES_SOURCE"
		fi
		;;
	*mips-sni* )
		;;
esac
AC_MSG_RESULT([using CPPFLAGS=\"${CPPFLAGS}\", CFLAGS=\"${CFLAGS}\"])

dnl ----------------------------------------------------------------------------
dnl headers:

AC_CHECK_HEADERS(a_out.h aouthdr.h ar.h arpa/inet.h arpa/nameser.h assert.h)
AC_CHECK_HEADERS(com_err.h compat.h ctype.h ctypes.h dirent.h errno.h)
AC_CHECK_HEADERS(exechdr.h fcntl.h filehdr.h grp.h limits.h locale.h)
AC_CHECK_HEADERS(machine/vmparam.h malloc.h memory.h ndir.h netdb.h netinet/in.h)
AC_CHECK_HEADERS(nlist.h pwd.h reloc.h resolv.h select.h setjmp.h)
AC_CHECK_HEADERS(sgs.h sgtty.h signal.h stab.h stdarg.h stdio.h)
AC_CHECK_HEADERS(stdlib.h string.h strings.h sys/dir.h sys/exec.h sys/exechdr.h)
AC_CHECK_HEADERS(sys/fcntl.h sys/file.h sys/ioctl.h sys/loader.h sys/mount.h sys/ndir.h)
AC_CHECK_HEADERS(sys/param.h sys/pstat.h sys/resource.h sys/select.h sys/signal.h sys/socket.h)
AC_CHECK_HEADERS(sys/stat.h sys/statfs.h sys/statvfs.h sys/syslog.h sys/systeminfo.h sys/termio.h)
AC_CHECK_HEADERS(sys/termiox.h sys/time.h sys/ttold.h sys/ttycom.h sys/types.h sys/utsname.h)
AC_CHECK_HEADERS(sys/vfs.h sys/wait.h syslog.h term.h termcap.h termio.h)
AC_CHECK_HEADERS(termios.h time.h unistd.h utsname.h varargs.h vmparam.h)

dnl ----------------------------------------------------------------------------
dnl libraries:

dnl check to see if we suppress probing for libraries
dnl this is done by using the checklibs variable

if test -z "$checklibs"; then
	dnl A/UX uses this...
	AC_CHECK_LIB(posix, getpwent, [LIBS="$LIBS -lposix"])

	dnl use old-style shared libs if we have 'em.
	AC_CHECK_LIB(socket_s, socket, [LIBS="$LIBS -lsocket_s"; have_socket=1], ,-lnsl)
	if test -z "$have_socket"; then
		AC_CHECK_LIB(socket, socket, [LIBS="$LIBS -lsocket"], , -lnsl)
	fi

	AC_TRY_LINK(,[extern int gethostbyaddr; return (gethostbyaddr);],
		have_gethost=1)
	if test -z "$have_gethost" ; then
		h="you need additional libs for gethostbyaddr";
	else
		h="no additional libs for gethostbyaddr";
	fi
	AC_MSG_RESULT($h)
	if test -z "$have_gethost" ; then
		AC_CHECK_LIB(nsl_s, gethostbyaddr, [LIBS="$LIBS -lnsl_s"; have_gethost=1])
	fi
	if test -z "$have_gethost"; then
		AC_CHECK_LIB(nsl, gethostbyaddr, [LIBS="$LIBS -lnsl"; have_gethost=1])
	fi

	if test -z "$have_gethost"; then
		AC_CHECK_LIB(net_s, gethostbyaddr, [LIBS="$LIBS -lnet_s"; have_gethost=1])
	fi
	if test -z "$have_gethost"; then
		AC_CHECK_LIB(net, gethostbyaddr, [LIBS="$LIBS -lnet"; have_gethost=1])
	fi

	dnl BIND library may be needed,  need to force this first
	if test -z "$no_resolv_lib"; then
	  AC_CHECK_FUNC(inet_ntop,name2=yes)
	  if test -z "$name2" ; then
		AC_CHECK_LIB(resolv, inet_ntop, [LIBS="$LIBS -lresolv";name2=yes])
	  fi;
	fi
fi

dnl ----------------------------------------------------------------------------
dnl function checks:

AC_CHECK_FUNCS(_res cfsetispeed fcntl flock gethostbyname2 getdtablesize)
AC_CHECK_FUNCS(gethostname getrlimit inet_aton inet_ntop inet_pton)
AC_CHECK_FUNCS(innetgr initgroups killpg lockf mkstemp)
AC_CHECK_FUNCS(mktemp openlog putenv random rand setenv seteuid setgroups setlocale setpgid setproctitle)
AC_CHECK_FUNCS(setresuid setreuid setruid setsid sigaction)
AC_CHECK_FUNCS(sigprocmask siglongjmp socketpair strcasecmp)
AC_CHECK_FUNCS(strchr strdup strerror strncasecmp sysconf sysinfo)
AC_CHECK_FUNCS(tcdrain tcflush tcsetattr uname unsetenv wait3 waitpid)

if test ! "$ac_cv_func_setreuid" = yes -a ! "$ac_cv_func_seteuid" = yes -a ! "$ac_cv_func_setresuid" = yes; then
	echo "WARNING: missing setreuid(), seteuid(), and setresuid()"
fi

AC_FUNC_VFORK
AC_FUNC_VPRINTF


dnl ----------------------------------------------------------------------------
dnl special system checks

AC_CACHE_CHECK(how to manipulate tty attributes,
ac_cv_struct_term,
[

if test "$ac_cv_header_termios_h" = yes; then
	ac_cv_struct_term=termios
fi
if test "$ac_cv_header_sys_termios_h" = yes; then
	ac_cv_struct_term=termios
fi

dnl test to see if we need to compile
if test -z "$ac_cv_struct_term" ; then
AC_TRY_COMPILE([
#ifdef HAVE_TERMIO_H
#include <termio.h>
#endif
#ifdef HAVE_SYS_TERMIO_H
#include <sys/termio.h>
#endif],[struct termio t;t.c_iflag = 0],
ac_cv_struct_term=termio)
fi

dnl now you have determined if you have termio
if test -z "$ac_cv_struct_term" ; then
    AC_TRY_COMPILE([#include <sgtty.h>],[
    struct sgttyb s;s.sg_flags = 0],
    ac_cv_struct_term=sgttyb)
fi
if test -z "$ac_cv_struct_term" ; then
	ac_cv_struct_term=UNDEFINED
fi
])
if test "$ac_cv_struct_term" = "sgttyb"; then
	AC_DEFINE(USE_SGTTYB,1,[use sgttyb])
	AC_DEFINE(USE_STTY,SGTTYB,[use sgttyb])
fi
if test "$ac_cv_struct_term" = "termio"; then
	AC_DEFINE(USE_TERMIO,1,[use termio])
	AC_DEFINE(USE_STTY,TERMIO,[use termio])
fi
if test "$ac_cv_struct_term" = "termios"; then
	AC_DEFINE(USE_TERMIOS,1,[use termios])
	AC_DEFINE(USE_STTY,TERMIOS,[use termios])
	if test "$ac_cv_header_sys_termiox_h" = yes; then
		AC_DEFINE(USE_TERMIOX,1,[use termiox])
	fi
fi

dnl ----------------------------------------------------------------------------

AC_CACHE_CHECK(checking for struct exec,
ac_cv_struct_exec,
[
ac_cv_struct_exec=no
if test "$ac_cv_header_a_out_h" != no ; then
  AC_TRY_COMPILE([
#include <sys/types.h>
#include <a.out.h>],[struct exec b; b.a_text = 0],
	ac_cv_struct_exec=yes, ac_cv_struct_exec=no )
fi
])
if test "$ac_cv_struct_exec" = yes; then
  AC_DEFINE(HAVE_STRUCT_EXEC,1,[have struct exec])
fi

dnl ----------------------------------------------------------------------------

dnl test to see if long long is defined

AC_CACHE_CHECK(checking for long long,
ac_cv_long_long,
[
AC_TRY_COMPILE([
#include <sys/types.h>
],[long long x; x = 0],
ac_cv_long_long=yes, ac_cv_long_long=no)
])
if test "$ac_cv_long_long" = yes; then
  AC_DEFINE(HAVE_LONG_LONG,1,[have long long])
fi

dnl ----------------------------------------------------------------------------

dnl test to see if lseek has a prototype - you make it get an error

AC_CACHE_CHECK(checking for lseek prototype,
ac_cv_lseek_proto,
[
AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_UNISTD_H
#include <sys/unistd.h>
#endif
],[off_t x; x = lseek(0,"test",SEEK_SET);],
ac_cv_lseek_proto=no, ac_cv_lseek_proto=yes)
])
if test "$ac_cv_lseek_proto" = yes; then
  AC_DEFINE(HAVE_LSEEK_PROTO,1,[have lseek definition])
fi

dnl ----------------------------------------------------------------------------

AC_CACHE_CHECK(how to get filesystem free space,
ac_cv_struct_fstype,
[
fstype=

dnl do this check if statvfs is a valid function
if test "$ac_cv_func_statvfs" != no ; then		#{
  AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#include <sys/param.h>
#ifdef HAVE_SYS_STATVFS_H
# include <sys/statvfs.h>
#endif
#ifdef HAVE_SYS_STATFS_H
# include <sys/statfs.h>
#endif

#ifdef HAVE_SYS_MOUNT_H
# include <sys/mount.h>
#endif
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif],[struct statvfs s; statvfs ("/", &s); return(s.f_bavail+s.f_bsize)],
  fstype=statvfs)
fi							#}

dnl do these checks if statfs is a valid function

if test "$ac_cv_func_statfs" != no ; then		#{
  if test -z "$fstype" ; then				#{
    AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#include <sys/param.h>
#ifdef HAVE_SYS_STATFS_H
# include <sys/statfs.h>
#endif

#ifdef HAVE_SYS_STATVFS_H
# include <sys/statvfs.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
# include <sys/mount.h>
#endif
#ifdef HAVE_SYS_VFS_H
# include <sys/vfs.h>
#endif],[struct fs_data s; return(s.fd_bfree+s.fd_bsize)],
    fstype=Ultrix-statfs)
  fi							#}

  if test -z "$fstype" ; then				#{
    AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#include <sys/param.h>
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif],[struct statfs s; return(s.f_bavail+s.f_bsize)],
    fstype=statfs)
  fi							# }

  if test -z "$fstype" ; then				# {
    AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#include <sys/param.h>
#ifdef HAVE_SYS_STATFS_H
#include <sys/statfs.h>
#endif
#ifdef HAVE_SYS_MOUNT_H
#include <sys/mount.h>
#endif
#ifdef HAVE_SYS_VFS_H
#include <sys/vfs.h>
#endif],[struct statfs s; return(s.f_bfree+s.f_bsize)],
    fstype=SVR3-statfs)
  fi							# }
fi							# }

if test -z "$fstype" ; then
    echo "cannot find a valid statfs-like structure!"
	fstype=UNKNOWN
fi

ac_cv_struct_fstype=$fstype

])

if test "$ac_cv_struct_fstype" = SVR3-statfs; then
	AC_DEFINE(USE_STATFS_TYPE,SVR3_STATFS,[svr3 statfs])
fi
if test "$ac_cv_struct_fstype" = Ultrix-statfs; then
	AC_DEFINE(USE_STATFS_TYPE,ULTRIX_STATFS,[ultix statfs])
fi
if test "$ac_cv_struct_fstype" = statfs; then
	AC_DEFINE(USE_STATFS_TYPE,STATFS,[plain statfs])
fi
if test "$ac_cv_struct_fstype" = statvfs; then
	AC_DEFINE(USE_STATFS_TYPE,STATVFS,[statvfs statfs])
fi

dnl ----------------------------------------------------------------------------
dnl

AC_CACHE_CHECK(for errno,
ac_cv_errno,
[
AC_TRY_LINK(,[extern int errno; return (errno);],
	ac_cv_errno=yes, ac_cv_errno=no)
])
if test "$ac_cv_errno" = yes; then
	AC_DEFINE(HAVE_ERRNO,1,[have errno])
	AC_CACHE_CHECK(for errno declaration,
	ac_cv_decl_errno,
	[
	AC_TRY_COMPILE([
	#include <stdio.h>
	#ifdef HAVE_STDLIB_H
	#include <stdlib.h>
	#endif
	#ifdef HAVE_UNISTD_H
	#include <unistd.h>
	#endif
	#ifdef HAVE_ERRNO_H
	#include <errno.h>
	],[return(sys_nerr);],
		ac_cv_decl_errno=yes, ac_cv_decl_errno=no)
	])
	if test "$ac_cv_decl_errno" = yes; then
		AC_DEFINE(HAVE_DECL_ERRNO,1,[have errno declaration])
	fi;
fi

AC_CACHE_CHECK(for sys_nerr,
ac_cv_sys_nerr,
[
AC_TRY_LINK(,[extern int sys_nerr; return (sys_nerr);],
	ac_cv_sys_nerr=yes, ac_cv_sys_nerr=no)
])
if test "$ac_cv_sys_nerr" = yes; then
	AC_DEFINE(HAVE_SYS_NERR,1,[have sys_nerr])
	AC_CACHE_CHECK(for sys_nerr declaration,
	ac_cv_decl_sys_nerr,
	[
	AC_TRY_COMPILE([
	#include <stdio.h>
	#ifdef HAVE_STDLIB_H
	#include <stdlib.h>
	#endif
	#ifdef HAVE_UNISTD_H
	#include <unistd.h>
	#endif],[return(sys_nerr);],
	ac_cv_decl_sys_nerr_def=yes, ac_cv_decl_sys_nerr_def=no)
	])
	if test "$ac_cv_decl_sys_nerr" = yes; then
		AC_DEFINE(HAVE_DECL_SYS_NERR,1,[have sys_nerr declaration])
	fi
fi

AC_CACHE_CHECK(for sys_errlist array,
ac_cv_sys_errlist,
[AC_TRY_LINK(,[extern char *sys_errlist[];
	sys_errlist[0];],
	ac_cv_sys_errlist=yes, ac_cv_sys_errlist=no)
])
if test "$ac_cv_sys_errlist" = yes; then
	AC_DEFINE(HAVE_SYS_ERRLIST,1,[have sys_errlist])
	AC_CACHE_CHECK(for sys_errlist declaration,
	ac_cv_sys_errlist_def,
	[AC_TRY_COMPILE([
	#include <stdio.h>
	#include <errno.h>
	#ifdef HAVE_STDLIB_H
	#include <stdlib.h>
	#endif
	#ifdef HAVE_UNISTD_H
	#include <unistd.h>
	#endif],[char *s = sys_errlist[0]; return(*s);],
	ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)
	])
	if test "$ac_cv_decl_sys_errlist" = yes; then
		AC_DEFINE(HAVE_DECL_SYS_ERRLIST,1,[sys_errlist declared])
	fi
fi


AC_CACHE_CHECK(for setproctitle declaration,
ac_cv_decl_setproctitle_def,
[AC_TRY_COMPILE([
#include <stdio.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_ERRNO_H
#include <errno.h>
#endif
],[setproctitle(0);],
ac_cv_decl_setproctitle_def=no, ac_cv_decl_setproctitle_def=yes)
])
if test "$ac_cv_decl_setproctitle_def" = yes; then
    AC_DEFINE(HAVE_SETPROCTITLE_DEF,1,[setproctitle defined])
fi


dnl ----------------------------------------------------------------------------
dnl sys_siglist array (list of signals)

AC_CACHE_CHECK(for sys_siglist declaration,
ac_cv_decl_sys_siglist_def,
[AC_TRY_COMPILE([
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <signal.h>],
[printf("%s",sys_siglist[0]);],
ac_cv_decl_sys_siglist_def=yes, ac_cv_decl_sys_siglist_def=no)
])
if test "$ac_cv_decl_sys_siglist_def" = yes; then
    AC_DEFINE(HAVE_SYS_SIGLIST_DEF,1,[sys_siglist defined])
	ac_cv_sys_siglist=yes
fi

AC_CACHE_CHECK(for _sys_siglist declaration,
ac_cv_decl__sys_siglist_def,
[AC_TRY_COMPILE([
#include <stdio.h>
#include <sys/types.h>
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <signal.h>],
[printf("%s",_sys_siglist[0]);],
ac_cv_decl__sys_siglist_def=yes, ac_cv_decl__sys_siglist_def=no)
])
if test "$ac_cv_decl__sys_siglist_def" = yes; then
    AC_DEFINE(HAVE__SYS_SIGLIST_DEF,1,[_sys_siglist defined])
	ac_cv__sys_siglist=yes
fi

AC_CACHE_CHECK(for sys_siglist array,
ac_cv_sys_siglist,
[AC_TRY_LINK([
#include <stdio.h>],
[extern int sys_siglist; printf("%d",sys_siglist);],
ac_cv_sys_siglist=yes, ac_cv_sys_siglist=no)
])
if test "$ac_cv_sys_siglist" = yes; then
    AC_DEFINE(HAVE_SYS_SIGLIST,1,[have sys_syslist])
fi

AC_CACHE_CHECK(for _sys_siglist array,
ac_cv__sys_siglist,
[AC_TRY_LINK([
#include <stdio.h>],
[extern int _sys_siglist; printf("%d",_sys_siglist);],
ac_cv__sys_siglist=yes, ac_cv__sys_siglist=no)
])
if test "$ac_cv__sys_siglist" = yes; then
    AC_DEFINE(HAVE__SYS_SIGLIST,1,[have _sys_siglist])
fi

dnl ----------------------------------------------------------------------------
dnl just for (really) backwards compatibility
dnl we really try not to use union wait -- it's heinously unportable.
dnl nicked this check from Tcl as well. ;
dnl
dnl The check below checks whether <sys/wait.h> defines the type
dnl "union wait" correctly.  It's needed because of weirdness in
dnl HP-UX where "union wait" is defined in both the BSD and SYS-V
dnl environments.  Checking the usability of WIFEXITED seems to do
dnl the trick.

AC_CACHE_CHECK(for obsolete union wait compatibility,
ac_cv_unionwait,
[
AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#include <sys/wait.h>], [union wait x;WIFEXITED(x);],
ac_cv_unionwait=yes, ac_cv_unionwait=no)
])
if test "$ac_cv_unionwait" = yes; then
	AC_DEFINE(HAVE_UNION_WAIT,1,[have union wait])
fi

dnl ----------------------------------------------------------------------------
dnl Would you believe the gethostname declarations are broken on some machines
dnl ----------------------------------------------------------------------------
AC_CACHE_CHECK(for gethostname declaration,
ac_cv_decl_gethostname_def,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif],[gethostname(1);],
ac_cv_decl_gethostname_def=no, ac_cv_decl_gethostname_def=yes)
])
if test "$ac_cv_decl_gethostname_def" = yes; then
    AC_DEFINE(HAVE_GETHOSTNAME_DEF,1,[have gethostname definition])
fi

dnl ----------------------------------------------------------------------------
dnl innetgr() declarations missing
dnl ----------------------------------------------------------------------------
AC_CACHE_CHECK(for innetgr declaration,
ac_cv_decl_innetgr_def,
[
AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_NETDB_H
#include <netdb.h>
#endif],[printf("%d", innetgr(1));],
ac_cv_decl_innetgr_def=no, ac_cv_decl_innetgr_def=yes )
]
)
if test "$ac_cv_decl_innetgr_def" = yes; then
  AC_DEFINE(HAVE_INNETGR_DEF,1,[use innetgr(1)])
fi

dnl ----------------------------------------------------------------------------
dnl openlog() declarations missing
dnl ----------------------------------------------------------------------------
AC_CACHE_CHECK(for openlog declaration,
ac_cv_decl_openlog_def,
[AC_TRY_COMPILE([
#include <stdio.h>
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif],[printf("%d",openlog);],
ac_cv_decl_openlog_def=yes, ac_cv_decl_openlog_def=no)
])
if test "$ac_cv_decl_openlog_def" = yes; then
    AC_DEFINE(HAVE_OPENLOG_DEF,1,[have openlog definition])
fi


dnl ----------------------------------------------------------------------------
dnl syslog() declarations missing
dnl ----------------------------------------------------------------------------
AC_CACHE_CHECK(for syslog declaration,
ac_cv_decl_syslog_def,
[AC_TRY_COMPILE([
#include <stdio.h>
#ifdef HAVE_STDARG_H
#include <stdarg.h>
#endif
#ifdef HAVE_SYSLOG_H
#include <syslog.h>
#endif],[printf("%d",syslog);],
ac_cv_decl_syslog_def=yes, ac_cv_decl_syslog_def=no)
])
if test "$ac_cv_decl_syslog_def" = yes; then
    AC_DEFINE(HAVE_SYSLOG_DEF,1,[have syslog definition])
fi

dnl ----------------------------------------------------------------------------
dnl IPV6 - check for structure declarations
dnl ----------------------------------------------------------------------------

AC_CACHE_CHECK(for struct in6_addr declaration,
ac_cv_decl_in6_addr_def,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>],[struct in6_addr v;],
ac_cv_decl_in6_addr_def=yes, ac_cv_decl_in6_addr_def=no)
])
if test "$ac_cv_decl_in6_addr_def" = yes; then
    AC_DEFINE(IN6_ADDR,1,[in6_addr defined])
    AC_DEFINE(IPV6,1,[ipV6])
fi


AC_CACHE_CHECK([for struct in_addr6 declaration (LINUX)],
ac_cv_decl_in_addr6_def,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>],[struct in_addr6 v;],
ac_cv_decl_in_addr6_def=yes, ac_cv_decl_in_addr6_def=no)
])
if test "$ac_cv_decl_in_addr6_def" = yes; then
    AC_DEFINE(IN_ADDR6,1,[in_addr6 defined])
    AC_DEFINE(IPV6,1,[ipV6])
fi

dnl ----------------------------------------------------------------------------
dnl struct stat can have a st_mtime_nsec field
dnl ----------------------------------------------------------------------------


AC_CACHE_CHECK(for struct stat has st_mtimespec.tv_nsec,
ac_cv_decl_st_mtimespec_tv_nsec,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/stat.h>],[struct stat statb; statb.st_mtimespec.tv_nsec;],
ac_cv_decl_st_mtimespec_tv_nsec=yes,
ac_cv_decl_st_mtimespec_tv_nsec=no)
])
if test "$ac_cv_decl_st_mtimespec_tv_nsec" = yes; then
    AC_DEFINE_UNQUOTED(ST_MTIMESPEC_TV_NSEC,1,[stat st_mtimespec.tv_nsec present])
fi

AC_CACHE_CHECK(for struct stat has st_mtimensec,
ac_cv_decl_st_mtimensec,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#if defined(HAVE_SYS_TIME_H)
#include <sys/time.h>
#endif
#include <sys/stat.h>],[struct stat statb; statb.st_mtimensec;],
ac_cv_decl_st_mtimensec=yes,
ac_cv_decl_st_mtimensec=no)
])
if test "$ac_cv_decl_st_mtimensec" = yes; then
    AC_DEFINE_UNQUOTED(ST_MTIMENSEC,1,[struct st_mtimensec present])
fi

dnl ----------------------------------------------------------------------------

AC_CACHE_CHECK(for strcasecmp definition,
ac_cv_decl_strcasecmp,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#if defined(HAVE_STDLIB_H)
#include <stdlib.h>
#endif
#if defined(HAVE_STRING_H)
#include <string.h>
#endif
#if defined(HAVE_STRINGS_H)
#include <strings.h>
#endif
],[strcasecmp(1)],
ac_cv_decl_strcasecmp=no,
ac_cv_decl_strcasecmp=yes)
])
if test "$ac_cv_decl_strcasecmp" = yes; then
    AC_DEFINE_UNQUOTED(HAVE_STRCASECMP_DEF,1,[have strcasecmp definition])
fi

dnl ----------------------------------------------------------------------------

AC_CACHE_CHECK(for flock definition,
ac_cv_decl_flock,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#if defined(HAVE_STDLIB_H)
#include <stdlib.h>
#endif
#if defined(HAVE_SYS_FILE_H)
#include <sys/file.h>
#endif
#if defined(HAVE_FCNTL_H)
#include <fcntl.h>
#endif
],[flock(1)],
ac_cv_decl_flock=no,
ac_cv_decl_flock=yes)
])
if test "$ac_cv_decl_flock" = yes; then
    AC_DEFINE_UNQUOTED(HAVE_FLOCK_DEF,1,[have flock definition])
fi

dnl ----------------------------------------------------------------------------

AC_PROG_INSTALL
AC_CHECK_PROG(INSTALL_MAN,auxman,auxman,[$INSTALL -m 644])

AC_PROG_MAKE_SET

dnl ----------------- force this to be Bourne Shell for now ---------------
AC_MSG_CHECKING(for shell)
SHELL=/bin/sh
AC_MSG_RESULT(using $SHELL (FORCED))

AM_GNU_GETTEXT([external])

dnl XX AC_MSG_RESULT([LIBS $LIBS, INTLLIBS $INTLLIBS])
dnl XX  if test "${USE_NLS}" = yes; then
dnl XX    AC_MSG_RESULT([Using NLS, localedir ${LOCALEDIR}, need intl/libintl.a - "${USE_INCLUDED_LIBINTL}" ])
dnl XX    if test "${USE_INCLUDED_LIBINTL}" = yes ; then
dnl XX       CPPFLAGS="$CPPFLAGS -I \${top_builddir}/intl"
dnl XX 	  AC_MSG_RESULT([using \${top_builddir}/intl])
dnl XX 	  if test "$nls_cv_force_use_gnu_gettext" = no ; then
dnl XX 		echo "NLS enabled and requested system gettext support not available."
dnl XX 		echo " You may need to use:"
dnl XX 		echo "  configure 'CPPFLAGS=-I/usr/local/include' 'LDFLAGS=-L/usr/local/lib'"
dnl XX 		echo " See ${srcdir}/ABOUT-NLS.LPRng in the LPRng distribution for details."
dnl XX 		exit 1;
dnl XX       fi
dnl XX 	  if test ! -f ${srcdir}/intl/gettext.h ; then
dnl XX 		echo "gettext code is not in the ${srcdir}/intl directory."
dnl XX 		echo "See ${srcdir}/ABOUT-NLS.LPRng in the LPRng distribution for details."
dnl XX 		exit 1;
dnl XX 	  fi
dnl XX    fi
dnl XX    LIBS="$INTLLIBS $LIBS"
dnl XX  else
dnl XX    AC_MSG_RESULT([No NLS])
dnl XX  fi   
dnl XX  if test "$XGETTEXT" = "" ; then
dnl XX 	 XGETTEXT=xgettext;
dnl XX  fi
dnl XX  AC_MSG_RESULT(using XGETTEXT $XGETTEXT)


if test "${enable_nls}" = yes -a "$nls_cv_force_use_gnu_gettext" != yes \
	-a "$gt_use_preinstalled_gnugettext" != "yes" ; then
	   AC_MSG_ERROR([
NLS enabled and requested system gettext support not available.
You may need to use:
configure 'CPPFLAGS=-I/usr/local/include' 'LDFLAGS=-L/usr/local/lib'
See ABOUT-NLS.LPRng in the LPRng distribution for details.
])
fi
AC_MSG_RESULT([LIBS $LIBS, INTLLIBS $INTLLIBS])

dnl ----------------------------------------------------------------------------
dnl ----------------- END OF GENERAL CONFIGURATION   ---------------------------

dnl check to see if tcp wrappers required
AC_MSG_CHECKING(use tcp wrappers)
AC_ARG_ENABLE( tcpwrappers,
[  --enable-tcpwrappers             use tcp wrappers (-lwrap)],
[
if test "$enableval" = "yes" ; then
 v=yes
 AC_CHECK_HEADERS(tcpd.h,
  [AC_DEFINE(HAVE_TCPD_H,1,[have tcpd])],
  [AC_MSG_ERROR(tcpd.h not found);
   v=no;
  ]
 )
 AC_CHECK_LIB(wrap, request_init,
  [LIBS="-lwrap $LIBS"],
  [AC_MSG_ERROR(request_init not found in -wrap library);
   v=no;
  ]
 )
else
 v=no;
fi
],
[
 v=no;
]
)

if test "$v" = "yes" ; then
	 AC_DEFINE(TCPWRAPPERS,1,[tcpwrappers])
fi
AC_MSG_RESULT($v);dnl

dnl check to see if ssl is disabled
AC_MSG_CHECKING(if ssl authentication is disabled)
AC_ARG_ENABLE( ssl,
[  --disable-ssl                 disable ssl support],
[
if test "$enableval" = "yes" ; then
	v=enabled;  SSL_ENABLE=1;
else
	v=disabled; SSL_ENABLE=;
fi
],
[
	v=enabled;  SSL_ENABLE=1;
],
)
AC_MSG_RESULT($v);dnl

dnl Now look for OpenSSL
ac_openssl_lib_dir=
ac_openssl_inc_dir=
if test "$SSL_ENABLE" != ""; then

	dnl See if we can find OpenSSL
	dnl We can compile without OpenSSL if we have to
	ac_openssl_lib_dir="/usr/lib /usr/local /usr/local/ssl /usr/local/ssl/lib /usr/pkg"
	ac_openssl_inc_dir="/usr/include /usr/local /usr/local/ssl /usr/pkg /usr/local/ssl/include"

	AC_ARG_WITH(openssl,
	[  --with-openssl=DIR          root location for OpenSSL],
	[
		ac_openssl_lib_dir="$withval/lib $withval"
		ac_openssl_inc_dir="$withval/include $withval"
	]
	)

	AC_ARG_WITH(openssl-inc,
	[  --with-openssl-inc        OpenSSL include files],
		ac_openssl_inc_dir=$withval
	)
	AC_ARG_WITH(openssl-lib,
	[  --with-openssl-lib        OpenSSL library files],
		ac_openssl_lib_dir=$withval
	)

	ac_found_openssl_inc_dir="no"
	AC_MSG_CHECKING(for OpenSSL include files)
	for dir in $ac_openssl_inc_dir; do
		if test -f $dir/openssl/ssl.h; then
		   ac_found_openssl_inc_dir=$dir
		   break
		fi
        done
	if test "$ac_found_openssl_inc_dir" != "no"; then
	   	echo "found in $ac_found_openssl_inc_dir"
	else
		echo "not found."
		SSL_ENABLE=""
	fi
fi

if test "$SSL_ENABLE" != ""; then
	ac_found_openssl_lib_dir="no"
	AC_MSG_CHECKING(for OpenSSL libraries)
	for dir in $ac_openssl_lib_dir; do
		found_ssl="false"
		if test -f $dir/libssl.a -a -f $dir/libcrypto.a; then
		  found_ssl="true"
		fi
		if test -f $dir/libssl.so -a -f $dir/libcrypto.so; then
		  found_ssl="true"
		fi
		if $found_ssl != "false"; then
		dnl Ok, we think we've found them, but check that they
		dnl actually ontain the right functions
		save_LIBS=$LIBS
		save_LDFLAGS=$LDFLAGS
		LIBS="-lssl -lcrypto $LIBS"
		LDFLAGS="$LDFLAGS -L$dir "
		AC_TRY_LINK_FUNC(SSL_load_error_strings,ac_linked_libssl="true",
			ac_linked_libssl="false");
		AC_TRY_LINK_FUNC(RC4_set_key,ac_linked_libcrypto="true",
			ac_linked_libcrypto="false");
		if test "$ac_linked_libssl" != "false" -a \
			"$ac_linked_libcrypto" != "false"; then
				ac_found_openssl_lib_dir=$dir
				break
		fi
		LIBS=$save_LIBS
		LDFLAGS=$save_LDFLAGS
		fi
	done
	if test "$ac_found_openssl_lib_dir" != "no"; then
	   	echo "found in $ac_found_openssl_lib_dir"
		CPPFLAGS="$CPPFLAGS -I$ac_found_openssl_inc_dir " ;
	else
		echo "not found."
		SSL_ENABLE=""
	fi
fi

test "$SSL_ENABLE" != "" && AC_DEFINE(SSL_ENABLE,1,[ssl enabled])


dnl  ssl certificate authority CERT file
dnl
AC_MSG_CHECKING(ssl Certificate Authority CERT file)
AC_ARG_WITH(ssl_ca_file,
[  --with-ssl_ca_file=FILE     ssl Certificate Authority CERT file (default \${sysconfdir}/${CONFIG_SUBDIR}/ssl.ca/ca.crt)],
SSL_CA_FILE=$withval,
SSL_CA_FILE=\${sysconfdir}/${CONFIG_SUBDIR}/ssl.ca/ca.crt,
)
AC_MSG_RESULT($SSL_CA_FILE)
AC_SUBST(SSL_CA_FILE)

dnl  ssl certificate authority private key file
dnl
AC_MSG_CHECKING(ssl Certificate Authority private key file)
AC_ARG_WITH(ssl_ca_key,
[  --with-ssl_ca_key=KEY     ssl Certificate Authority private key file (default \${sysconfdir}/${CONFIG_SUBDIR}/ssl.ca/ca.key)],
SSL_CA_KEY=$withval,
SSL_CA_KEY=\${sysconfdir}/${CONFIG_SUBDIR}/ssl.ca/ca.key,
)
AC_MSG_RESULT($SSL_CA_KEY)
AC_SUBST(SSL_CA_KEY)

dnl  ssl certificate authority certs working directory
dnl
AC_MSG_CHECKING(ssl Certificate Authority certs working directory)
AC_ARG_WITH(ssl_certs_dir,
[  --with-ssl_certs_dir=DIR     ssl Certificate Authority certs working directory (default \${sysconfdir}/${CONFIG_SUBDIR}/ssl.certs/)],
SSL_CERTS_DIR=$withval,
SSL_CERTS_DIR=\${sysconfdir}/${CONFIG_SUBDIR}/ssl.certs,
)
AC_MSG_RESULT($SSL_CERTS_DIR)
AC_SUBST(SSL_CERTS_DIR)

dnl  ssl certificate revocation list
dnl
AC_MSG_CHECKING(ssl Certificate Revocation List (CRL) file)
AC_ARG_WITH(ssl_crl_file,
[  --with-ssl_crl_file=PATH     ssl Certificate Revocation List File (default \${sysconfdir}/${CONFIG_SUBDIR}/ssl.crl/ssl.crl)],
SSL_CRL_FILE=$withval,
SSL_CRL_FILE=\${sysconfdir}/${CONFIG_SUBDIR}/ssl.crl/ssl.crl,
)
AC_MSG_RESULT($SSL_CRL_FILE)
AC_SUBST(SSL_CRL_FILE)

dnl  ssl server certificate file
dnl
AC_MSG_CHECKING(ssl server certificate file)
AC_ARG_WITH(ssl_server_cert,
[  --with-ssl_server_cert=FILE     ssl server certificate file (default \${sysconfdir}/${CONFIG_SUBDIR}/ssl.server/server.crt)],
SSL_SERVER_CERT=$withval,
SSL_SERVER_CERT=\${sysconfdir}/${CONFIG_SUBDIR}/ssl.server/server.crt,
)
AC_MSG_RESULT($SSL_SERVER_CERT)
AC_SUBST(SSL_SERVER_CERT)

dnl  ssl server password file for private key file
dnl
AC_MSG_CHECKING(ssl server password file for private key file)
AC_ARG_WITH(ssl_server_password_file,
[  --with-ssl_server_password_file=FILE     ssl server private key in password file (default \${sysconfdir}/${CONFIG_SUBDIR}/ssl.server/server.pwd)],
SSL_SERVER_PASSWORD_FILE=$withval,
SSL_SERVER_PASSWORD_FILE=\${sysconfdir}/${CONFIG_SUBDIR}/ssl.server/server.pwd,
)
AC_MSG_RESULT($SSL_SERVER_PASSWORD_FILE)
AC_SUBST(SSL_SERVER_PASSWORD_FILE)

dnl ----------------------------------------------------------------------------
dnl ---------------- START OF KERBEROS -----------------------------------------

dnl Kerberos stuff again

if test -n "$KERBEROS" ; then
	echo "Kerberos checks with CFLAGS '$CFLAGS', CPPFLAGS '$CPPFLAGS',  LDFLAGS '$LDFLAGS"
	if test -d /usr/kerberos/include; then
		CPPFLAGS="$CPPFLAGS -I/usr/kerberos/include"
	fi
	if test -d /usr/kerberos/lib; then
		LDFLAGS="-L/usr/kerberos/lib $LDFLAGS"
	fi
	dnl Kerberos 5 - release 1.1.1
	found=
	AC_CHECK_HEADERS(krb5.h,found=yes)
    if test "$found" != "yes" ; then
		  AC_MSG_ERROR([
Kerberos 5 support wanted and cannot find krb5.h include file
use configure --disable-kerberos-checks or check your Kerberos 5 installation
If you have installed kerberos in /usr/local/{lib,include} then use
configure --enable-kerberos CPPFLAGS=-I/usr/local/include LDFLAGS=-L/usr/local/lib
])
	fi
	if test "$MIT_KERBEROS4" != "" ; then
		found=
		if test "$found" != "yes" ; then
			AC_CHECK_HEADERS(krb.h,found=yes)
		fi
		if test "$found" != "yes" ; then
			AC_CHECK_HEADERS(kerberosIV/krb.h,found=yes)
		fi
		if test "$found" != "yes" ; then
		  AC_MSG_ERROR(MIT Kerberos 4 support wanted and cannot find krb.h or kerberosIV/krb.h)
		fi
	fi

	if test "$KERBEROS_CHECKS" = 1 ; then
		dnl we have the Kerberos 5 package, lets try for the rest
		AC_TRY_COMPILE([
		#include <stdio.h>
		#include <krb5.h>
		], [printf("%d",sizeof(HostAddress));],
		heimdal=yes, heimdal=no)
		if test $heimdal = yes; then
		    AC_MSG_WARN(compiling with CFLAGS $CFLAGS, CPPFLAGS $CPPFLAGS)
			AC_MSG_ERROR(You appear to be using the Heimdal Kerberos krb5.h file. You must use MIT Kerberos with LPRng)
		fi

		dnl we check for the library we need to use
		dnl courtesy of mandrake linux and friends.
		dnl  Christian Zoffoli <czoffoli@linux-mandrake.com>
dnl X		SAVELIBS=$LIBS
dnl X		found=
dnl X		if test "$found" = "" ; then
dnl X			LIBS=" -lcrypto -lcom_err $SAVELIBS"
dnl X			AC_CHECKING(for krb5_des_string_to_key in $LIBS, )
dnl X			AC_TRY_LINK_FUNC(krb5_des_string_to_key,found="yes")
dnl X		fi;
dnl X		if test "$found" = "" ; then
dnl X			LIBS=" -lk5crypto -lcom_err $SAVELIBS"
dnl X			AC_CHECKING(for krb5_des_string_to_key in $LIBS, )
dnl X			AC_TRY_LINK_FUNC(krb5_des_string_to_key,found="yes")
dnl X		fi;
dnl X		if test "$found" = "" ; then
dnl X			echo "Kerberos 5 encryption support library not found."
dnl X			echo " You may need to use:"
dnl X			echo "  configure 'CPPFLAGS=-I/usr/local/include' 'LDFLAGS=-L/usr/local/lib'"
dnl X			exit 1
dnl X		fi

		SAVELIBS=$LIBS

		found=no
		if test "$found" "!=" "yes" ; then
			found=yes
			LIBS=" -lkrb5 -lcrypto -lcom_err $SAVELIBS"
			AC_CHECKING(for krb5_init_context and krb5_read_message in $LIBS )
			AC_TRY_LINK_FUNC(krb5_init_context,,found="no")
			AC_TRY_LINK_FUNC(krb5_read_message,,found="no")
		fi;
		if test "$found" "!=" "yes" ; then
			found=yes
			LIBS=" -lkrb5 -lk5crypto -lcom_err $SAVELIBS"
			AC_CHECKING(for krb5_init_context and krb5_read_message in $LIBS )
			AC_TRY_LINK_FUNC(krb5_init_context,,found="no")
			AC_TRY_LINK_FUNC(krb5_read_message,,found="no")
		fi;
		if test "$found" "!=" "yes" ; then
			  AC_MSG_WARN(Kerberos 5 library does not have krb5_init_context or krb5_read_message )
			  AC_MSG_WARN(use configure --disable-kerberos or check your Kerberos 5 installation)
			  exit 1
        fi
		AC_MSG_RESULT(found in $LIBS)

		if test "$MIT_KERBEROS4" != "" ; then
			SAVELIBS=$LIBS
			found=;
			if test "$found" = "" ; then
				LIBS=" -lkrb4 -ldes425 $SAVELIBS"
				AC_CHECKING(for krb_recvauth in $LIBS, )
				AC_TRY_LINK_FUNC(krb_recvauth,found="yes")
			fi;
			if test "$found" = "" ; then
				LIBS=" -lkrb4 -ldes $SAVELIBS"
				AC_CHECKING(for krb_recvauth in $LIBS, )
				AC_TRY_LINK_FUNC(krb_recvauth,found="yes")
			fi;
			if test "$found" = "" ; then
			  AC_MSG_WARN(MIT Kerberos 4 support wanted and cannot find krb_recvauth in Kerberos 4 libraries)
			  exit 1
            fi
		fi;
	fi

	AC_CHECK_FUNCS(krb5_free_data_contents)

	AC_CACHE_CHECK(for krb5_xfree,
	ac_cv_krb5_xfree,
	[AC_TRY_LINK([
	# define KRB5_DEPRECATED 1
	#if defined(HAVE_KRB5_H)
	#include <krb5.h>
	#endif
	],[krb5_xfree((void *)0);],
	ac_cv_krb5_xfree=yes,
	ac_cv_krb5_xfree=no)
	])
	if test "$ac_cv_krb5_xfree" = yes; then
		AC_DEFINE_UNQUOTED(HAVE_KRB5_XFREE,1,[have krb5_xfree])
	fi

	AC_CACHE_CHECK(for krb_xfree,
	ac_cv_krb_xfree,
	[AC_TRY_LINK([
	# define KRB5_DEPRECATED 1
	#if defined(HAVE_KRB5_H)
	#include <krb5.h>
	#endif
	],[krb_xfree((void *)0);],
	ac_cv_krb_xfree=yes,
	ac_cv_krb_xfree=no)
	])
	if test "$ac_cv_krb_xfree" = yes; then
		AC_DEFINE_UNQUOTED(HAVE_KRB_XFREE,1,[have krb_xfree])
	fi

	AC_CACHE_CHECK(for kerberos 4 krb_sendauth definition,
	ac_cv_decl_krb_sendauth_def,
	[AC_TRY_COMPILE([
	# define KRB5_DEPRECATED 1
	#if defined(HAVE_KRB5_H)
	#include <krb5.h>
	#endif
	#if defined(HAVE_KRB_H)
	#include <krb.h>
	#include <des.h>
	#endif
	#if defined(HAVE_KERBEROSIV_KRB_H)
	#include <kerberosIV/krb.h>
	#include <kerberosIV/des.h>
	#endif
	],[printf("%d",krb_sendauth(1));],
	ac_cv_decl_krb_sendauth_def=no,
	ac_cv_decl_krb_sendauth_def=yes)
	])
	if test "$ac_cv_decl_krb_sendauth_def" = yes; then
		AC_DEFINE_UNQUOTED(HAVE_KRB_AUTH_DEF,1,[have krb_sendauth defined])
	fi

fi;

dnl ----------------------------------------------------------------------------
dnl ---------------- END OF KERBEROS -----------------------------------------


dnl ----------------------------------------------------------------------------
dnl ----------------- START OF OUTPUT ------------------------------------------


if test "$ac_cv_prog_gcc" = yes; then
	CFLAGS="$CFLAGS -g -W -Wall $werror -Wno-unused "
	CPPFLAGS="$CPPFLAGS -g -W -Wall $werror -Wno-unused "
fi;

AC_OUTPUT( po/Makefile.in 
[
Makefile
DOCS/Makefile
TESTSUPPORT/Makefile
DISTRIBUTIONS/Makefile
UTILS/LPRng.pm
UTILS/Makefile
UTILS/accounting.pl
UTILS/decode_args_with_perl
UTILS/decode_args_with_sh
UTILS/fixid
UTILS/fixupdate
UTILS/lpq_in_perl
UTILS/lpr_in_perl
UTILS/lprm_in_perl
UTILS/make_lpd_conf
UTILS/make_printcap_use
UTILS/makeinc
UTILS/read_conf
UTILS/remote_active
UTILS/test_read
UTILS/update_z.pl
lpd.perms
man/Makefile
src/Makefile
src/pclbanner
src/psbanner
po/Makefile.in
],
[
for i in  \
UTILS/LPRng.pm \
UTILS/accounting.pl \
UTILS/decode_args_with_perl \
UTILS/decode_args_with_sh \
UTILS/fixid \
UTILS/fixupdate \
UTILS/lpq_in_perl \
UTILS/lpr_in_perl \
UTILS/lprm_in_perl \
UTILS/make_lpd_conf \
UTILS/make_printcap_use \
UTILS/makeinc \
UTILS/read_conf \
UTILS/remote_active \
UTILS/test_read \
UTILS/update_z.pl \
; do chmod +x $i ; done
]

)

dnl ----------------------------------------------------------------------------
dnl ----------------- END OF OUTPUT --------------------------------------------
