dnl
dnl Copyright (c) 2000-2004 QoSient, LLC
dnl All rights reserved.
dnl
dnl This program is free software; you can redistribute it and/or modify
dnl it under the terms of the GNU General Public License as published by
dnl the Free Software Foundation; either version 2, or (at your option)
dnl any later version.
dnl                
dnl This program is distributed in the hope that it will be useful,
dnl but WITHOUT ANY WARRANTY; without even the implied warranty of
dnl MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
dnl GNU General Public License for more details. 
dnl                
dnl You should have received a copy of the GNU General Public License 
dnl along with this program; if not, write to the Free Software
dnl Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.  */
dnl
dnl
dnl Process this file with autoconf to produce a configure script.
dnl

AC_INIT(server/argus.c)

dnl all our local stuff like install scripts and include files
dnl is in there
AC_CONFIG_AUX_DIR(config)

AC_CANONICAL_SYSTEM

AC_LBL_C_INIT(V_CCOPT, V_INCLS)
AC_C_INLINE

dnl where we install our stuff ...
AC_PREFIX_DEFAULT( /usr/local )

dnl Minimum Autoconf version required.
AC_PREREQ(2.13)

AC_PROG_CC
AC_PROG_CPP
AC_PROG_MAKE_SET
AC_PROG_RANLIB
AC_QOSIENT_LEX_AND_YACC(V_LEX, V_YACC, argus_)
AC_CHECK_PROGS(V_RANLIB, ranlib, @true)

if test -z "$with_pcap" && test "$cross_compiling" = yes; then
        AC_MSG_ERROR(pcap type not determined when cross-compiling; use --with-pcap=...)
fi
AC_ARG_WITH(pcap, [  --with-pcap=TYPE        use packet capture TYPE])
AC_MSG_CHECKING(packet capture type)
if test ! -z "$with_pcap" ; then
        V_PCAP="$withval"
elif test -r /dev/bpf0 ; then
        V_PCAP=bpf
elif test -r /usr/include/net/pfilt.h ; then
        V_PCAP=pf
elif test -r /dev/enet ; then
        V_PCAP=enet
elif test -r /dev/nit ; then
        V_PCAP=snit
elif test -r /usr/include/sys/net/nit.h ; then
        V_PCAP=nit
elif test -r /usr/include/net/raw.h ; then
        V_PCAP=snoop
elif test -r /usr/include/sys/dlpi.h ; then
        V_PCAP=dlpi
elif test -r /usr/include/linux/socket.h ; then
        V_PCAP=linux
elif test -c /dev/bpf0 ; then           # check again in case not readable
        V_PCAP=bpf
elif test -c /dev/enet ; then           # check again in case not readable
        V_PCAP=enet
elif test -c /dev/nit ; then            # check again in case not readable
        V_PCAP=snit
else
        V_PCAP=null
fi
AC_MSG_RESULT($V_PCAP)

AC_LBL_UNALIGNED_ACCESS
AC_LBL_DEVEL(V_CCOPT)
AC_QOSIENT_DEBUG(V_CCOPT)
AC_CMU_SASL
AC_SYS_LARGEFILE

AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)
if test ! -z "$V_PCAPDEP"; then
if test -f $V_PCAPDEP; then
        if test -f lib/libpcap.a; then
           rm -rf lib/libpcap.a
        fi
	pcapdir=`echo $V_PCAPDEP | sed -e 's/^\.\./..\/../'`
        ln -s $pcapdir lib/libpcap.a
        V_PCAPDEP="../lib/libpcap.a"
else
        if test $V_PCAPDEP = "-lpcap" ; then
                if test -f lib/libpcap.a; then
                        rm -rf lib/libpcap.a
                fi
        fi
        if test $V_PCAPDEP = "-lwpcap" ; then
                if test -f lib/libpcap.a; then
                        rm -rf lib/libpcap.a
                fi
        fi
fi
LIBS="$LIBS $V_PCAPDEP"
fi


