dnl @(#)configure.in	10.74 (Sleepycat) 12/2/98
dnl Process this file with autoconf to produce a configure script.

AC_INIT(../db/db.c)
AC_CONFIG_HEADER(config.h:config.hin)

dnl We cannot build in the top-level directory.
AC_MSG_CHECKING(if building in the top-level directory)
[ test -d db_archive ] && AC_MSG_ERROR([
Berkeley DB cannot be built in the top-level distribution directory.])

dnl Configure setup.
AC_PROG_INSTALL()
AC_CANONICAL_HOST
AC_ARG_PROGRAM()

dnl This is where we handle stuff that autoconf can't handle: compiler,
dnl preprocessor and load flags, libraries that the standard tests don't
dnl look for.  The default optimization is -O.
dnl
dnl XXX
dnl Don't override anything if it's already set from the environment.
AC_SUBST(CFLAGS)
AC_SUBST(CPPFLAGS)
AC_SUBST(CXX)
AC_SUBST(CXXFLAGS)
AC_SUBST(LDFLAGS)
case "$host_os" in
aix4.1*)   CFLAGS=${CFLAGS-"-O3"};;
bsd4.4)    CFLAGS=${CFLAGS-"-O2"};;
bsdi4*)	   CFLAGS=${CFLAGS-"-O2"};;
bsdi*)	   CC=${CC-"shlicc2"}
	   CFLAGS=${CFLAGS-"-O2"}
	   LIBS="-lipc $LIBS";;
irix*)	   CFLAGS=${CFLAGS-"-O2"};;
nextstep3) CFLAGS=${CFLAGS-"-O2"};;
linux*)	   CFLAGS=${CFLAGS-"-O2"};;
mpeix*)	   CPPFLAGS="-D_POSIX_SOURCE -D_SOCKET_SOURCE $CPPFLAGS"
	   LIBS="-lsocket -lsvipc $LIBS";;
sco*)	   CFLAGS="$CFLAGS -b elf"
	   LIBS="-lsocket -lnsl $LIBS";;
*)	   CFLAGS=${CFLAGS-"-O"};;
esac
CXXFLAGS=${CXXFLAGS-"$CFLAGS"}

dnl If the user wants a debugging environment, add -g to the CFLAGS value.
dnl
dnl XXX
dnl Some compilers can't mix optimizing and debug flags.  The only way to
dnl handle this is to specify CFLAGS in the environment before configuring.
AC_MSG_CHECKING(if --enable-debug option specified)
AC_ARG_ENABLE(debug,
	[  --enable-debug          Build a debugging version.],
	[db_cv_debug="$enable_debug"], [db_cv_debug="no"])
AC_MSG_RESULT($db_cv_debug)
if test "$db_cv_debug" = yes; then
	AC_DEFINE(DEBUG)
	CFLAGS="$CFLAGS -g"
	CXXFLAGS="$CXXFLAGS -g"
fi

dnl The default compiler is cc (NOT gcc), the default CFLAGS is as specified
dnl above, NOT what is set by AC_PROG_CC, as it won't set optimization flags.
dnl We still call AC_PROG_CC so that we get the other side-effects.
AC_CHECK_PROG(CC, cc, cc)
AC_CHECK_PROG(CC, gcc, gcc)
AC_PROG_CC

dnl If the user wants run-time checks, define DIAGNOSTIC.
AC_MSG_CHECKING(if --enable-diagnostic option specified)
AC_ARG_ENABLE(diagnostic,
	[  --enable-diagnostic     Build a version with run-time diagnostics.],
	[db_cv_diagnostic="$enable_diagnostic"], [db_cv_diagnostic="no"])
AC_MSG_RESULT($db_cv_diagnostic)
if test "$db_cv_diagnostic" = yes; then
	AC_DEFINE(DIAGNOSTIC)
fi

dnl Optional C++ API..
dnl
dnl XXX
dnl Versions of GCC up to 2.8.0 required -fhandle-exceptions, but it is
dnl the default in versions 2.8.0 and after.
AC_MSG_CHECKING(if --enable-cxx option specified)
AC_ARG_ENABLE(cxx,
	[  --enable-cxx            Provide C++ interfaces.],
	[db_cv_cxx="$enable_cxx"], [db_cv_cxx="no"])
