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

sinclude(ac_prog_cc_no_writeable_strings.m4)

AC_INIT(secnet,0.1.16+,secnet@chiark.greenend.org.uk)
AC_CONFIG_SRCDIR(secnet.c)
AC_CONFIG_HEADER(config.h)

AC_PREREQ(2.50)
AC_REVISION($Id: configure.in,v 1.4 2002/09/09 22:05:02 steve Exp $)

AC_LANG_C

AC_PROG_MAKE_SET
AC_PROG_CC
AC_PROG_INSTALL
AC_PATH_PROG(RM,rm)
AC_STDC_HEADERS
AC_CHECK_HEADERS([stdint.h inttypes.h])
AC_CHECK_HEADERS([net/if.h net/route.h])
AC_CHECK_HEADERS([sys/socket.h])
AC_CHECK_HEADERS([linux/if.h], [], [], 
[#if HAVE_SYS_SOCKET_H
# include <sys/socket.h>
#endif
])
AC_CHECK_HEADERS([stropts.h sys/sockio.h net/if_tun.h])
AC_C_BIGENDIAN
AC_CHECK_SIZEOF(unsigned long long)
AC_CHECK_SIZEOF(unsigned long)
AC_CHECK_SIZEOF(unsigned int)
AC_CHECK_SIZEOF(unsigned short)
AC_CHECK_SIZEOF(unsigned char)
AC_PROG_CC_NO_WRITEABLE_STRINGS(WRITESTRINGS)

AC_DEFUN([REQUIRE_HEADER],[AC_CHECK_HEADER($1,,[AC_MSG_ERROR($1 not found)])])

dnl the order in which libraries is checked is important
dnl eg. adns on Solaris 2.5.1 depends on -lnsl and -lsocket
AC_CHECK_LIB(gmp,mpz_init_set_str)
AC_CHECK_LIB(gmp2,mpz_init_set_str)
AC_CHECK_LIB(gmp,__gmpz_init_set_str)
REQUIRE_HEADER([gmp.h])
dnl Would love to barf if no gmp was found, but how to test? Requiring the header will do for now.
AC_CHECK_LIB(fl,yywrap)
if test "$ac_cv_lib_fl_yywrap" != yes; then
  AC_MSG_ERROR([A compatible libfl is required])
fi
AC_CHECK_LIB(nsl,inet_ntoa)
AC_CHECK_LIB(getopt,getopt_long)
AC_CHECK_LIB(gnugetopt,getopt_long)
AC_CHECK_LIB(socket,socket)
AC_CHECK_LIB(resolv,inet_aton)
AC_CHECK_LIB(adns,adns_init)
REQUIRE_HEADER([adns.h])

dnl check for getopt in standard library
AC_REPLACE_FUNCS([snprintf])
AC_CHECK_FUNC([getopt_long], [], [AC_LIBOBJ([getopt])
 AC_LIBOBJ([getopt1])])

AC_OUTPUT(Makefile,echo timestamp >stamp-h)

AH_TOP([
#ifndef _CONFIG_H
#define _CONFIG_H
])

AH_BOTTOM([
/* -*- c -*- */

/* These used to be in config.h.bot, but are now in configure.in. */

#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#else
#ifdef HAVE_STDINT_H
#include <stdint.h>
#else
#if SIZEOF_UNSIGNED_LONG_LONG==8
typedef unsigned long long uint64_t;
typedef long long int64_t;
#elif SIZEOF_UNSIGNED_LONG==8
typedef unsigned long uint64_t;
typedef long int64_t;
#else
#error I do not know what to use for a uint64_t.
#endif

/* Give us an unsigned 32-bit data type. */
#if SIZEOF_UNSIGNED_LONG==4
typedef unsigned long uint32_t;
typedef long int32_t;
#elif SIZEOF_UNSIGNED_INT==4
typedef unsigned int uint32_t;
typedef int int32_t;
#else
#error I do not know what to use for a uint32_t.
#endif

/* An unsigned 16-bit data type. */
#if SIZEOF_UNSIGNED_INT==2
typedef unsigned int uint16_t;
typedef int int16_t;
#elif SIZEOF_UNSIGNED_SHORT==2
typedef unsigned short uint16_t;
typedef short int16_t;
#else
#error I do not know what to use for a uint16_t.
#endif

/* An unsigned 8-bit data type */
#if SIZEOF_UNSIGNED_CHAR==1
typedef unsigned char uint8_t;
#else
#error I do not know what to use for a uint8_t.
#endif
#endif
#endif

#ifndef HAVE_SNPRINTF
#include <stdio.h>
#include <stdarg.h>
#include "snprintf.h"
#endif

#ifdef __GNUC__
#define NORETURN(_x) void _x __attribute__ ((noreturn))
#define FORMAT(_a,_b,_c) __attribute__ ((format (_a,_b,_c)))
#else
#define NORETURN(_x) _x
#define FORMAT(_a,_b,_c)
#endif

#endif /* _CONFIG_H */
])
