dnl
dnl configure.in for the Dancer project
dnl

AC_INIT(dancer.h)
AC_CONFIG_HEADER(config.h)

dnl Check compiler

CFLAGS=""
AC_PROG_CC
AC_C_INLINE

dnl Check libraries

AC_CHECK_LIB(m, exp)
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(ucb, gethostname)
AC_CHECK_LIB(crypt, crypt)
AC_CHECK_LIB(fpl, fplExecuteFile)

dnl Checks for header files.

AC_HEADER_STDC
AC_CHECK_HEADERS(limits.h sys/time.h unistd.h pwd.h)

dnl Checks for typedefs, structures, and compiler characteristics.

AC_C_CONST
AC_TYPE_SIZE_T
AC_HEADER_TIME
AC_STRUCT_TM
AC_CHECK_TYPE(ulong, unsigned long)

dnl Checks for library functions.

AC_FUNC_ALLOCA
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(gettimeofday mktime strftime)
AC_CHECK_FUNCS(strdup strstr strtol strtoul atol strsep strcasecmp memmove)
AC_CHECK_FUNCS(gethostname getdomainname select socket strerror getdtablesize)
AC_CHECK_FUNCS(yp_get_default_domain yp_master inet_ntoa)
AC_CHECK_FUNCS(re_comp regcomp _crypt)

dnl
dnl check if %n is available in sscanf()
dnl

AC_MSG_CHECKING(for %n in scanf)
AC_TRY_RUN([
#include <stdio.h>
main()
{
  int a, b, i = 0;
  char buf[] = "1 2";

  sscanf(buf, "%d %d %n", &a, &b, &i);
  exit (i-strlen(buf));
}
],AC_DEFINE(HAVE_N_IN_SCANF) AC_MSG_RESULT(yes), AC_MSG_RESULT(no), :)

dnl
dnl following two checks "borrowed" from ircd
dnl

dnl
dnl check for non-blocking fd style available..
dnl

AC_MSG_CHECKING(for non-blocking)
changequote(<<, >>)dnl
<<
precode='#include <sys/types.h>
#include <sys/socket.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/file.h>
#include <signal.h>
 
alarmed()
{
        exit(1);
}
 
main()
{
        char b[12], x[32];
        int f, l = sizeof(x);
        f = socket(AF_INET, SOCK_DGRAM, 0);
        if (f >= 0 && !(fcntl(f, F_SETFL,'
postcode='))) {
                signal(SIGALRM, alarmed);
                alarm(3);
                recvfrom(f, b, 12, 0, (struct sockaddr *)x, &l);
                alarm(0);
                exit(0);
        }
        exit(1);
}'
>>
changequote([, ])dnl

code="$precode O_NONBLOCK $postcode"
 
AC_TRY_RUN($code,
  AC_DEFINE(NBLOCK_POSIX)
  AC_MSG_RESULT(posix),
  code="$precode O_NDELAY $postcode"
  AC_TRY_RUN($code,
    AC_DEFINE(NBLOCK_BSD)
    AC_MSG_RESULT(bsd),
    code="$precode FIONBIO $postcode"
    AC_TRY_RUN($code,
      AC_DEFINE(NBLOCK_SYSV)
      AC_MSG_RESULT(system v),
      AC_MSG_WARN(i can't find a working non blocking system),
      :),
    :),
  :)
 

dnl
dnl check for sys_errlist declaration
dnl

AC_MSG_CHECKING(for sys_errlist declaration)
AC_TRY_RUN([
#include <sys/types.h>
#include <stdio.h>
#include <errno.h>
main()
{
  char *s = sys_errlist[0];
  exit(0);
}
],AC_DEFINE(SYS_ERRLIST_DECLARED) AC_MSG_RESULT(yes), AC_MSG_RESULT(no), :)

AC_OUTPUT(Makefile)