AC_MSG_RESULT($db_cv_cxx)
if test "$db_cv_cxx" = "yes"; then
	AC_PROG_CXX

	if test "$GXX" = "yes"; then
		CXXFLAGS="-fhandle-exceptions $CXXFLAGS"
	fi

	LIBOBJS="$LIBOBJS \$(COBJS)"
fi

dnl There are additional libraries we need for some compiler/architecture
dnl combinations.
AC_SUBST(LIBS)

dnl Optional DB 1.85 compatibility API.
AC_MSG_CHECKING(if --enable-compat185 option specified)
AC_ARG_ENABLE(compat185,
	[  --enable-compat185      Include DB 1.85 compatibility API.],
	[db_cv_compat185="$enable_compat185"], [db_cv_compat185="no"])
AC_MSG_RESULT($db_cv_compat185)
if test "$db_cv_compat185" = "yes"; then
	LIBOBJS="db185.o $LIBOBJS"
fi

dnl Optional utilities.
AC_SUBST(build_additional)
AC_MSG_CHECKING(if --enable-dump185 option specified)
AC_ARG_ENABLE(dump185,
	[  --enable-dump185        Build db_dump185(1) to dump 1.85 databases.],
	[db_cv_dump185="$enable_dump185"], [db_cv_dump185="no"])
AC_MSG_RESULT($db_cv_dump185)
if test "$db_cv_dump185" = "yes"; then
	build_additional="db_dump185 $build_additional"
fi

dnl Check for programs used in building and installation.
AC_PATH_PROG(db_cv_path_ar, ar, missing_ar)
if test "$db_cv_path_ar" = missing_ar; then
	AC_MSG_ERROR([No ar utility found.])
fi
AC_PATH_PROG(db_cv_path_chmod, chmod, missing_chmod)
if test "$db_cv_path_chmod" = missing_chmod; then
	AC_MSG_ERROR([No chmod utility found.])
fi
AC_PATH_PROG(db_cv_path_cp, cp, missing_cp)
if test "$db_cv_path_cp" = missing_cp; then
	AC_MSG_ERROR([No cp utility found.])
fi
AC_PATH_PROG(db_cv_path_mkdir, mkdir, missing_mkdir)
if test "$db_cv_path_mkdir" = missing_mkdir; then
	AC_MSG_ERROR([No mkdir utility found.])
fi
AC_PATH_PROG(db_cv_path_ranlib, ranlib, missing_ranlib)
AC_PATH_PROG(db_cv_path_rm, rm, missing_rm)
if test "$db_cv_path_rm" = missing_rm; then
	AC_MSG_ERROR([No rm utility found.])
fi
AC_PATH_PROG(db_cv_path_sh, sh, missing_sh)
if test "$db_cv_path_sh" = missing_sh; then
	AC_MSG_ERROR([No sh utility found.])
fi
AC_PATH_PROG(db_cv_path_strip, strip, missing_strip)
if test "$db_cv_path_strip" = missing_strip; then
	AC_MSG_ERROR([No strip utility found.])
fi

dnl Checks for typedefs, structures, and compiler characteristics.
AC_CHECK_TYPE(ssize_t, int)
AC_C_BIGENDIAN
AC_C_CONST
AC_STRUCT_ST_BLKSIZE
AC_HEADER_STAT
AC_TYPE_MODE_T
AC_TYPE_OFF_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T

dnl Checks for header files.
AC_HEADER_DIRENT
AC_CHECK_HEADERS(sys/select.h)
AC_CHECK_HEADERS(sys/time.h)

dnl Checks for system functions for which we have replacements.
dnl
dnl XXX
dnl The only portable getcwd call is getcwd(char *, size_t), where the
dnl buffer is non-NULL -- Solaris can't handle a NULL buffer, and they
dnl deleted getwd().
AC_REPLACE_FUNCS(getcwd getopt memcmp memcpy memmove)
AC_REPLACE_FUNCS(raise snprintf strerror strsep vsnprintf)

dnl Check for system functions we optionally use.
AC_CHECK_FUNCS(getuid pread pstat_getdynamic sysconf)

