dnl process this file with GNU autoconf to produce a configure script.
dnl
dnl $Id: configure.in,v 1.141 2004/10/05 15:50:11 papowell Exp papowell $

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

PACKAGE=ifhp
VERSION=3.5.20

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"

AC_AIX
AC_ISC_POSIX
AC_MINIX

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(PERL,perl)dnl
AC_SUBST(PERL)dnl

WITH_CCOPTS dnl
WITH_CPPOPTS dnl
WITH_LDOPTS dnl

if test -z "$LOCALEDIR" ; then
    LOCALEDIR='$(prefix)/share/locale'
fi;

WITH_LOCALEDIR dnl

AC_DISABLE_SHARED
AM_PROG_LIBTOOL

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

v="cannot open";
AC_PATH_PROG(FILEUTIL,file,FILE_UTILITY_NOT_FOUND)dnl
if test "$FILEUTIL" != "FILE_UTILITY_NOT_FOUND" ; then
	if ${FILEUTIL} - </etc/passwd 2>/dev/null ; then
		echo "the '${FILEUTIL} -'  operates correctly";
	else
		echo "Please use a file utility that handles 'file - 'correctly";
		echo "You can obtain one from: ftp://ftp.astron.com/pub/file/";
		echo " or ftp://ftp.lprng.com/pub/LPRng/UNIXTOOLS/file/";
		echo "if necessary, use the FILEUTIL environment variable to specify the path"
		exit 1
	fi
fi
AC_SUBST(FILEUTIL)dnl
AC_PATH_PROG(GZIP,gzip,GZIP_NOT_FOUND)dnl
AC_SUBST(GZIP)dnl
AC_PATH_PROG(GS,gs,GHOSTSCRIPT_NOT_FOUND)dnl
AC_SUBST(GS)dnl
AC_PATH_PROG(A2PS,a2ps,A2PS_NOT_FOUND)dnl
AC_SUBST(A2PS)dnl
AC_PATH_PROG(CAT,cat,CAT_NOT_FOUND)dnl
AC_SUBST(CAT)dnl

AC_MSG_CHECKING(directory where to install the ifhp.conf file)
AC_ARG_WITH(ifhp_conf,
[  --with-ifhp_conf=path   ifhp.conf config file (default \${sysconfdir}/ifhp.conf)],
IFHP_CONF=$withval,
IFHP_CONF=\${sysconfdir}/ifhp.conf,
)
AC_MSG_RESULT($IFHP_CONF)
AC_SUBST(IFHP_CONF)


dnl ---------------------------------------------------------------------------
dnl ---------- XXXXXX END OF OPTIONS ------------------------------------------

AC_MSG_CHECKING(use snmp)
AC_ARG_ENABLE(snmp,
[  --disable-snmp       disable snmp support],
[
if test "$enableval" = "yes" ; then
	SNMP="yes";
else
	SNMP="no";
fi
],
[ SNMP="yes"; ]
)
AC_MSG_RESULT($SNMP)
AC_SUBST(SNMP)

if test "$SNMP" = yes ; then
	if perl -MNet::SNMP -e exit ; then 
	:
	else
	AC_MSG_ERROR([
SNMP support enabled and the Net::SNMP module not installed.
Get the NET-SNMP libraries from http://www.sourceforge.net
Get the Net::SNMP perl modules from http://www.cpan.org
]);
		
	fi
fi

AC_MSG_CHECKING(foomatic-rip)
AC_ARG_WITH(foomatic-rip,
[  --with-foomatic-rip=PATH   path to foomatic-rip],
FOOMATIC_RIP=$withval,
[AC_PATH_PROG(FOOMATIC_RIP,foomatic-rip)]
)
dnl AC_MSG_RESULT($FOOMATIC_RIP)
AC_SUBST(FOOMATIC_RIP)

AC_MSG_CHECKING(use foomatic)
AC_ARG_ENABLE(foomatic,
[  --disable-foomatic       disable foomatic support],
[
if test "$enableval" = "yes" ; then
	FOOMATIC="1";
else
	FOOMATIC="0";
fi
],
[ FOOMATIC="1"; ]
)
AC_MSG_RESULT($FOOMATIC)
AC_SUBST(FOOMATIC)

if test "${FOOMATIC}" "!=" 0 -a "${FOOMATIC_RIP}" = "" ; then
	AC_MSG_ERROR([
foomatic enabled and foomatic-rip not found
Download foomatic-filters from:
  http://www.linuxprinting.org/download/foomatic
]);
fi

