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

AC_INIT(stunnel.c)
AC_CONFIG_HEADER(config.h)

AC_CANONICAL_HOST
AC_PROG_CC
if test "$GCC" = "yes"; then CFLAGS="$CFLAGS -Wall"; fi
AC_PROG_INSTALL
AC_PROG_MAKE_SET

VERSION="3.6"
AC_SUBST(VERSION)
AC_DEFINE_UNQUOTED(VERSION, "$VERSION")

AC_MSG_CHECKING([for SSL config directory])
for dir in /usr/local/openssl /usr/lib/openssl /var/openssl; do
    sslcnf="$dir"
    if test -d "$dir/certs"; then
        break
    fi
done
AC_MSG_RESULT($sslcnf)
AC_SUBST(sslcnf)
AC_DEFINE_UNQUOTED(sslcnf, "$sslcnf")

AC_SUBST(host)
AC_DEFINE_UNQUOTED(HOST, "$host")

dnl Checks for standard libraries.
AC_CHECK_LIB(nsl, gethostbyname)
AC_CHECK_LIB(socket, socket)
AC_CHECK_LIB(pthread, pthread_create)
AC_CHECK_LIB(util, openpty)

dnl Check for libwrap library.
AC_MSG_CHECKING([for hosts_access in -lwrap])
saved_LIBS="$LIBS"
LIBS="-lwrap $saved_LIBS"
AC_TRY_LINK([int hosts_access(); int allow_severity, deny_severity;],
[hosts_access()],
[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LIBWRAP)],
[AC_MSG_RESULT(no)]; LIBS="$saved_LIBS")

dnl Check for SSL directories.
AC_MSG_CHECKING([for SSL directory])
for dir in ${prefix} /usr/local/ssl /usr/lib/ssl /usr/ssl /usr/pkg /usr/local /usr; do
    ssldir="$dir"
    if test -f "$dir/include/openssl/ssl.h"; then
        AC_DEFINE(HAVE_OPENSSL)
        break
    fi
    if test -f "$dir/include/ssl.h"; then
        break
    fi
done
AC_MSG_RESULT($ssldir)
AC_SUBST(ssldir)
AC_DEFINE_UNQUOTED(ssldir, "$ssldir")
CFLAGS="$CFLAGS -I$ssldir/include"
LIBS="$LIBS -L$ssldir/lib -lssl -lcrypto"

dnl Check for RSAref library.
AC_MSG_CHECKING([for RSAref library])
saved_LIBS="$LIBS"
LIBS="$saved_LIBS -lRSAglue -lrsaref"
AC_TRY_LINK([], [],
[AC_MSG_RESULT(yes); ],
[AC_MSG_RESULT(no)]; LIBS="$saved_LIBS")

dnl Checks for header files.
# AC_HEADER_DIRENT
# AC_HEADER_STDC
# AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(getopt.h unistd.h sys/select.h tcpd.h pthread.h pty.h)

# dnl Checks for typedefs, structures, and compiler characteristics.
# AC_C_CONST
# AC_TYPE_SIGNAL
# AC_TYPE_SIZE_T
# AC_TYPE_PID_T
# AC_HEADER_TIME

dnl Checks for library functions.
AC_CHECK_FUNCS(getopt snprintf vsnprintf)

AC_OUTPUT(Makefile stunnel.8)

