dnl Process this file with autoconf to produce a configure script.

# Require autoconf 2.13
AC_PREREQ(2.13)

AC_INIT(nbase.h)

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

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

dnl Checks for programs.
AC_PROG_CC

 if test -n "$GCC"; then
      CFLAGS="$CFLAGS -Wall "
 fi
AC_PROG_RANLIB
dnl AC_PROG_INSTALL
dnl AC_PATH_PROG(MAKEDEPEND, makedepend)

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)
    if test -z "$GCC"; then
      sgi_cc=yes
    fi
    ;;
  *-sgi-irix6*)
    AC_DEFINE(IRIX)
    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)
    ;;
  *-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 header files.
AC_HEADER_STDC
AC_CHECK_HEADERS( string.h getopt.h strings.h memory.h sys/param.h sys/time.h unistd.h bstring.h netinet/if_ether.h netinet/in.h sys/time.h sys/socket.h sys/sockio.h rpc/types.h netdb.h pwd.h arpa/inet.h sys/resource.h sys/stat.h sys/wait.h  libiberty.h )
AC_HEADER_TIME

dnl equiv to '#define inline' to 'inline', '__inline__', '__inline' or ''
AC_C_INLINE
AC_C___ATTRIBUTE__
if test -n "$sgi_cc"; then
   AC_DEFINE(inline, )
fi

dnl AC_HEADER_TIME

AC_SUBST(CFLAGS)

dnl check endedness
AC_C_BIGENDIAN

dnl determine integer widths so nbase can export u32, u16, etc.
AC_CHECK_SIZEOF(char, 1)
AC_CHECK_SIZEOF(short, 2)
AC_CHECK_SIZEOF(int, 4)
AC_CHECK_SIZEOF(long, 4)

dnl Checks for library functions.
dnl AC_TYPE_SIGNAL
AC_CHECK_FUNCS( bzero snprintf vsnprintf memcpy nanosleep strerror strcasestr strcasecmp strncasecmp signal )

needsnprintf=no
AC_CHECK_FUNCS(vsnprintf snprintf asprintf asnprintf vasprintf vasnprintf,,
        [needsnprintf=yes])
if test $needsnprintf = yes; then
        LIBOBJS="$LIBOBJS snprintf.o"
fi

AC_CHECK_FUNCS(usleep gettimeofday sleep, ,
  [ LIBOBJS="$LIBOBJS nbase_time.o" ])

AC_REPLACE_FUNCS(inet_ntop inet_pton inet_aton)

AC_CHECK_FUNC(getopt_long_only, , 
  [ LIBOBJS="$LIBOBJS getopt.o getopt1.o" ])

AC_CHECK_FUNCS(strcasecmp strncasecmp, , 
  [ LIBOBJS="$LIBOBJS strcasecmp.o" ])

dnl We always want some of our files
LIBOBJS="$LIBOBJS nbase_str.o nbase_misc.o"

AC_OUTPUT(Makefile)
