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

AC_INIT(install-sh)
AC_PREREQ([2.50])
AC_CONFIG_HEADER(config.h)

AC_SUBST(TARGETS)
AC_SUBST(PLTARGETS)
AC_SUBST(NETLIBS)
AC_SUBST(CRYPTLIBS)
AC_SUBST(CRYPTOBJ)

m4_include([../ac_swi_c.m4])

TARGETS="socket.$SO cgi.$SO memfile.$SO files.$SO mime.$SO crypt.$SO time.$SO"

case "$PLARCH" in
    *-win32|*-win64)
        AC_CHECK_LIB(ws2_32, main,
                     [NETLIBS="$NETLIBS -lws2_32"])
        AC_CHECK_LIB(gdi32, main,
                     [NETLIBS="$NETLIBS -lgdi32"])
        ;;
    *)
        TARGETS="$TARGETS uid.$SO unix.$SO"
        ;;
esac

AC_CHECK_FUNC(socket, [], [
             AC_CHECK_LIB(socket, socket,
                      [NETLIBS="$NETLIBS -lsocket"; LIBS="$LIBS -lsocket"]
                      AC_DEFINE(HAVE_LIBSOCKET, 1,
                      "Define if you have the socket library (-lsocket)."))])
AC_CHECK_FUNC(gethostent, [], [
             AC_CHECK_LIB(nsl, gethostent,
                      [NETLIBS="$NETLIBS -lnsl"]
                      AC_DEFINE(HAVE_LIBNSL, 1,
                      "Define if you have the nsl library (-lnsl)."))])

oldlibs="$LIBS"
AC_CHECK_LIB(crypt, crypt)
CRYPTLIBS="$LIBS"
AC_CHECK_FUNC(crypt,
	      [],
	      [CRYPTOBJ=bsd-crypt.o])
AC_DEFINE(HAVE_CRYPT, 1,
	  "Define if you have the crypt function.")
LIBS="$oldlibs"

AC_MSG_CHECKING("Configuring MIME libraries")
case "$CC" in
	.*) ACC="../../$CC"
	    ;;
	*)  ACC="$CC"
esac
case "$LD" in
	.*) ALD="../../$LD"
	    ;;
	*)  ALD="$LD"
esac
case "$CPP" in
	.*) ACPP="../../$CPP"
	;;
	*) ACPP="$CPP"
esac
( CC=$ACC; LD=$ALD; CPP=$ACPP; CFLAGS=$CFLAGS; LDFLAGS=$LDFLAGS;
  export CC LD CFLAGS LDFLAGS

  (cd maildrop/rfc822 && $SHELL configure --host=$host)
  (cd maildrop/rfc2045 && $SHELL configure --host=$host)
)
AC_MSG_RESULT("Done")

AC_MSG_CHECKING(h_errno)
AC_TRY_COMPILE(
[
#include <sys/types.h>
#include <sys/socket.h>
#include <netdb.h>
#include <netinet/in.h>
],
[ int x = h_errno;
], AC_DEFINE(HAVE_H_ERRNO, 1,
	     [Define of h_errno is provided])
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))

AC_CHECK_HEADERS(malloc.h alloca.h unistd.h sys/time.h fcntl.h utime.h)
AC_CHECK_HEADERS(execinfo.h sys/resource.h crypt.h)
AC_CHECK_HEADERS(sys/types.h sys/wait.h sys/stat.h)
AC_CHECK_HEADERS(netinet/tcp.h crt_externs.h)

AC_CHECK_SIZEOF(long, 4)
AC_CHECK_SIZEOF(long long, 8)

AC_CHECK_FUNCS(setsid strerror utime getrlimit strcasestr vfork _NSGetEnviron)
AC_CHECK_TYPES(socklen_t, [], [],
[
#include <sys/types.h>
#include <sys/socket.h>
])
AC_CHECK_TYPES(ssize_t, [], [],
[
#include <sys/types.h>
#include <sys/socket.h>
])

AC_MSG_CHECKING(_XOPEN_SOURCE)
AC_TRY_COMPILE(
[
#define _XOPEN_SOURCE
#include <unistd.h>
],
[
], AC_DEFINE(DEFINE_XOPEN_SOURCE, 1,
	     "Define if _XOPEN_SOURCE is needed")
   AC_MSG_RESULT(yes),
   AC_MSG_RESULT(no))

with_time=yes
AC_ARG_WITH(time, [  --without-time		  Exclude alarm library],
	    [case "$withval" in
		yes)	with_time=yes ;;
		no)     with_time=no ;;
	     esac])

if test "$ac_cv_func_getrlimit" = "yes"; then
  TARGETS="$TARGETS rlimit.$SO"
else
  "WARNING: no getrlimit(); dropping rlimit.pl from targets"
fi

PLTARGETS=`echo $TARGETS | sed -e "s/\.$SO/.pl/g" -e "s/files.pl/filesex.pl/"`
if echo "$PLTARGETS" | grep socket.pl 2>&1 >/dev/null; then
  PLTARGETS="$PLTARGETS streampool.pl"
fi

AC_OUTPUT(Makefile)



