dnl Process this file with autoconf to produce a configure script.
AC_INIT(e_os.h)
AM_INIT_AUTOMAKE(SSLeay, 0.8.1)
AM_CONFIG_HEADER(config.h)

AC_ARG_ENABLE(idea,
[  --disable-idea          disable IDEA support],
[if test "$enableval" = no; then
	AC_DEFINE(NO_IDEA)
fi])

AC_ARG_ENABLE(rc2,
[  --disable-rc2           disable RC2 support],
[if test "$enableval" = no; then
	AC_DEFINE(NO_RC2)
fi])

AC_ARG_ENABLE(rc4,
[  --disable-rc4           disable RC4 support],
[if test "$enableval" = no; then
	AC_DEFINE(NO_RC4)
fi])

AC_ARG_ENABLE(longcrypt,
[  --enable-longcrypt      enable HP/UX 10.x long password support],
[if test "$enableval" = yes; then
	AC_DEFINE(LONGCRYPT)
fi])

AC_ARG_ENABLE(anon-dh,
[  --enable-anon-dh        allow server to use SSLv3 anon-DH ciphers],
[if test "$enableval" = yes; then
	AC_DEFINE(SSL_ALLOW_ADH)
fi])

AC_ARG_ENABLE(enull,
[  --enable-enull          allow server to use NULL encryption ciphers],
[if test "$enableval" = yes; then
	AC_DEFINE(SSL_ALLOW_ENULL)
fi])

AC_ARG_ENABLE(lock-debug,
[  --enable-lock-debug     turn on lots of lock debugging output],
[if test "$enableval" = yes; then
	AC_DEFINE(LOCK_DEBUG)
fi])

AC_ARG_ENABLE(ref-check,
[  --enable-ref-check      turn on some foo_free() assertions.],
[if test "$enableval" = yes; then
	AC_DEFINE(REF_CHECK)
fi])

AC_ARG_ENABLE(mdebug,
[  --enable-mdebug         turn on memory leak detection code],
[if test "$enableval" = yes; then
	AC_DEFINE(CRYPTO_MDEBUG)
fi])

AC_ARG_ENABLE(mfunc,
[  --enable-mfunc          use hookable versions of malloc/free/realloc],
[if test "$enableval" = yes; then
	AC_DEFINE(MFUNC)
fi])

dnl Checks for programs.
AC_PROG_CC
AC_PROG_CPP
AM_PROG_INSTALL
AC_PROG_RANLIB
AC_PROG_LN_S

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS([fcntl.h limits.h malloc.h sgtty.h strings.h synch.h \
sys/file.h sys/filio.h sys/fcntl.h sys/ioctl.h sys/param.h sys/prctl.h \
sys/select.h sys/termio.h sys/termios.h sys/time.h sys/timeb.h sys/times.h \
termio.h termios.h typedefs.h unistd.h pwd.h])

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_C_INLINE
AC_STRUCT_TM
AC_C_BIGENDIAN
AC_CANONICAL_HOST
AC_TYPE_SIGNAL
AC_CHECK_SIZEOF(int)
AC_CHECK_SIZEOF(long)

AC_MSG_CHECKING(for optimized assembly code)
BN_MULW=bn_mulw.o
DES_ENC="des_enc.o fcrypt_b.o"
BF_ENC=bf_enc.o
case "$host" in
	i?86-*-bsdi*)
		BN_MULW=asm/x86-bsdi.o
		DES_ENC="asm/dx86bsdi.o asm/cx86bsdi.o"
		BF_ENC="asm/bx86bsdi.o"
		AC_MSG_RESULT([bignums, DES, Blowfish])
		;;
	i?86-*-solaris*)
		BN_MULW=asm/x86-sol.o
		DES_ENC="asm/dx86-sol.o asm/cx86-sol.o"
		BF_ENC="asm/bx86-sol.o"
		AC_MSG_RESULT([bignums, DES, Blowfish])
		;;
	i?86-*-*aout*|i?86-*-*bsd*)
		BN_MULW=asm/x86-lnxa.o
		DES_ENC="asm/dx86-out.o asm/cx86-out.o"
		BF_ENC="asm/bx86-out.o"
		AC_MSG_RESULT([bignums, DES, Blowfish])
		;;
	i?86-*-*elf*|i?86-*-*linux*|i?86-*-*gnu*|i?86-*-*dgux*)
		BN_MULW=asm/x86-lnx.o
		DES_ENC="asm/dx86-elf.o asm/cx86-elf.o"
		BF_ENC="asm/bx86-elf.o"
		AC_MSG_RESULT([bignums, DES, Blowfish])
		;;
	alpha-*-osf*)
		# The Digital UNIX assembler doesn't like alpha.s.
		AC_MSG_RESULT(no)
		;;
	alpha-*)
		BN_MULW=asm/alpha.o
		AC_MSG_RESULT(bignums)
		;;
	hppa*)
		BN_MULW=asm/pa-risc2.o
		AC_MSG_RESULT(bignums)
		;;
	mips-sgi-irix*)
		# I can probably broaden this.  Oh well.
		BN_MULW=asm/r3000.o
		AC_MSG_RESULT(bignums)
		;;
	sparc-*)
		BN_MULW=asm/sparc.o
		AC_MSG_RESULT(bignums)
		;;
	*)
		AC_MSG_RESULT(no)
		;;
