dnl Process this file with autoconf to produce a configure script.
AC_INIT(configure)
AM_CONFIG_HEADER(config.h)

AM_INIT_AUTOMAKE(db, 1.85)

dnl AM_PROG_INSTALL
AC_PROG_INSTALL
dnl AM_MAINTAINER_MODE
AC_PROG_MAKE_SET
AC_ARG_PROGRAM

# This is a hack to work around an automake deficiency.  Sigh.
HACK=
AC_SUBST(HACK)

dnl Configure setup.
AC_PROG_CC
AC_PROG_CPP
AC_EXEEXT
AC_OBJEXT

dnl Checks for programs.
AC_PROG_RANLIB

AC_PATH_PROG(FALSE,false,:)
AC_PATH_PROG(SH,sh,$FALSE)
AC_PATH_PROG(SH5,sh5,$FALSE)
AC_PATH_PROG(BASH,bash,$FALSE)

# In the cygwin32 environment, we need some additional flags.
ELBRUS_AC_CYGWIN
ELBRUS_AC_MINGW32

if test x$ide_cv_os_cygwin32 = xyes -o x$ide_cv_os_mingw32 = xyes; then
  WINFLAGS="-DWIN32"
else
  WINFLAGS=
fi

# In the Microsoft Visual C++ compiler.
AC_CACHE_CHECK([for Microsoft Visual C++], sn_cv_os_msvc,
[AC_EGREP_CPP(coool, [
#ifdef _MSC_VER
coool
#endif],[sn_cv_os_msvc=yes],[sn_cv_os_msvc=no])])
if test $sn_cv_os_msvc = yes; then
  WINFLAGS="-DWIN32 -D__MSVC__ -FI\$(srcdir)/win32/NTunixstubs.h -I\$(srcdir)/win32/include"
fi

AC_SUBST(WINFLAGS)

AC_CACHE_CHECK([checking for shell with functions],local_cv_program_fctsh,
[if $SH -c 'foo() { true; }; foo' > /dev/null 2>&1; then
	local_cv_program_fctsh=$SH
else
	if $SH5 -c 'foo() { true; }; foo' > /dev/null 2>&1; then
		local_cv_program_fctsh=$SH5
	else
		if $BASH -c 'foo() { true; }; foo' > /dev/null 2>&1; then
			local_cv_program_fctsh=$BASH
		else
			local_cv_program_fctsh=$FALSE
		fi
	fi
fi])

FCTSH=$local_cv_program_fctsh
AC_SUBST(FCTSH)

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_SYS_WAIT
AC_CHECK_HEADERS(fcntl.h limits.h sys/time.h unistd.h)

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

AC_MSG_CHECKING(for u_char)
AC_CACHE_VAL(db_cv_type_u_char, [dnl
AC_TRY_COMPILE([#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <sys/types.h>], [u_char c = '0';], db_cv_type_u_char=yes,
db_cv_type_u_char=no)])
AC_MSG_RESULT($db_cv_type_u_char)
if test "$db_cv_type_u_char" = yes; then
   AC_DEFINE(HAVE_UCHAR_T)
fi

dnl Checks for library functions.
AC_FUNC_VPRINTF
AC_FUNC_MMAP
AC_CHECK_FUNCS(mkdir rmdir select)
AC_REPLACE_FUNCS(memmove snprintf strerror)
# memcmp strdup
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.
dnl When cross compiling, we assume that ANSI standard character count.
AC_MSG_CHECKING(for sprintf return value)
AC_CACHE_VAL(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],
	[db_cv_sprintf_count=no])])
if test "$db_cv_sprintf_count" = no; then
	AC_DEFINE(SPRINTF_RET_CHARPNT)
fi
AC_MSG_RESULT($db_cv_sprintf_count)

dnl Do some other checks.  Done via a macro because other packages
dnl have to use this to include db.h.
CY_AC_BERKELEY_DB

AC_OUTPUT([Makefile PORT/Makefile include/Makefile])
