K5_AC_INIT(db/db.c)
AC_CONFIG_HEADER(include/config.h include/db-config.h)
build_dynobj=yes
CONFIG_RULES

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

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_CHECK_HEADERS(unistd.h stdint.h inttypes.h)
dnl checks for typedefs
AC_TYPE_SIZE_T

dnl AC_COMPILE_TYPE(TYPE, DEFAULT)
AC_DEFUN(AC_COMPILE_TYPE,
[AC_REQUIRE([AC_HEADER_STDC])dnl
AC_MSG_CHECKING(for $1)
AC_CACHE_VAL(ac_cv_type_$1,
[AC_TRY_COMPILE([#include <sys/types.h>
#if STDC_HEADERS
#include <stdlib.h>
#endif], [$1 test_variable;], ac_cv_type_$1=yes, ac_cv_type_$1=no)])dnl
AC_MSG_RESULT($ac_cv_type_$1)
if test $ac_cv_type_$1 = no; then
  AC_DEFINE($1, $2, [Define to \`$2' if not defined on system])
fi
])


AC_CHECK_TYPE(ssize_t, int)

AC_CHECK_TYPE(u_char, unsigned char)
AC_CHECK_TYPE(u_int, unsigned int)
AC_CHECK_TYPE(u_long, unsigned long)

AC_CHECK_TYPE(int8_t, signed char)
AC_CHECK_TYPE(u_int8_t, unsigned char)
AC_CHECK_TYPE(int16_t, short)
AC_CHECK_TYPE(u_int16_t, unsigned short)
AC_COMPILE_TYPE(int32_t, int)
AC_COMPILE_TYPE(u_int32_t, unsigned int)

dnl checks for structures
dnl checks for compiler characteristics
dnl AC_C_BIGENDIAN - No, check at compile time; Darwin can build for multiple
dnl                  targets in one tree.
AC_CHECK_HEADERS(endian.h machine/endian.h sys/param.h)
dnl sys/param.h for AIX 4.3.3 (actually sys/machine.h)
dnl There's also sys/endian.h on IRIX, but we already check _MIPSE{L,B}.
AC_C_CONST

dnl checks for library functions
AC_CHECK_FUNC(memmove, ,
[MEMMOVE_OBJ=memmove.o
AC_DEFINE(memmove, kdb2__memmove,[Define to kdb2__memmove to provide private memmove function])
AC_DEFINE(MEMMOVE,1,[Define if memmove.o is compiled in])])
AC_SUBST(MEMMOVE_OBJ)

AC_CHECK_FUNC(mkstemp, ,
[MKSTEMP_OBJ=mkstemp.o
AC_DEFINE(mkstemp, kdb2__mkstemp,[Define to \`kdb2__mkstemp' to provide private mkstemp function])])
AC_SUBST(MKSTEMP_OBJ)

AC_CHECK_FUNC(strerror, ,
[STRERROR_OBJ=strerror.o
AC_DEFINE(strerror, kdb2__strerror,[Define to \`kdb2__strerror' to provide private strerror function])])
AC_SUBST(STRERROR_OBJ)

KRB5_BUILD_LIBRARY
KRB5_BUILD_LIBOBJS
KRB5_BUILD_PROGRAM
KRB5_RUN_FLAGS
AC_CONFIG_FILES(include/generated.stmp:Makefile.in)
V5_AC_OUTPUT_MAKEFILE(. hash btree db mpool recno clib test)
