dnl Process this file with autoconf to produce a configure script.
AC_INIT(aclocal.m4)
AC_PREFIX_DEFAULT(/usr/X11R6/bin)
dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AC_PROG_INSTALL

AC_PATH_X

if test "$x_libraries" = "NONE" || test "$x_includes" = "NONE"; then
AC_MSG_ERROR([Couldn't find X. Please rerun configure and supply
the full path to X includes and libraries using --x-includes and
--x-libraries]);
fi	
if test "$x_libraries" != ""; then
LDFLAGS="$LDFLAGS -L$x_libraries"
fi
if test "$x_includes" != ""; then
CPPFLAGS="$CPPFLAGS -I$x_includes"
fi
CPPFLAGS+=" -g "
AC_CHECK_LIB(X11, XSelectInput,
, AC_MSG_ERROR([*** Could not find libX11 ***]))
LDFLAGS="$LDFLAGS -lX11"

AC_CHECK_LIB(Xext, XShapeCombineMask,
, AC_MSG_ERROR([*** Could not find libXext ***]))
LDFLAGS="$LDFLAGS -lXext"

AC_PATH_LIBXPM
if test "$xpm_libraries" != "$x_libraries"; then
	LDFLAGS="$LDFLAGS -L$xpm_libraries"
fi

AC_CHECK_LIB(Xpm, XpmCreatePixmapFromData,
, AC_MSG_ERROR([*** Could not find libXpm ***]))
LDFLAGS="$LDFLAGS -lXpm"

if test "$xpm_includes" != "$x_include"; then
  CPPFLAGS="$CPPFLAGS -I$xpm_includes"
fi

dnl Checks for header files.

AC_HEADER_STDC
AC_CHECK_HEADERS(fcntl.h malloc.h sys/file.h sys/time.h unistd.h sys/types.h ctype.h X11/Xlib.h X11/xpm.h,,
AC_MSG_ERROR([Couldn't find some include files... aborting]))
AC_CHECK_HEADERS(netinet/in_systm.h netinet/in.h netinet/ip.h netinet/ip_icmp.h arpa/inet.h netdb.h sys/socket.h,,
AC_MSG_ERROR([Couldn't find network include files])) 
AC_CHECK_HEADERS(limits.h)

AC_CHECK_LIB(socket, socket, LDFLAGS="$LDFLAGS -lsocket")
AC_CHECK_LIB(nsl, inet_ntoa, LDFLAGS="$LDFLAGS -lnsl")

ac_inet_aton_in_resolv=no
AC_CHECK_LIB(resolv, inet_aton, LDFLAGS="$LDFLAGS -lresolv"
ac_inet_aton_in_resolv=yes
AC_DEFINE(HAVE_INET_ATON)
)

if test $ac_inet_aton_in_resolv = no; then
ac_inet_aton=no
AC_MSG_CHECKING(for inet_aton)
AC_TRY_COMPILE([
#include <sys/types.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>],
[ struct sockaddr_in *sock;
inet_aton("10.10.10.10",sock);
], 
ac_inet_aton=yes
AC_DEFINE(HAVE_INET_ATON)
)
AC_MSG_RESULT($ac_inet_aton)

fi

ac_inet_aton_in_libresolv=no

AC_HAVE_STRUCT_ICMP

if test "$ac_have_icmp" = "no"; then
  AC_HAVE_STRUCT_ICMPHDR
  if test "$ac_have_icmphdr" = "no"; then
   AC_MSG_ERROR([Couldn't find icmp header structures. You probably have a broken libc installation])
  fi
else
 AC_DEFINE(HAVE_STRUCT_ICMP)
fi

AC_HAVE_STRUCT_UDPBSD
if test "$ac_have_udpbsd" = "no"; then
  AC_HAVE_STRUCT_UDP
  if test "$ac_have_udp" = "no"; then
   AC_MSG_ERROR([Couldn't find udp header structures. You probably have a broken libc installation])
  fi
else
 AC_DEFINE(HAVE_STRUCT_UDPBSD)
fi

has_struct_ip=no

AC_MSG_CHECKING(if we have BSD-style struct ip)
  AC_TRY_COMPILE([
#include <sys/types.h>
#include <netinet/in_systm.h>
#include <netinet/in.h>
#include <netinet/ip.h>
  ] , [struct ip iph; iph.ip_hl=0;]
  , has_struct_ip=yes)
  AC_MSG_RESULT($has_struct_ip)

if test $has_struct_ip = no ; then
AC_MSG_ERROR([Couldn't find struct ip. You probably have a broken libc installation])
fi

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

dnl Checks for library functions.
AC_TYPE_SIGNAL
AC_CHECK_FUNCS(select socket strcspn strdup strspn strstr strtoul)

AC_SUBST(x_libraries)
AC_CONFIG_HEADER(config.h)
AC_OUTPUT(Makefile)