AC_QOSIENT_TCPWRAP(V_WRAPDEP, V_INCLS)
if test ! -z "$V_WRAPDEP"; then
	if test -f $V_WRAPDEP; then
		if test -f lib/libwrap.a; then
			rm -rf lib/libwrap.a
		fi
		wrapdir=`echo $V_WRAPDEP | sed -e 's/^\.\./..\/../'`
        	ln -s $wrapdir lib/libwrap.a
		V_WRAPDEP="../lib/libwrap.a"
		AC_DEFINE(HAVE_TCP_WRAPPER)
		LIBS="$LIBS $V_WRAPDEP"
	else
		if test $V_WRAPDEP = "-lwrap" ; then
			AC_DEFINE(HAVE_TCP_WRAPPER)
			case "$target_os" in
			linux*)
				LIBS="-lnsl $LIBS" ;;
			esac
        	fi
	fi
fi

umask 002

if test -z "$PWD"; then
	PWD=`pwd`
fi

AC_HAVE_HEADERS(sys/sockio.h string.h fcntl.h sys/file.h syslog.h)
AC_CHECK_FUNCS(ether_hostton strerror)

case "$target_cpu" in
 
*86*)
        AC_DEFINE(CONFIG_X86_BSWAP,1)
        ;;
 
powerpc*)
        V_CCOPT="-mpowerpc $V_CCOPT"
        ;;
esac


case "$target_os" in

aix*)
	dnl Workaround to enable certain features
	AC_DEFINE(_SUN)
	;;

hpux9*)
	AC_DEFINE(HAVE_HPUX9)
	;;

hpux10.0*)
	;;

hpux10.1*)
	;;

hpux*)
	dnl HPUX 10.20 and above is similar to HPUX 9...
	AC_DEFINE(HAVE_HPUX10_20)
	;;

sinix*)
	AC_MSG_CHECKING(if SINIX compiler defines sinix)
	AC_CACHE_VAL(ac_cv_cc_sinix_defined,
		AC_TRY_COMPILE(
		    [],
		    [int i = sinix;],
		    ac_cv_cc_sinix_defined=yes,
		    ac_cv_cc_sinix_defined=no))
	    AC_MSG_RESULT($ac_cv_cc_sinix_defined)
	    if test $ac_cv_cc_sinix_defined = no ; then
		    AC_DEFINE(sinix)
	    fi
	;;

solaris*)
	AC_DEFINE(HAVE_SOLARIS,1,[On solaris])
	AC_MSG_CHECKING(for LD_LIBRARY_PATH, since you appear to be running Solaris)
	if test x$LD_LIBRARY_PATH != x ; then
		LIBS="$LIBS -R$LD_LIBRARY_PATH"
		AC_MSG_RESULT(yes -- added LD_LIBRARY_PATH to run-time linker path)
	else
		AC_MSG_RESULT(no -- this may be a problem in a few seconds)
	fi
	COMPATLIB="-lsocket -lnsl"
	;;

cygwin*)
	AC_DEFINE(CYGWIN,1)
	V_INCLS="$V_INCLS -I../include/cygwin-include"
	;;

linux*)
	;;
esac

INSTALL_LIB="../lib"
INSTALL_BIN="../bin"

AC_SUBST(V_PCAP)
AC_SUBST(V_CCOPT)
AC_SUBST(V_INCLS)
AC_SUBST(V_RANLIB)
AC_SUBST(V_PCAPDEP)
AC_SUBST(V_WRAPDEP)
AC_SUBST(V_YACC)
AC_SUBST(V_LEX)
AC_SUBST(LIBS)
AC_SUBST(COMPATLIB)
AC_SUBST(INSTALL_LIB)
AC_SUBST(INSTALL_BIN)

AC_PROG_INSTALL
AC_STDC_HEADERS

AC_OUTPUT(
   Makefile
   ./common/Makefile
   ./server/Makefile
)

if test -f .devel ; then
	make depend
fi
exit 0
