dnl     $Id$
dnl
dnl     Firewalk autoconfiguration information file
dnl     Copyright (c) 1998, 1999 Mike D. Schiffman <mike@infonexus.com>
dnl     All rights reserved.
dnl                               
dnl     Process this file with autoconf to produce a configure script.
dnl

AC_INIT(firewalk.h)

dnl
dnl Determine hosttype.
dnl
AC_CANONICAL_SYSTEM

dnl
dnl Use these compiler flags unless overridden at the command line.
dnl
if test -z "${CFLAGS}"; then
	if test -z "${CCOPTS}"; then
        	CCOPTS='-O3 -funroll-loops -fomit-frame-pointer -pipe'
    	fi
  	CFLAGS="$CCOPTS"
fi

dnl
dnl Check for package inclusion/exclusion
dnl
AC_ARG_WITH(gtk, [ --with-gtk=[yes,no] override defaults], \
    with_gtk=no, with_gtk=yes)

dnl
dnl Checks for programs.
dnl
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL

dnl
dnl Checks for libraries.
dnl
AC_SUBST(FW_GTK_OBJS)
AC_SUBST(FW_GTK_CONFIG)
AC_CHECK_LIB(net, libnet_build_ip, , AC_MSG_ERROR(No libnet?  No firewalk.))
AC_CHECK_LIB(pcap, pcap_open_live, , AC_MSG_ERROR(No libpcap?  No firewalk.))

if test $with_gtk = yes; then
    AM_PATH_GTK(1.0.0, CFLAGS="$CFLAGS $GTK_CFLAGS" LIBS="$LIBS $GTK_LIBS" \
        AC_DEFINE(HAVE_GTK) FW_GTK_OBJS="gtk_main.o gtk_util.o gtk_cb.o gtk_cp.o" \
        FW_GTK_CONFIG="\`gtk-config --cflags --libs\`", \
        AC_MSG_RESULT(GTK distribution not found.  GTK interface will not be installed.))
fi

dnl
dnl Checks for header files.
dnl
AC_HEADER_STDC
dnl AC_CHECK_HEADERS(sys/file.h sys/ioctl.h sys/time.h syslog.h unistd.h libnet.h net/bpf.h)

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

dnl
dnl Checks for library functions.
dnl
AC_PROG_GCC_TRADITIONAL
AC_CHECK_FUNCS(strerror)

dnl
dnl Sets OS specific CPP directives.
dnl
case "$target_os" in

*linux*)
    AC_DEFINE(_BSD_SOURCE)
    AC_DEFINE(__BSD_SOURCE)
    AC_DEFINE(__FAVOR_BSD)
    ;;

*freebsd*)
    AC_DEFINE(BSDISH_OS)
    AC_DEFINE(HAVE_SOCKADDR_SA_LEN)
    ;;

*openbsd*)
    AC_DEFINE(BSDISH_OS)
    ;;

*solaris*)
    AC_DEFINE(HAVE_SOLARIS)
    AC_CHECK_LIB(socket, socket, , AC_MSG_ERROR(libsocket not found.))
    AC_CHECK_LIB(nsl, gethostbyname, , AC_MSG_ERROR(libnsl not found.))
    AC_SUBST(ADDITIONAL_LIBS)
    ADDITIONAL_LIBS='-lsocket -lnsl'
    AC_MSG_WARN(Unless you've done something special, firewalk will not work under Solaris until we write packets at the link layer rather than the IP layer.  Sorry.)
    ;;

*)
    AC_MSG_WARN(your OS is not officially supported yet)
    AC_MSG_WARN(dunno if this will work)
    ;;
  
esac

AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile)