dnl A/UX has a broken getopt(3).
case "$host_os" in
aux*)	LIBOBJS="getopt.o $LIBOBJS";;
esac

dnl Checks for system functions for which we don't have replacements.
dnl
dnl HP/UX has the shmget(2) interfaces, but you can't use them to hold
dnl mutexes, so they're useless.
dnl
dnl SunOS has the shmget(2) interfaces, but there appears to be a missing
dnl #include <debug/debug.h> file, so we ignore them.
dnl
dnl Nextstep (version 3.3) apparently supports mmap(2) (the mmap symbol is
dnl defined in the C library) but does not support munmap(2).  Don't try
dnl to find mmap if we can't find munmap.
shmget_ok=no
case "$host_os" in
hpux*)
	AC_MSG_WARN([shmget(2) interface ignored on HP/UX.]);;
sunos*)
	AC_MSG_WARN([shmget(2) interface ignored on SunOS.]);;
*)
	shmget_ok=yes
	AC_CHECK_FUNCS(shmget, , shmget_ok=no)
esac
mmap_ok=no
case "$host_os" in
ultrix*)
	AC_MSG_WARN([mmap(2) interface ignored on Ultrix.]);;
*)
	mmap_ok=yes
	AC_CHECK_FUNCS(mmap munmap, , mmap_ok=no)
esac

dnl We require either mmap/munmap(2) or shmget(2).
if test "$mmap_ok" = no -a "$shmget_ok" = no; then
	AC_MSG_ERROR([Neither mmap/munmap(2) or shmget(2) library functions.])
fi

dnl We require qsort(3) and select(2).
AC_CHECK_FUNCS(qsort, , AC_MSG_ERROR([No qsort library function.]))
AC_CHECK_FUNCS(select, , AC_MSG_ERROR([No select library function.]))

dnl Check for the sigfillset macro/function.  If it exists, we assume we can
dnl use it and sigprocmask to we block signals when creating temporary files.
AC_CACHE_CHECK([for sigfillset], db_cv_have_sigfillset, [dnl
AC_TRY_LINK([#include <signal.h>], [sigset_t set; sigfillset(&set);],
        [db_cv_have_sigfillset=yes], [db_cv_have_sigfillset=no])])
if test "$db_cv_have_sigfillset" = yes; then
	AC_DEFINE(HAVE_SIGFILLSET)
fi

dnl Some versions of sprintf return a pointer to the first argument instead
dnl of a character count.  We assume that the return value of snprintf and
dnl vsprintf etc. will be the same as sprintf, and check the easy one.
AC_CACHE_CHECK([for int type sprintf return value], db_cv_sprintf_count, [dnl
AC_TRY_RUN([main(){char buf[20]; exit(sprintf(buf, "XXX") != 3);}],
	[db_cv_sprintf_count=yes], [db_cv_sprintf_count=no])])
if test "$db_cv_sprintf_count" = no; then
	AC_DEFINE(SPRINTF_RET_CHARPNT)
fi

dnl Vendors are doing 64-bit lseek in different ways.
dnl AIX, HP/UX and Solaris all use _FILE_OFFSET_BITS to specify a "big-file"
dnl environment.
AC_MSG_CHECKING(if --disable-bigfile option specified)
AC_ARG_ENABLE(bigfile,
	[  --disable-bigfile       Disable AIX, HP/UX, Solaris big files.],
	[db_cv_bigfile="$enable_bigfile"], [db_cv_bigfile="yes"])
if test "$db_cv_bigfile" = yes; then
	case "$host_os" in
	bsdi*|aix*|hpux*|solaris*)      AC_DEFINE(HAVE_FILE_OFFSET_BITS);;
	esac
	AC_MSG_RESULT("no")
else
	AC_MSG_RESULT("yes")
fi

