# configure.in borrowed from nmap-2.3BETA6 by fyodor@dhp.com

AC_SUBST(VERSION)
VERSION=`pwd | sed 's/.*-//'`

if test -d /usr/local/lib; then
  LDFLAGS="$LDFLAGS -L/usr/local/lib"
fi
if test -d /usr/local/include; then
  CFLAGS="$CLFAGS -I/usr/local/include"
fi

dnl Process this file with autoconf to produce a configure script.
AC_INIT(tcpblast.c)

dnl use config.h instad of -D macros
AC_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_CC
 if test -n "$GCC"; then
      CFLAGS="$CFLAGS -Wall "
 fi

AC_SUBST(COMPAT_OBJS)
AC_SUBST(COMPAT_SRCS)

dnl Host specific hacks
AC_CANONICAL_HOST

linux=no

case "$host" in
  *-netbsd*)
    AC_DEFINE(NETBSD)
    ;;
  *-openbsd*)
    AC_DEFINE(OPENBSD)
    ;;
  *-sgi-irix5*)
    AC_DEFINE(IRIX)
    no_libsocket=yes
    no_libnsl=yes
    if test -z "$GCC"; then
      sgi_cc=yes
    fi
    ;;
  *-sgi-irix6*)
    AC_DEFINE(IRIX)
    no_libsocket=yes
    no_libnsl=yes
    if test -z "$GCC"; then
      sgi_cc=yes
    fi
    ;;
  *-solaris2.0*)  
    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
    AC_DEFINE(SOLARIS)
    ;;
  *-solaris2.1*)
    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
    AC_DEFINE(SOLARIS)
    ;;
  *-solaris2.2*)
    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
    AC_DEFINE(SOLARIS)
    ;;
  *-solaris2.3*)
    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
    AC_DEFINE(SOLARIS)
    ;;
  *-solaris2.4*)
    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
    AC_DEFINE(SOLARIS)
    ;;
  *-solaris2.5.1)
    AC_DEFINE(STUPID_SOLARIS_CHECKSUM_BUG)
    AC_DEFINE(SOLARIS)
    ;;
  *-solaris*)
    AC_DEFINE(SOLARIS)
    ;;
  *-sunos4*)
    AC_DEFINE(SUNOS)
    AC_DEFINE(SPRINTF_RETURNS_STRING)
    no_libnsl=yes
    no_libsocket=yes
    ;;
  *-linux*)
    linux=yes
    AC_DEFINE(LINUX)
    AC_DEFINE(PCAP_TIMEOUT_IGNORED)  # libpcap doesn't even LOOK at
                                     # the timeout you give it under Linux
    ;;
  *-freebsd*)
    AC_DEFINE(FREEBSD)
    ;;
  *-bsdi*)
    AC_DEFINE(BSDI)
    ;;
esac

dnl Checks for libraries.
dnl AC_CHECK_LIB(m, pow)
if test -z "$no_libnsl"; then
AC_CHECK_LIB(nsl, inet_ntoa)
fi
if test -z "$no_libsocket"; then
AC_CHECK_LIB(socket, socket)
fi

dnl Checks for header files.
AC_HEADER_STDC
AC_CHECK_HEADERS(string.h getopt.h strings.h memory.h sys/param.h sys/sockio.h sys/time.h )
AC_HEADER_TIME

dnl AC_CHECK_HEADERS(fcntl.h sys/time.h unistd.h)

dnl Checks for typedefs, structures, and compiler characteristics.

dnl socklen_t
AC_MSG_CHECKING(for socklen_t)
AC_TRY_COMPILE([
#include <sys/types.h>
#include <sys/socket.h>], [socklen_t len; len = 1;], 
 	[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SOCKLEN_T)], [AC_MSG_RESULT(no)])

dnl in6_addr
AC_MSG_CHECKING(for in6_addr)
AC_TRY_COMPILE([
#include <sys/types.h>
#include <netinet/in.h>], [struct in6_addr addr;], 
 	[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_IN6_ADDR)], [AC_MSG_RESULT(no)])

dnl AC_HEADER_TIME

AC_SUBST(CFLAGS)

AC_C_BIGENDIAN


dnl Checks for library functions.

AC_CHECK_FUNCS(bzero getaddrinfo inet_pton strerror)

AC_MSG_CHECKING(for timersub)
AC_TRY_COMPILE([#include <sys/time.h>], [#ifndef timersub
	error
#endif],
	[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_TIMERSUB)], [AC_MSG_RESULT(no)])

AC_CHECK_FUNC(getopt_long, , 
  [ COMPAT_SRCS="$COMPAT_SRCS getopt.c getopt1.c"
    COMPAT_OBJS="$COMPAT_OBJS getopt.o getopt1.o" ])

AC_REPLACE_FUNCS(strsep daemon)

AC_OUTPUT(Makefile docs/tcpblast.spec)