AC_MSG_CHECKING(default page size)
AC_ARG_WITH(pagesize,
[  --with-pagesize=SIZE     default page size (default letter)],
PAGE_SIZE=$withval,
PAGE_SIZE=letter,
)
AC_MSG_RESULT($PAGE_SIZE)
AC_SUBST(PAGE_SIZE)

AC_SUBST(FILTER_DIR)
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)

AC_MSG_CHECKING(font directory)
AC_ARG_WITH(fontdir,
[  --with-fontdir=DIR     font directory (default \${libexecdir}/filters/fonts)],
FONT_DIR=$withval,
FONT_DIR=\${libexecdir}/filters/fonts,
)
AC_MSG_RESULT($FONT_DIR)
AC_SUBST(FONT_DIR)

dnl default strip binaries 
AC_MSG_CHECKING(strip 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 dislabel ghostscript check
AC_MSG_CHECKING(GhostScript check)
AC_ARG_ENABLE( gscheck,
[  --disable-gscheck      disable checking GhostScript for security flaw],
[
if test "$enableval" = "yes" ; then
	GSCHECK=yes;
else
	GSCHECK=no;
fi
],
[
	GSCHECK=no;
],
)
AC_MSG_RESULT($GSCHECK)
AC_SUBST(GSCHECK)

if test "$GS" != "GHOSTSCRIPT_NOT_FOUND" -a "$GSCHECK" != "no" ; then
  AC_MSG_CHECKING(GhostScript -dSAFER and -dPARANOIDSAFER option)
  if $GS -q -dBATCH -dNOPAUSE -dSAFER -dPARANOIDSAFER -sDEVICE=nullpage -sOutputFile=- $srcdir/gsQuit ; then
    if $GS -q -dBATCH -dNOPAUSE -dSAFER -dPARANOIDSAFER -sDEVICE=nullpage -sOutputFile=- $srcdir/gsTest 1>/dev/null 2>/dev/null ; then
  	  AC_MSG_WARN( [
WARNING: '($GS) -dSAFER -dPARANOIDSAFER ' allows files to be read
Please read README.GhostScriptSecurityProblem
and fix your distribution of GhostScript
OR use:
configure --disable-gscheck
] )
      AC_MSG_RESULT(GhostScript security hole found!)
	  exit 1
    else
      AC_MSG_RESULT(no GhostScript security hole found)
    fi
  else
    AC_MSG_RESULT(Error with: $GS -q -dSAFER -dPARANOIDSAFER -sDEVICE=nullpage -sOutputFile=- )
  fi
fi


AC_MSG_CHECKING(how to redirect GhostScript output to fd 3)
if test "$DEVFD3" = "" ; then
	v=`( if test -d /dev/fd ; then echo 3 >/dev/fd/3; fi) 2>/dev/null 3>&1 1>&2`
	if test "$v" != "" ; then
		DEVFD3=/dev/fd/3
		FD3=/dev/fd/3
	else
		DEVFD3="|$CAT >\&3"
		FD3="|$CAT >&3"
	fi
	rm -f gs_out
	gs -q -dBATCH -dNOPAUSE -dSAFER -dPARANOIDSAFER -sDEVICE=laserjet "-sOutputFile=${FD3}" ${srcdir}/gsPrint 3>gs_out
	if test "!" -s gs_out ; then
		AC_MSG_ERROR( "ERROR - gs cannot handle -sOutputFile=$OUT" );
	fi
fi
AC_MSG_RESULT($DEVFD3)
AC_SUBST(DEVFD3)


dnl ----------------------------------------------------------------------------
dnl -----------   C compiler checks    -----------------------------------------
AC_PROG_CC
AC_PROG_CPP

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
AC_MSG_WARN( [
WARNING: gcc -O (version 2.4.5 and below) produces incorrect code
for lpd.c and other large routines.
] )
	fi;
fi;

LDCC="$CC"
AC_MSG_RESULT(using CPPFLAGS=\"${CPPFLAGS}\", CFLAGS=\"${CFLAGS}\")

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(ARCHITECTURE,"$target_cpu",[target CPU])
AC_DEFINE_UNQUOTED(OSNAME,"$osword",[target os name])
AC_DEFINE_UNQUOTED(OSVERSION,$version,[target os version])
ARCHITECTURE=$target_cpu
OSNAME=$osword
OSVERSION=$version
AC_SUBST(ARCHITECTURE)
AC_SUBST(OSNAME)
AC_SUBST(OSVERSION)



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

AC_C_CONST
AC_C_INLINE

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_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;
		;;
	 *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 6])
		;;
	 *irix5* )
		checklibs=no
		AC_DEFINE(HAVE_BROKEN_TIOCEXCL,1,[broken tiocexcl])
		AC_DEFINE(SVR4,1,[have SVR4])
		AC_DEFINE_UNQUOTED(IRIX,$version,[IRIX 5])
		;;
	 *irix* )
		checklibs=no
		AC_DEFINE_UNQUOTED(IRIX,$version,[IRIX])
		;;
	*solaris* )
		AC_DEFINE(SVR4,1,[have SVR4])
		AC_DEFINE_UNQUOTED(SOLARIS,$version,[solaris])
		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,[SUNOS version])
		;;
	osf* )
		AC_DEFINE_UNQUOTED(DECALPHA,$version,[DEC ALPHA version])
		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

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 killpg lockf mkstemp)
AC_CHECK_FUNCS(mktemp openlog putenv random rand setenv seteuid setruid setlinebuf setlocale setpgid setproctitle)
AC_CHECK_FUNCS(setresuid setreuid setsid setvbuf 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
	AC_MSG_WARN( [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,[define use_stty])
fi
if test "$ac_cv_struct_term" = "termio"; then
	AC_DEFINE(USE_TERMIO,1,[use termio])
	AC_DEFINE(USE_STTY,TERMIO,[define use_stty])
fi
if test "$ac_cv_struct_term" = "termios"; then
	AC_DEFINE(USE_TERMIOS,1,[use termios])
	AC_DEFINE(USE_STTY,TERMIOS,[define use_stty])
	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 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 proto])
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,[statfs type svr3])
fi
if test "$ac_cv_struct_fstype" = Ultrix-statfs; then
	AC_DEFINE(USE_STATFS_TYPE,ULTRIX_STATFS,[statfs type ultrix])