esac
AC_SUBST(BN_MULW)
AC_SUBST(DES_ENC)
AC_SUBST(BF_ENC)
AM_CONDITIONAL(ASM_BN_MULW, echo "$BN_MULW" | fgrep asm/ > /dev/null)
AM_CONDITIONAL(ASM_DES_ENC, echo "$DES_ENC" | fgrep asm/ > /dev/null)
AM_CONDITIONAL(ASM_BF_ENC, echo "$BF_ENC" | fgrep asm/ > /dev/null)
if echo "$BN_MULW" | fgrep asm/ > /dev/null; then
	AC_DEFINE(BN_ASM)
fi

if echo "$DES_ENC" | fgrep asm/ > /dev/null; then
	AC_DEFINE(DES_ASM)
fi

if echo "$BF_ENC" | fgrep asm/ > /dev/null; then
	AC_DEFINE(BF_ASM)
fi

dnl Checks for library functions.
AC_PROG_GCC_TRADITIONAL
AC_FUNC_MEMCMP
AC_TYPE_SIGNAL
AC_FUNC_VPRINTF
AC_FUNC_VFORK
AC_CHECK_FUNCS(clock_gettime clock_getres ftime gethrtime getitimer gettimeofday lrand48 mutex_init random select setitimer times usinit tcflush waitpid wait4)
AC_CHECK_FUNCS(socket, [],
    AC_CHECK_LIB(socket, socket, [LIBS="-lsocket -lnsl $LIBS"], [nosocket=1],-lnsl))

oldCPPFLAGS=$CPPFLAGS
CPPFLAGS="-I$srcdir/crypto -I$srcdir/crypto/des $CPPFLAGS"
AC_CACHE_CHECK([which DES optimizations to use], ac_cv_des_opts,
[AC_TRY_RUN([
#include <stdio.h>
int realmain(int, char**);
int main(int argc, char **argv) {
    freopen("conftest.out", "w", stdout);
    freopen("conftest.err", "w", stderr);
    return realmain(argc, argv);
}
#define main realmain

#include "crypto/des/des_opts.c"
#include "crypto/des/set_key.c"
], [ac_cv_des_opts=`tail -1 conftest.out`], [ac_cv_des_opts=none],
[ac_cv_des_opts=none])])
if test "$ac_cv_des_opts" = none; then
	CPPFLAGS=$oldCPPFLAGS
else
	CPPFLAGS="$oldCPPFLAGS $ac_cv_des_opts -DDES_DEFAULT_OPTIONS"
fi

dnl Do not insert any tests after this point.  If you do, they will break.

moreflags='-I${top_srcdir}/include -DX509_CERT_AREA=\"${datadir}/ssl\"'
CPPFLAGS="$CPPFLAGS $moreflags"

AC_ARG_WITH(rsaref,
[  --with-rsaref[=LIBDIR]  use the RSAref RSA implementation],
[if test "$withval" \!= no; then
	AC_DEFINE(RSAref)
	LIBS="-L\$(top_builddir)/rsaref -lRSAglue -lrsaref $LIBS"
	if test "$withval" \!= yes; then
		LIBS="-L$withval $LIBS"
	fi
	CPPFLAGS="$CPPFLAGS -I\$(top_srcdir)/rsaref"
fi])

AC_OUTPUT([Makefile apps/Makefile apps/demoCA/Makefile \
apps/demoCA/certs/Makefile apps/demoCA/crl/Makefile \
apps/demoCA/newcerts/Makefile apps/demoCA/private/Makefile apps/set/Makefile \
apps/stuff/Makefile bugs/Makefile certs/Makefile crypto/Makefile \
crypto/asn1/Makefile crypto/bf/Makefile crypto/bf/asm/Makefile \
crypto/bio/Makefile crypto/bn/Makefile crypto/bn/asm/Makefile \
crypto/bn/stuff/Makefile crypto/buffer/Makefile crypto/conf/Makefile \
crypto/des/Makefile crypto/des/asm/Makefile crypto/des/t/Makefile \
crypto/des/times/Makefile crypto/dh/Makefile crypto/dsa/Makefile \
crypto/err/Makefile crypto/evp/Makefile crypto/idea/Makefile \
crypto/lhash/Makefile crypto/md/Makefile crypto/mdc2/Makefile \
crypto/objects/Makefile crypto/pem/Makefile crypto/perlasm/Makefile \
crypto/pkcs7/Makefile crypto/rand/Makefile crypto/rc2/Makefile \
crypto/rc4/Makefile crypto/rsa/Makefile crypto/sha/Makefile \
crypto/stack/Makefile crypto/txt_db/Makefile crypto/x509/Makefile \
demos/Makefile demos/bio/Makefile demos/maurice/Makefile \
demos/prime/Makefile demos/sign/Makefile demos/ssl/Makefile doc/Makefile \
include/Makefile ms/Makefile mt/Makefile rsaref/Makefile shlib/Makefile \
ssl/Makefile test/Makefile times/Makefile tools/Makefile util/Makefile \
util/pl/Makefile])

echo "#define DATE	\"`date`\"" > crypto/date.h
