AC_REVISION([@(#) $Id: configure.in 1541 2024-01-21 22:07:05Z leres $ (LBL)])
dnl
AC_COPYRIGHT([Copyright (c) 1994, 1995, 1996, 1997, 1998, 2000, 2006, 2009, 2010, 2011, 2013, 2016, 2017, 2019, 2020, 2021, 2023, 2024
	The Regents of the University of California.  All rights reserved.])
dnl
dnl Process this file with autoconf to produce a configure script.
dnl

AC_PREREQ([2.71])
AC_INIT
AC_CONFIG_SRCDIR(arpwatch.c)

AC_CANONICAL_TARGET

umask 002

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

AC_LBL_C_INIT(V_CCOPT, V_INCLS)
AC_PROG_INSTALL

AC_CHECK_HEADERS(fcntl.h memory.h)

AC_REPLACE_FUNCS(strerror)

AC_ARG_ENABLE([zeropad],
    [AS_HELP_STRING([--enable-zeropad],
    [zero pad displayed ethernet addresses by default])],
    ac_cv_enable_zeropad=${enableval})

if test "${ac_cv_enable_zeropad}" = yes ; then
	AC_DEFINE(MANZFLAG,[ (default)])
	AC_DEFINE(ZEROPAD)
	MANZFLAG=" (default)"
	MACZERO=0
	ZEROPAD=1
else
	AC_DEFINE(MANCFLAG,[ (default)])
	AC_DEFINE(ZEROPAD,0)
	AC_DEFINE(MACZERO,0)
	MACZERO=
	ZEROPAD=0
fi

dnl The following generates a warning from autoconf...
dnl AC_C_BIGENDIAN

AC_LBL_UNION_WAIT

AC_CHECK_LIB(resolv, res_query)
AC_LBL_LIBPCAP(V_PCAPDEP, V_INCLS)

AC_ARG_WITH(sendmail,
    AS_HELP_STRING([--with-sendmail=path],
    [path to sendmail]))
if test -n "${with_sendmail}"; then
	V_SENDMAIL=${with_sendmail}
	AC_MSG_RESULT(sendmail hardwired to ${V_SENDMAIL})
else
	AC_PATH_PROG(V_SENDMAIL, sendmail,,
	    $PATH:/usr/sbin:/usr/lib:/usr/bin:/usr/ucblib:/usr/local/etc)

	if test -z "${V_SENDMAIL}" ; then
		AC_MSG_ERROR([Can't find sendmail])
	fi
fi

dnl AC_LBL_CHECK_TYPE(int32_t, int)
dnl AC_LBL_CHECK_TYPE(u_int32_t, u_int)

dnl
dnl Use PYTHON from the environment if present
dnl
python=${PYTHON:-python}
AC_PATH_PROG(PYTHON, ${python}, "")
if test -z "$PYTHON" ; then
	PYTHON="/usr/bin/env python"
fi

AC_LBL_DEVEL(V_CCOPT)

AC_MSG_CHECKING(if ether_header uses ether_addr structs)
AC_CACHE_VAL(ac_cv_ether_header_has_ea,
    LBL_SAVE_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS $V_INCLS"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#	include <sys/types.h>
#	if __STDC__
	/* osf3 has REALLY good prototyes */
	struct mbuf;
	struct rtentry;
#	endif
#	include <sys/socket.h>
#	include <net/if.h>
#	include <netinet/in.h>
#	include <netinet/if_ether.h>],
	[u_int i =
	    sizeof(((struct ether_header *)0)->ether_dhost.ether_addr_octet)])],
	ac_cv_ether_header_has_ea=yes,
	ac_cv_ether_header_has_ea=no))
    CFLAGS="$LBL_SAVE_CFLAGS"
AC_MSG_RESULT($ac_cv_ether_header_has_ea)
if test $ac_cv_ether_header_has_ea = yes ; then
	AC_DEFINE(ETHER_HEADER_HAS_EA)
fi

AC_MSG_CHECKING(if ether_arp uses ether_addr structs)
AC_CACHE_VAL(ac_cv_ether_arp_has_ea,
    LBL_SAVE_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS $V_INCLS"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#	include <sys/types.h>
#	if __STDC__
	/* osf3 has REALLY good prototyes */
	struct mbuf;
	struct rtentry;
#	endif
#	include <sys/socket.h>
#	include <net/if.h>
#	include <netinet/in.h>
#	include <netinet/if_ether.h>],
	[u_int i =
	    sizeof(((struct ether_arp *)0)->arp_sha.ether_addr_octet)])],
	ac_cv_ether_arp_has_ea=yes,
	ac_cv_ether_arp_has_ea=no))
    CFLAGS="$LBL_SAVE_CFLAGS"
