dnl Process this file with autoconf to produce a configure script.
AC_INIT(mudconf.h)
AC_CONFIG_HEADER(autoconf.h)
AC_PROG_CC
AC_PROG_CPP
AC_ISC_POSIX
AC_MINIX
AC_AIX
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_FUNCS(strchr memcpy)
AC_CHECK_HEADERS(unistd.h memory.h string.h errno.h malloc.h sys/select.h)
AC_CHECK_HEADERS(fcntl.h limits.h sys/file.h sys/ioctl.h sys/time.h sys/stat.h)
AC_CHECKING(for sys_errlist decl)
if test $ac_cv_header_errno_h = no; then
	AC_DEFINE(NEED_SYS_ERRLIST_DCL)
else
	AC_EGREP_HEADER(sys_errlist,errno.h, ,AC_DEFINE(NEED_SYS_ERRLIST_DCL))
fi
AC_FUNC_STRFTIME
AC_FUNC_VFORK
AC_FUNC_VPRINTF
AC_CHECK_FUNCS(setrlimit getrusage timelocal mktime srandom)
AC_CHECK_FUNCS(getpagesize getdtablesize socket gethostbyaddr)
AC_CHECK_FUNCS(gettimeofday select socket wait3)
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIGNAL
AC_TRY_COMPILE([#include <sys/signal.h>],[struct sigcontext scp;],AC_DEFINE(HAVE_STRUCT_SIGCONTEXT))dnl
AC_HEADER_SYS_WAIT
AC_STRUCT_TM
AC_STRUCT_TIMEZONE
AC_TRY_COMPILE([#include <sys/wait.h>],[union wait stat;],AC_DEFINE(HAVE_UNION_WAIT))
AC_CHECKING(for extended string dcls)
AC_EGREP_HEADER(rindex,string.h, ,AC_DEFINE(NEED_INDEX_DCL))
AC_CHECKING(for malloc dcl)
AC_EGREP_HEADER(realloc,stdlib.h, ,AC_DEFINE(NEED_MALLOC_DCL))
AC_CHECKING(for vsprintf dcl)
AC_EGREP_HEADER(vsprintf,stdio.h, ,AC_DEFINE(NEED_VSPRINTF_DCL))
AC_CHECKING(for sprintf dcl)
AC_EGREP_HEADER(\<sprintf|\<*sprintf,stdio.h, ,AC_DEFINE(NEED_SPRINTF_DCL))
AC_CHECKING(for extended stdio dcls)
AC_EGREP_HEADER(fread,stdio.h,AC_DEFINE(EXTENDED_STDIO_DCLS))
AC_CHECKING(for extended socket dcls)
AC_EGREP_HEADER(setsockopt,sys/socket.h,AC_DEFINE(EXTENDED_SOCKET_DCLS))

AC_CHECKING(for gettimeofday dcl)
if test $ac_cv_header_time = yes && test $ac_cv_header_sys_time_h = yes ; then
AC_EGREP_HEADER(gettimeofday,[time.h>
#include <sys/time.h], ,AC_DEFINE(NEED_GETTIMEOFDAY_DCL))
elif test $ac_cv_header_sys_time_h = yes ; then
AC_EGREP_HEADER(gettimeofday,sys/time.h, ,AC_DEFINE(NEED_GETTIMEOFDAY_DCL))
else
AC_EGREP_HEADER(gettimeofday,time.h, ,AC_DEFINE(NEED_GETTIMEOFDAY_DCL))
fi

if test $ac_cv_header_sys_wait_h = yes ; then
AC_CHECKING(for wait3 dcl)
AC_EGREP_HEADER(wait3,sys/wait.h, ,AC_DEFINE(NEED_WAIT3_DCL))
fi

AC_CHECKING(for srandom dcl)
AC_EGREP_HEADER(srandom,math.h, ,AC_DEFINE(NEED_SRANDOM_DCL))

AC_CHECKING(for signal SIGCHLD braindamage)
AC_TRY_RUN([
#include <sys/signal.h>

#ifndef SIGCHLD
#define SIGCHLD SIGCLD
#endif

int rlev;

sighand(sig,code)
int sig, code;
{
int stat;

  if (rlev++ > 2)
    exit(1);
  signal(SIGCHLD, sighand);
  wait(&stat);
  return;
}

main(argc, argv)
int argc;
char **argv;
{

  rlev = 0;
  signal(SIGCHLD, sighand);
  if (fork()) {
    sleep(10);
  } else {
    sleep(2);
    exit(1);
  }
  exit(0);
}
], ,AC_DEFINE(SIGNAL_SIGCHLD_BRAINDAMAGE),AC_DEFINE(SIGNAL_SIGCHLD_BRAINDAMAGE))

AC_DECL_SYS_SIGLIST

AC_CHECKING(for perror dcl)
AC_EGREP_HEADER(perror,errno.h, ,AC_DEFINE(NEED_PERROR_DCL))
AC_CHECKING(for getrusage dcl)
AC_EGREP_HEADER(getrusage,sys/resource.h, ,AC_DEFINE(NEED_GETRUSAGE_DCL))
AC_CHECKING(for getrlimit dcl)
AC_EGREP_HEADER(getrlimit,sys/resource.h, ,AC_DEFINE(NEED_GETRLIMIT_DCL))
AC_C_CONST
AC_C_CHAR_UNSIGNED
AC_C_INLINE
AC_TRY_COMPILE([#include <sys/types.h>
#include <sys/socket.h>],
[struct linger ling; ling.l_onoff = 1;],
AC_DEFINE(HAVE_LINGER))dnl
dnl
dnl   Check for the presence of ndbm or dbm routines as follows
dnl   ndbm routines in libc
dnl   existence of libndbm
dnl   ndbm routines in libdbm
dnl   existence of libsdbm
dnl   dbm routines in libc
dnl   dbm routines in libdbm
dnl
AC_CHECKING(for ndbm routines in libc)
AC_CHECK_FUNC(dbm_close,AC_DEFINE(HAVE_NDBM))
if test $ac_cv_func_dbm_close = no; then
	for lib in ndbm dbm sdbm; do
		AC_CHECK_LIB($lib, dbm_close,
		[AC_DEFINE(HAVE_NDBM)
		ac_cv_func_dbm_close=yes;
		LIBS="$LIBS -l$lib"; break])
	done
fi
if test $ac_cv_func_dbm_close = no; then
	AC_CHECKING(for dbm routines in libc)
	AC_CHECK_FUNC(dbmclose,AC_DEFINE(HAVE_DBM))
 	if test $ac_cv_func_dbmclose = no; then
		AC_CHECK_LIB(dbm, dbmclose,
			AC_DEFINE(HAVE_DBM)
			LIBS="$LIBS -ldbm")
	fi
fi
if test $ac_cv_func_dbm_close = no && test $ac_cv_func_dbmclose = no ; then
	LIBOBJS="$LIBOBJS myndbm.o"
fi

AC_CHECK_LIB(resolv, main)
AC_CHECK_LIB(sun, getpwnam)
AC_CHECK_LIB(seq, main)
AC_CHECK_LIB(intl, main)
AC_CHECK_LIB(nsl, main)
if test $ac_cv_func_gethostbyaddr = no; then
	AC_CHECK_LIB(inet, main)
fi
if test $ac_cv_func_socket = no; then
	AC_CHECK_LIB(socket, main)
fi
AC_CHECK_LIB(m, main)
AC_SUBST(LIBOBJS)
AC_OUTPUT(Makefile)