dnl Figure out if we have spinlocks for the compiler/architecture.
AC_CACHE_CHECK([for spinlocks], db_cv_spinlocks, [dnl
db_cv_spinlocks=no

dnl msemaphore: HPPA
dnl Try HPPA before general msem test, it needs special mutex alignment.
if test "$db_cv_spinlocks" = no; then
AC_TRY_RUN([main(){
#if defined(__hppa)
#include <sys/mman.h>
typedef msemaphore tsl_t;
msemaphore x; msem_init(&x, 0); msem_lock(&x, 0); msem_unlock(&x, 0);
exit(0);
#else
exit(1);
#endif
}], [db_cv_spinlocks=msem-hppa/func])
fi

dnl msemaphore: OSF/1
if test "$db_cv_spinlocks" = no; then
AC_TRY_LINK([#include <sys/types.h>],
[#include <sys/mman.h>;
 typedef msemaphore tsl_t;
msemaphore x; msem_init(&x, 0); msem_lock(&x, 0); msem_unlock(&x, 0);],
[db_cv_spinlocks=msem/func])
fi

dnl ReliantUNIX
if test "$db_cv_spinlocks" = no; then
saved_libs="$LIBS"
LIBS="$LIBS -lmproc"
AC_TRY_LINK([#include <ulocks.h>],
[typedef spinlock_t tsl_t;
 spinlock_t x; initspin(&x, 1); cspinlock(&x); spinunlock(&x);],
[db_cv_spinlocks=reliant/func],[LIBS="$saved_libs"])
fi

dnl SCO: UnixWare has threads in libthread, but OpenServer doesn't.
if test "$db_cv_spinlocks" = no; then
AC_TRY_RUN([main(){
#if defined(__USLC__)
exit(0);
#endif
exit(1);}], [db_cv_spinlocks=sco/cc])
fi

dnl abilock_t: SGI
if test "$db_cv_spinlocks" = no; then
AC_TRY_LINK([#include <abi_mutex.h>],
[typedef abilock_t tsl_t;
 abilock_t x; init_lock(&x); acquire_lock(&x); release_lock(&x);],
[db_cv_spinlocks=sgi/func])
fi

dnl sema_t: Solaris
dnl The semaphore calls do not work on Solaris 5.5.
if test "$db_cv_spinlocks" = NOTYET; then
AC_TRY_LINK([#include <synch.h>],
[typedef sema_t tsl_t;
 sema_t x;
 sema_init(&x, 1, USYNC_PROCESS, NULL); sema_wait(&x); sema_post(&x);],
[db_cv_spinlocks=solaris/func])
fi

dnl _lock_try/_lock_clear: Solaris
if test "$db_cv_spinlocks" = no; then
AC_TRY_LINK([#include <sys/machlock.h>],
[typedef lock_t tsl_t;
 lock_t x;
 _lock_try(&x); _lock_clear(&x);],
[db_cv_spinlocks=solaris/func])
fi

dnl _check_lock/_clear_lock: AIX
if test "$db_cv_spinlocks" = no; then
AC_TRY_LINK([#include <sys/atomic_op.h>],
[int x; _check_lock(x,0,1); _clear_lock(x,0);],
[db_cv_spinlocks=aix/func])
fi

dnl PaRisc/gcc: HP/UX
if test "$db_cv_spinlocks" = no; then
AC_TRY_RUN([main(){
#if defined(__hppa)
#if defined(__GNUC__)
exit(0);
#endif
#endif
exit(1);}], [db_cv_spinlocks=parisc/gcc])
fi

dnl Sparc/gcc: Solaris
if test "$db_cv_spinlocks" = no; then
AC_TRY_RUN([main(){
#if defined(__sparc__)
#if defined(__GNUC__)
exit(0);
#endif
#endif
exit(1);}], [db_cv_spinlocks=sparc/gcc])
fi

dnl 68K/gcc: SunOS
if test "$db_cv_spinlocks" = no; then
AC_TRY_RUN([main(){
#if (defined(mc68020) || defined(sun3))
#if defined(__GNUC__)
exit(0);
#endif
#endif
exit(1);}], [db_cv_spinlocks=mc68020/gcc])
fi

dnl x86/gcc: BSD/OS, FreeBSD, NetBSD, Linux
if test "$db_cv_spinlocks" = no; then
AC_TRY_RUN([main(){
#if defined(i386)
#if defined(__GNUC__)
exit(0);
#endif
#endif
exit(1);}], [db_cv_spinlocks=x86/gcc])
fi

dnl: uts/cc: UTS
if test "$db_cv_spinlocks" = no; then
AC_TRY_RUN([main(){
#if defined(_UTS)
exit(0);
#endif
exit(1);}], [db_cv_spinlocks=uts4/cc])
fi

])

if test "$db_cv_spinlocks" = no; then
	AC_MSG_WARN([SPINLOCKS NOT IMPLEMENTED FOR THIS COMPILER/ARCHITECTURE.])
else
	AC_DEFINE(HAVE_SPINLOCKS)
fi

dnl Some architectures require DB to be compiled with special flags and/or
dnl libraries for threaded applications
case "$host_os" in
freebsd*) CPPFLAGS="-D_THREAD_SAFE $CPPFLAGS"
	  LIBS="-lc_r";;
irix*)    CPPFLAGS="-D_SGI_MP_SOURCE $CPPFLAGS";;
osf*)	  CPPFLAGS="-D_REENTRANT $CPPFLAGS";;
solaris*) CPPFLAGS="-D_REENTRANT $CPPFLAGS"
	  LIBS="-lthread $LIBS";;
esac

AC_SUBST(spin_line1)
AC_SUBST(spin_line2)
AC_SUBST(spin_line3)
AC_SUBST(mutex_align)
case "$db_cv_spinlocks" in
aix/func)
	AC_DEFINE(HAVE_FUNC_AIX)
	mutex_align="sizeof(int)"
	spin_line1="#include <sys/atomic_op.h>"
	spin_line2="typedef int tsl_t;";;
mc68020/gcc)
	AC_DEFINE(HAVE_ASSEM_MC68020_GCC)
	mutex_align="1"
	spin_line1="typedef unsigned char tsl_t;";;