AC_MSG_RESULT($ac_cv_ether_arp_has_ea)
if test $ac_cv_ether_arp_has_ea = yes ; then
	AC_DEFINE(ETHER_ARP_HAS_EA)
fi

AC_MSG_CHECKING(if ether_arp uses erp_xsha member)
AC_CACHE_VAL(ac_cv_struct_ether_arp_x,
    LBL_SAVE_CFLAGS="$CFLAGS"
    CFLAGS="$CFLAGS $V_INCLS"
    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([
#	include <sys/types.h>
#	include <sys/socket.h>
#	if __STDC__
	/* osf3 has REALLY good prototyes */
	struct mbuf;
	struct rtentry;
#	endif
#	include <net/if.h>
#	include <netinet/in.h>
#	include <netinet/if_ether.h>],
	[u_int i = sizeof(((struct ether_arp *)0)->arp_xsha)])],
	ac_cv_struct_ether_arp_x=yes,
	ac_cv_struct_ether_arp_x=no))
    CFLAGS="$LBL_SAVE_CFLAGS"
AC_MSG_RESULT($ac_cv_struct_ether_arp_x)
if test $ac_cv_struct_ether_arp_x = yes ; then
	AC_DEFINE(ETHER_ARP_HAS_X)
fi

dnl
dnl bind 8 does some routine name renaming so we must test specially
dnl
AC_MSG_CHECKING(for dn_skipname)
AC_CACHE_VAL(ac_cv_have_dn_skipname,
    AC_LINK_IFELSE([AC_LANG_PROGRAM([
#	include <sys/types.h>
#	include <netinet/in.h>
#	include <arpa/nameser.h>
#	include <resolv.h>],
	[(void)dn_skipname(0, 0);])],
	ac_cv_have_dn_skipname=yes,
	ac_cv_have_dn_skipname=no))
AC_MSG_RESULT($ac_cv_have_dn_skipname)
if test $ac_cv_have_dn_skipname = yes ; then
	AC_DEFINE(HAVE_DN_SKIPNAME)
fi

dnl
dnl configurable watcher and watchee email addresses
dnl
AC_MSG_CHECKING(for watcher)
AC_ARG_WITH(watcher,
    AS_HELP_STRING([--with-watcher=email],
    [email address to send reports to]))
if test -z "${with_watcher}"; then
	with_watcher="root"
fi
AC_DEFINE_UNQUOTED([WATCHER], ["${with_watcher}"])
AC_MSG_RESULT(${with_watcher})

AC_MSG_CHECKING(for watchee)
AC_ARG_WITH(watchee,
    AS_HELP_STRING([--with-watchee=email],
    [email address reports come from]))

if test -z "${with_watchee}"; then
	with_watchee="arpwatch"
fi
AC_DEFINE_UNQUOTED([WATCHEE], ["${with_watchee}"])
AC_MSG_RESULT(${with_watchee})

if test "${ac_cv_enable_debug}" = yes ; then
	AC_DEFINE(DEBUG)
fi

if test -r lbl/gnuc.h ; then
	rm -f gnuc.h
	ln -s lbl/gnuc.h gnuc.h
fi

AC_SUBST([HAVE_FREEBSD_FALSE])
AC_SUBST([HAVE_FREEBSD_TRUE])
AC_SUBST([LBL_LIBS])
AC_SUBST([LDFLAGS])
AC_SUBST([MACZERO])
AC_SUBST([MANCFLAG])
AC_SUBST([MANZFLAG])
AC_SUBST([V_CCOPT])
AC_SUBST([V_INCLS])
AC_SUBST([V_PCAPDEP])
AC_SUBST([V_SENDMAIL])
AC_SUBST([WATCHEE])
AC_SUBST([WATCHER])
AC_SUBST([ZEROPAD])

scripts="
    arpwatch.sh
    massagevendor.py
    update-ethercodes.sh
    "
files="
    arpsnmp.8
    arpwatch.8
    "

AC_CONFIG_COMMANDS([executable], [chmod -w ${files} ; chmod +x ${scripts}],
    [files="${files}" ; scripts="${scripts}"])
AC_CONFIG_FILES([Makefile ${files} ${scripts}])
AC_OUTPUT

if test ! -f arp.dat ; then
	echo 'creating empty arp.dat file'
	touch arp.dat
fi

if test "${ac_cv_enable_debug}" = yes ; then
	make depend
fi
exit 0
