dnl Process this file with autoconf to produce a configure script.
AC_INIT(tcp-lp.c)
AC_CONFIG_AUX_DIR(.)
AC_CANONICAL_SYSTEM
AC_CONFIG_HEADER(config.h)
AC_PREFIX_DEFAULT(/usr/local)
AC_SUBST(INSTALL)
AC_SUBST(INSTALL_MAN)
AC_SUBST(SHELL)
AC_SUBST(CPP)
AC_SUBST(CFLAGS)
AC_SUBST(LDCC)

dnl Checks for programs.
AC_PROG_CC
AC_PROG_INSTALL

dnl ----------------------------------------------------------------------------
dnl ------------   OS Checks  --------------------------------------------------
AC_ISC_POSIX
AC_MINIX
AC_AIX



changequote(, )dnl
version=`echo $target_os | sed -e 's/[^0-9][^0-9]*//' -e 's/\.//g'`
changequote([, ])dnl
echo "Target is $target, arch $target_cpu, os $target_os, version $version"
AC_DEFINE_UNQUOTED(ARCHITECTURE,"$target_cpu")

LDCC="$CC"
checklibs=
case $target_os in
	 linux* )
		no_resolv_lib=yes;
		;;
	 bsdi* )
		LDCC=shlicc
		;;
	 unicos* )
		checklibs=no
		;;
	 irix6* )
		checklibs=no
		AC_DEFINE_UNQUOTED(IRIX,$version)
		LIBS="$LIBS -lcurses"
		;;
	 irix5* )
		checklibs=no
		AC_DEFINE(HAVE_BROKEN_TIOCEXCL)
		AC_DEFINE(SVR4)
		AC_DEFINE_UNQUOTED(IRIX,$version)
		LIBS="$LIBS -lcurses"
		;;
	 irix* )
		checklibs=no
		AC_DEFINE_UNQUOTED(IRIX,$version)
		LIBS="$LIBS -ltermcap"
		;;
	solaris* )
		AC_DEFINE(SVR4)
		if test $version -lt 100 ; then
			version=`expr $version \* 10 `;
			echo "using version $version";
		fi;
		no_resolv_lib=yes;
		AC_DEFINE_UNQUOTED(SOLARIS,$version)
		;;
	hpux* )
		AC_DEFINE(_HPUX_SOURCE)
		CFLAGS="$CFLAGS -D_HPUX_SOURCE=1"
		AC_DEFINE_UNQUOTED(HPUX,$version)
		if test $ac_cv_prog_gcc != yes; then
			echo "HP UX and not using GCC, adding -Aa flag for compilation";
			CFLAGS="$CFLAGS -Aa";
		fi;
		;;
	sunos* )
		AC_DEFINE_UNQUOTED(SUNOS,$version)
		;;
	alpha*dec*osf* )
		AC_DEFINE_UNQUOTED(DECALPHA,$version)
		;;
esac

AC_CHECK_HEADER(elf.h, AC_DEFINE(SVR4) LIBS="$LIBS -lelf")

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h sys/fcntl.h sys/time.h)
AC_CHECK_HEADERS(stdarg.h stdlib.h varargs.h unistd.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_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(select socket strerror)

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

AC_MSG_CHECKING(for sys_nerr)
AC_CACHE_VAL(ac_cv_decl_sys_nerr,
[AC_TRY_LINK(,[extern int sys_nerr; return (sys_nerr);],
	ac_cv_decl_sys_nerr=yes, ac_cv_decl_sys_nerr=no)
])
AC_MSG_RESULT($ac_cv_decl_sys_nerr)
if test $ac_cv_decl_sys_nerr = yes; then
	AC_DEFINE(HAVE_SYS_NERR)
fi;

AC_MSG_CHECKING(for sys_nerr declaration)
AC_CACHE_VAL(ac_cv_decl_sys_nerr_def,
[AC_TRY_LINK([
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif],[printf("%d",sys_nerr);],
ac_cv_decl_sys_nerr_def=yes, ac_cv_decl_sys_nerr_def=no)
])
AC_MSG_RESULT($ac_cv_decl_sys_nerr_def)
if test $ac_cv_decl_sys_nerr_def = yes; then
    AC_DEFINE(HAVE_SYS_NERR_DEF)
fi

AC_MSG_CHECKING(for sys_errlist array)
AC_CACHE_VAL(ac_cv_decl_sys_errlist,
[AC_TRY_LINK(,[extern char *sys_errlist[];
	sys_errlist[0];],
	ac_cv_decl_sys_errlist=yes, ac_cv_decl_sys_errlist=no)
])
AC_MSG_RESULT($ac_cv_decl_sys_errlist)
if test $ac_cv_decl_sys_errlist = yes; then
	AC_DEFINE(HAVE_SYS_ERRLIST)
fi

AC_MSG_CHECKING(for sys_errlist declaration)
AC_CACHE_VAL(ac_cv_decl_sys_errlist_def,
[AC_TRY_LINK([
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif],[printf("%s",sys_errlist[1]);],
ac_cv_decl_sys_errlist_def=yes, ac_cv_decl_sys_errlist_def=no)
])
AC_MSG_RESULT($ac_cv_decl_sys_errlist_def)
if test $ac_cv_decl_sys_errlist_def = yes; then
    AC_DEFINE(HAVE_SYS_ERRLIST_DEF)
fi


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

AC_MSG_CHECKING(for sys_siglist array)
AC_CACHE_VAL(ac_cv_decl_sys_siglist,
[AC_TRY_LINK(,[extern char *sys_siglist[]; sys_siglist[1][0] = 0;],
	ac_cv_decl_sys_siglist=yes, ac_cv_decl_sys_siglist=no)
])
AC_MSG_RESULT($ac_cv_decl_sys_siglist)
if test $ac_cv_decl_sys_siglist = yes; then
	AC_DEFINE(HAVE_SYS_SIGLIST)
fi

AC_MSG_CHECKING(for sys_siglist declaration)
AC_CACHE_VAL(ac_cv_decl_sys_siglist_def,
[AC_TRY_LINK([
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#ifdef HAVE_STDLIB_H
#include <stdlib.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif],[printf("%s",sys_siglist[1]);],
ac_cv_decl_sys_siglist_def=yes, ac_cv_decl_sys_siglist_def=no)
])
AC_MSG_RESULT($ac_cv_decl_sys_siglist_def)
if test $ac_cv_decl_sys_siglist_def = yes; then
    AC_DEFINE(HAVE_SYS_SIGLIST_DEF)
fi


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

AC_PROG_RANLIB
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))

AC_OUTPUT(Makefile Makefile.bsd)