msem-hppa/func)
	AC_DEFINE(HAVE_FUNC_MSEM)
	mutex_align="16"
	spin_line1="#include <sys/mman.h>"
	spin_line2="typedef msemaphore tsl_t;";;
msem/func)
	AC_DEFINE(HAVE_FUNC_MSEM)
	mutex_align="sizeof(int)"
	spin_line1="#include <sys/mman.h>"
	spin_line2="typedef msemaphore tsl_t;";;
parisc/gcc)
	AC_DEFINE(HAVE_ASSEM_PARISC_GCC)
	mutex_align="16"
	spin_line1="typedef u_int32_t tsl_t;";;
reliant/func)
	AC_DEFINE(HAVE_FUNC_RELIANT)
	mutex_align="1"
	spin_line1="#include <ulocks.h>"
	spin_line2="typedef spinlock_t tsl_t;";;
sgi/func)
	AC_DEFINE(HAVE_FUNC_SGI)
	mutex_align="sizeof(int)"
	spin_line1="#include <abi_mutex.h>"
	spin_line2="typedef abilock_t tsl_t;";;
NOTYET_solaris/func)
	AC_DEFINE(HAVE_FUNC_SOLARIS)
	mutex_align="sizeof(int)"
	spin_line1="#include <synch.h>"
	spin_line2="typedef sema_t tsl_t;";;
sco/cc)
	AC_DEFINE(HAVE_ASSEM_SCO_CC)
	mutex_align="1"
	spin_line1="typedef unsigned char tsl_t;";;
solaris/func)
	AC_DEFINE(HAVE_FUNC_SOLARIS)
	mutex_align="sizeof(int)"
	spin_line1="#include <sys/machlock.h>"
	spin_line2="typedef lock_t tsl_t;";;
sparc/gcc)
	AC_DEFINE(HAVE_ASSEM_SPARC_GCC)
	mutex_align="1"
	spin_line1="typedef unsigned char tsl_t;";;
uts4/cc)
	AC_DEFINE(HAVE_ASSEM_UTS4_CC)
	mutex_align="sizeof(int)"
	spin_line1="typedef int tsl_t;"
	LIBOBJS="$LIBOBJS uts4.cc.o";;
x86/gcc)
	AC_DEFINE(HAVE_ASSEM_X86_GCC)
	mutex_align="1"
	spin_line1="typedef unsigned char tsl_t;";;
*)
	mutex_align="1";;
esac

dnl Check for the standard shorthand types.
AC_SUBST(u_char_decl)
AC_CACHE_CHECK([for u_char], db_cv_uchar, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], u_char foo;,
	[db_cv_uchar=yes], [db_cv_uchar=no])])
