dnl Process this file with autoconf to produce a configure script.
AC_INIT(lft_ifname.h)
AC_CONFIG_HEADER(acconfig.h)

AC_CYGWIN

AC_DEFINE_UNQUOTED(HOST_SYSTEM_TYPE, "$host")

dnl Checks for programs.
AC_PROG_CC
AC_PROG_LN_S
AC_PROG_MAKE_SET
AC_PROG_INSTALL

AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, connect)
AC_CHECK_LIB(resolv, inet_aton)
AC_CHECK_LIB(m, sin)

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h limits.h strings.h sys/ioctl.h sys/time.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME

dnl Checks for library functions.
AC_FUNC_ALLOCA
AC_CHECK_FUNCS(gettimeofday select socket strdup strstr)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, connect)

dnl OS specific checks
case "$host" in
*darwin*)
  AC_DEFINE(BSD_IP_STACK)
;;
*bsd*)
  AC_DEFINE(BSD_IP_STACK)
;;
*linux*)
  AC_DEFINE(_BSD_SOURCE)
;;
*solaris*)
  dnl some versions of solaris need special treatment
  dnl for the th_sum field, and it varies
  dnl between versions...
  case "$host" in
  *solaris2.4*)
    AC_DEFINE(SOLARIS_LENGTH_IN_CHECKSUM)
    ;;
  *solaris2.5*)
    AC_DEFINE(SOLARIS_LENGTH_IN_CHECKSUM)
    ;;
  esac
;;
esac


case "$host" in
*cygwin*)
: we do not require pcap, but we do require special win32 libraries.
LIBS="-lws2_32 $LIBS"
;;
*)
dnl Make sure we have pcap
AC_ARG_WITH(pcap,
[  --with-pcap=PATH        Specify path to pcap library.],
    [
        AC_MSG_CHECKING(for --with-pcap option)
        case "$withval" in
          yes|no)
            AC_MSG_ERROR(PATH required with pcap option)
            ;;
          *)
            if test '!' -d "$withval"; then
                AC_MSG_ERROR($withval does not exist!)
            else
                AC_MSG_RESULT($withval)
                if test -d "$withval/include"; then
                  CFLAGS="$CFLAGS -I$withval/include"
                  CPPFLAGS="$CPPFLAGS -I$withval/include"
                else
                  CFLAGS="$CFLAGS -I$withval"
                  CPPFLAGS="$CPPFLAGS -I$withval"
                fi
                if test -d "$withval/lib"; then
                  LIBS="$LIBS -L$withval/lib"
                else
                  LIBS="$LIBS -L$withval"
                fi
            fi
            ;;
          esac
    ]
)


for incdir in /usr/local/include /usr/include
do
  if test -d $incdir/pcap
  then
    CFLAGS="$CFLAGS -I$incdir/pcap"
    CPPFLAGS="$CFLAGS -I$incdir/pcap"
  fi
done

AC_TRY_COMPILE([
#       include <sys/types.h>
#       include <sys/socket.h>],
        [u_int i = sizeof(((struct sockaddr *)0)->sa_len)],
        AC_DEFINE(HAVE_SOCKADDR_SA_LEN))


AC_CHECK_LIB(pcap, pcap_lookupdev, , [
        AC_MSG_ERROR([
Can't find the pcap library (libpcap.a); install the pcap library (from
ftp://ftp.ee.lbl.gov/libpcap.tar.Z ) and/or use
--with-pcap to specify the path to it on your system

When installing libpcap do both 'make install' and 'make install-incl'])
])

AC_CHECK_HEADER(pcap.h, , [
        AC_MSG_ERROR([
Can't find pcap.h; install the pcap library (from
ftp://ftp.ee.lbl.gov/libpcap.tar.Z ) and/or use
--with-pcap to specify the path to it on your system

When installing libpcap do both 'make install' and 'make install-incl'])
])

esac

AC_OUTPUT(Makefile)