fi
if test "$ac_cv_struct_fstype" = statfs; then
	AC_DEFINE(USE_STATFS_TYPE,STATFS,[statfs type statfs])
fi
if test "$ac_cv_struct_fstype" = statvfs; then
	AC_DEFINE(USE_STATFS_TYPE,STATVFS,[statfs type sysv])
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 decl])
	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 decl])
	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,[have sys_errlist decl])
	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,[have setproctitle])
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,[have sys_siglist def])
	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,[have _sys_siglist def])
	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_siglist])
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 check to see if you have getpgrp(0) or getpgrp()
dnl
dnl POSIX `getpgrp(void)'  define HAVE_GETPGRP_0
dnl BSD   `getpgrp(int)' - takes 0 as argument
dnl                        define HAVE_GETPGRP_0 0

dnl check to see if you have getpgrp(0) or getpgrp()

AC_CACHE_CHECK([for getprgp() or getpgrp(0) form],
ac_cv_func_getpgrp_0,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#include <sys/types.h>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif],[getpgrp(0);],
ac_cv_func_getpgrp_0=getpgrp_0, ac_cv_func_getpgrp_0=getpgrp)
])
if test "$ac_cv_func_getpgrp_0" = getpgrp_0; then
AC_DEFINE(HAVE_GETPGRP_0,0,[set getprgrp 0])
else
AC_DEFINE(HAVE_GETPGRP_0,1,[set getpgrgp 1])
fi

dnl ----------------------------------------------------------------------------
dnl check to see if you have setpgrp(n,m) or setpgrp()

AC_CACHE_CHECK(for setprgp form,
ac_cv_func_setpgrp_0,
[AC_TRY_COMPILE([
#ifdef HAVE_CTYPES_H
#include <ctypes.h>
#endif
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
#ifdef HAVE_UNISTD_H
# include <unistd.h>
#endif
],[setpgrp(0,0);],
	ac_cv_func_setpgrp_0=setpgrp_0, ac_cv_func_setpgrp_0=setpgrp)
])
if test "$ac_cv_func_setpgrp_0" = setpgrp_0; then
	AC_DEFINE(HAVE_SETPGRP_0,1,[set setpgrp 0])
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 getbostname def])
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,[have innetgr def])
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 def])
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 def])
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,[have in6_addr])
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,[have in_addr6])
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,[have mtimespec])
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,[have mtimensec])
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 def])
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 def])
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))

dnl ----------------- Option for enabling GNU gettext --------------------

AM_GNU_GETTEXT([external])

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

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

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


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

AC_OUTPUT(
Makefile src/Makefile man/Makefile fonts/Makefile
DOCS/Makefile
UTILS/accounting.sh UTILS/sendhp.sh UTILS/supported
UTILS/fixupdate
src/extract_pjl
src/wrapper
po/Makefile.in
)

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