if test "$db_cv_uchar" = no; then
	u_char_decl="typedef unsigned char u_char;"
fi

AC_SUBST(u_short_decl)
AC_CACHE_CHECK([for u_short], db_cv_ushort, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], u_short foo;,
	[db_cv_ushort=yes], [db_cv_ushort=no])])
if test "$db_cv_ushort" = no; then
	u_short_decl="typedef unsigned short u_short;"
fi

AC_SUBST(u_int_decl)
AC_CACHE_CHECK([for u_int], db_cv_uint, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], u_int foo;,
	[db_cv_uint=yes], [db_cv_uint=no])])
if test "$db_cv_uint" = no; then
	u_int_decl="typedef unsigned int u_int;"
fi

AC_SUBST(u_long_decl)
AC_CACHE_CHECK([for u_long], db_cv_ulong, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], u_long foo;,
	[db_cv_ulong=yes], [db_cv_ulong=no])])
if test "$db_cv_ulong" = no; then
	u_long_decl="typedef unsigned long u_long;"
fi

dnl DB/Vi use specific integer sizes.
AC_SUBST(u_int8_decl)
AC_CACHE_CHECK([for u_int8_t], db_cv_uint8, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], u_int8_t foo;,
	[db_cv_uint8=yes],
	AC_TRY_RUN([main(){exit(sizeof(unsigned char) != 1);}],
	    [db_cv_uint8="unsigned char"], [db_cv_uint8=no]))])
if test "$db_cv_uint8" = no; then
	AC_MSG_ERROR(No unsigned 8-bit integral type.)
fi
if test "$db_cv_uint8" != yes; then
	u_int8_decl="typedef $db_cv_uint8 u_int8_t;"
fi

AC_SUBST(u_int16_decl)
AC_CACHE_CHECK([for u_int16_t], db_cv_uint16, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], u_int16_t foo;,
	[db_cv_uint16=yes],
AC_TRY_RUN([main(){exit(sizeof(unsigned short) != 2);}],
	[db_cv_uint16="unsigned short"],
AC_TRY_RUN([main(){exit(sizeof(unsigned int) != 2);}],
	[db_cv_uint16="unsigned int"], [db_cv_uint16=no])))])
if test "$db_cv_uint16" = no; then
	AC_MSG_ERROR([No unsigned 16-bit integral type.])
fi
if test "$db_cv_uint16" != yes; then
	u_int16_decl="typedef $db_cv_uint16 u_int16_t;"
fi

AC_SUBST(int16_decl)
AC_CACHE_CHECK([for int16_t], db_cv_int16, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], int16_t foo;,
	[db_cv_int16=yes],
AC_TRY_RUN([main(){exit(sizeof(short) != 2);}],
	[db_cv_int16="short"],
AC_TRY_RUN([main(){exit(sizeof(int) != 2);}],
	[db_cv_int16="int"], [db_cv_int16=no])))])
if test "$db_cv_int16" = no; then
	AC_MSG_ERROR([No signed 16-bit integral type.])
fi
if test "$db_cv_int16" != yes; then
	int16_decl="typedef $db_cv_int16 int16_t;"
fi

AC_SUBST(u_int32_decl)
AC_CACHE_CHECK([for u_int32_t], db_cv_uint32, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], u_int32_t foo;,
	[db_cv_uint32=yes],
AC_TRY_RUN([main(){exit(sizeof(unsigned int) != 4);}],
	[db_cv_uint32="unsigned int"],
AC_TRY_RUN([main(){exit(sizeof(unsigned long) != 4);}],
	[db_cv_uint32="unsigned long"], [db_cv_uint32=no])))])
if test "$db_cv_uint32" = no; then
	AC_MSG_ERROR([No unsigned 32-bit integral type.])
fi
if test "$db_cv_uint32" != yes; then
	u_int32_decl="typedef $db_cv_uint32 u_int32_t;"
fi

AC_SUBST(int32_decl)
AC_CACHE_CHECK([for int32_t], db_cv_int32, [dnl
AC_TRY_COMPILE([#include <sys/types.h>], int32_t foo;,
	[db_cv_int32=yes],
AC_TRY_RUN([main(){exit(sizeof(int) != 4);}],
	[db_cv_int32="int"],
AC_TRY_RUN([main(){exit(sizeof(long) != 4);}],
	[db_cv_int32="long"], [db_cv_int32=no])))])
if test "$db_cv_int32" = no; then
	AC_MSG_ERROR([No signed 32-bit integral type.])
fi
if test "$db_cv_int32" != yes; then
	int32_decl="typedef $db_cv_int32 int32_t;"
fi

AC_MSG_CHECKING(if --enable-test option specified)
AC_ARG_ENABLE(test,
	[  --enable-test           Build the Tcl-based test suite.],
	[db_cv_test="$enable_test"], [db_cv_test="no"])
AC_MSG_RESULT($db_cv_test)

if test "$db_cv_test" = yes; then
	dnl Try to find the Tk/Tcl library.
	dnl
	dnl XXX
	dnl Some systems require -ldl (Linux, BSD/OS 3.X), and we have to
	dnl figure that out.  There are two problems here: (1) assume that
	dnl loading Tcl_Eval, Tcl_VarEval and Tcl_EvalFile will force a
	dnl load error if -ldl or -lm are needed and not there.  (2) use
	dnl different function names on each test, otherwise we find the
	dnl result of the first test in the cache and don't do subsequent
	dnl checks.
	AC_CHECK_LIB(tcl, Tcl_Eval, [db_cv_tcl="-ltcl"],
	    [AC_CHECK_LIB(tcl, Tcl_VarEval, [db_cv_tcl="-ltcl -ldl -lm"],
	    [AC_CHECK_LIB(tcl, Tcl_EvalFile, [db_cv_tcl="-ltcl -lm"],
	    [db_cv_tcl=no], -lm)], -ldl -lm)])

	if test "$db_cv_tcl" = "no"; then
		AC_MSG_ERROR([No Tcl library: unable to build test program.])
	else
		build_additional="dbtest $build_additional"
		LIBS="$LIBS $db_cv_tcl"
	fi

	dnl Check for programs used in testing.
	AC_PATH_PROG(db_cv_path_cmp, cmp, missing_cmp)
	if test "$db_cv_path_cmp" = missing_cmp; then
		AC_MSG_ERROR([No cmp utility found.])
	fi
	AC_PATH_PROG(db_cv_path_diff, diff, missing_diff)
	if test "$db_cv_path_diff" = missing_diff; then
		AC_MSG_ERROR([No diff utility found.])
	fi
	AC_PATH_PROG(db_cv_path_kill, kill, missing_kill)
	if test "$db_cv_path_kill" = missing_kill; then
		AC_MSG_ERROR([No kill utility found.])
	fi
	AC_PATH_PROG(db_cv_path_ls, ls, missing_ls)
	if test "$db_cv_path_ls" = missing_ls; then
		AC_MSG_ERROR([No ls utility found.])
	fi
	AC_PATH_PROG(db_cv_path_mv, mv, missing_mv)
	if test "$db_cv_path_mv" = missing_mv; then
		AC_MSG_ERROR([No mv utility found.])
	fi
	AC_PATH_PROG(db_cv_path_sed, sed, missing_sed)
	if test "$db_cv_path_sed" = missing_sed; then
		AC_MSG_ERROR([No sed utility found.])
	fi
	AC_PATH_PROG(db_cv_path_sleep, sleep, missing_sleep)
	if test "$db_cv_path_sleep" = missing_sleep; then
		AC_MSG_ERROR([No sleep utility found.])
	fi
	AC_PATH_PROG(db_cv_path_sort, sort, missing_sort)
	if test "$db_cv_path_sort" = missing_sort; then
		AC_MSG_ERROR([No sort utility found.])
	fi
	AC_PATH_PROG(db_cv_path_tr, tr, missing_tr)
	if test "$db_cv_path_tr" = missing_tr; then
		AC_MSG_ERROR([No tr utility found.])
	fi
fi

AC_OUTPUT(Makefile include.tcl:../test/include.tcl \
    db.h:../include/db.h db_int.h:../include/db_int.h \
    db_185.h:../include/db_185.h)
