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

AC_PREREQ(2.57)
AC_INIT

VERSION=`cat ${srcdir}/../.version`
MAJOR_VERSION=[`expr $VERSION : '\([0-9][0-9]*\)'`]
AC_SUBST(MAJOR_VERSION)
MINOR_VERSION=[`expr $VERSION : '[0-9][0-9]*\.\([0-9][0-9]*\)'`]
AC_SUBST(MINOR_VERSION)
MICRO_VERSION=[`expr $VERSION : '[0-9][0-9]*\.[0-9][0-9]*\.\([0-9][0-9]*\)'`]
AC_SUBST(MICRO_VERSION)

AM_INIT_AUTOMAKE(htdig_db, $VERSION,nosubst)
AC_CONFIG_SRCDIR([db_byteorder.c])
AM_CONFIG_HEADER([db_config.h])
AC_CANONICAL_HOST

# Initialize maintainer mode
AM_MAINTAINER_MODE

# Checks for programs.
AC_PROG_CXX
AC_PROG_CC
AC_PROG_LIBTOOL
AC_PROG_INSTALL

# Checks for libraries.
CHECK_ZLIB

# Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_CHECK_HEADERS([fcntl.h limits.h stddef.h stdlib.h string.h sys/select.h sys/time.h unistd.h])

# Checks for typedefs, structures, and compiler characteristics.
AC_C_BIGENDIAN
AC_C_CONST
AC_HEADER_STAT
AC_HEADER_TIME
AC_TYPE_OFF_T
AC_TYPE_MODE_T
AC_TYPE_SIZE_T
AC_TYPE_PID_T
AC_TYPE_SIZE_T
AC_CHECK_MEMBERS([struct stat.st_blksize])

dnl Define any short-hand types we're missing.
AM_SHORTHAND_TYPES

# Process all options before using them.  This is necessary because there
# are dependencies among them.
AM_OPTIONS_SET

dnl Check for mutexes.  We do this here because it changes $LIBS.
AM_DEFINE_MUTEXES


# This is where we handle stuff that autoconf can't handle: compiler,
# preprocessor and load flags, libraries that the standard tests don't
# look for.  The default optimization is -O.
#
# There are additional libraries we need for some compiler/architecture
# combinations.
#
# Some architectures require DB to be compiled with special flags and/or
# libraries for threaded applications
#
# The makefile CC may be different than the CC used in config testing,
# because the makefile CC may be set to use $(LIBTOOL).
#
# XXX
# Don't override anything if it's already set from the environment.
optimize_def="-O"
case "$host_os" in
aix4.*)	   optimize_def="-O2"
	   CC=${CC-"xlc_r"}
	   CPPFLAGS="-D_THREAD_SAFE $CPPFLAGS";;
bsdi3*)	   CC=${CC-"shlicc2"}
	   optimize_def="-O2"
	   LIBS="-lipc $LIBS";;
bsdi*)	   optimize_def="-O2";;
freebsd*)  optimize_def="-O2"
	   CPPFLAGS="-D_THREAD_SAFE -pthread $CPPFLAGS";;
hpux*)	   CPPFLAGS="-D_REENTRANT $CPPFLAGS";;
irix*)	   optimize_def="-O2"
	   CPPFLAGS="-D_SGI_MP_SOURCE $CPPFLAGS";;
linux*)	   optimize_def="-O2"
	   CPPFLAGS="-D_REENTRANT $CPPFLAGS";;
mpeix*)	   CPPFLAGS="-D_POSIX_SOURCE -D_SOCKET_SOURCE $CPPFLAGS"
	   LIBS="-lsocket -lsvipc $LIBS";;
osf*)	   CPPFLAGS="-D_REENTRANT $CPPFLAGS";;
sco3.2v4*) CC=${CC-"cc -belf"}
	   LIBS="-lsocket -lnsl_s $LIBS";;
sco*)	   CC=${CC-"cc -belf"}
	   LIBS="-lsocket -lnsl $LIBS";;
solaris*)  CPPFLAGS="-D_REENTRANT $CPPFLAGS";;
esac

CFLAGS=${CFLAGS-$optimize_def}
CXXFLAGS=${CXXFLAGS-"$CFLAGS"}

# If the user wants a debugging environment, add -g to the CFLAGS value.
#
# XXX
# Some compilers can't mix optimizing and debug flags.  The only way to
# handle this is to specify CFLAGS in the environment before configuring.
if test "$db_cv_debug" = yes; then
	AC_DEFINE(DEBUG,,[degbug environment enabled])
	CFLAGS="$CFLAGS -g"
	CXXFLAGS="$CXXFLAGS -g"
fi

dnl Set some #defines based on configuration options.
if test "$db_cv_diagnostic" = yes; then
	AC_DEFINE(DIAGNOSTIC,,[Enables diagnostic])
fi
if test "$db_cv_debug_rop" = yes; then
	AC_DEFINE(DEBUG_ROP,,[Log operations that read the database])
fi
if test "$db_cv_debug_wop" = yes; then
	AC_DEFINE(DEBUG_WOP,,[Log operations that write to the database])
fi
# Checks for library functions.
AC_FUNC_CLOSEDIR_VOID
AC_FUNC_MALLOC
AC_FUNC_MEMCMP
AC_FUNC_MMAP
AC_FUNC_REALLOC
AC_FUNC_SELECT_ARGTYPES
AC_FUNC_STAT
AC_FUNC_VPRINTF
AC_CHECK_FUNCS([getcwd getuid memmove memset munmap pstat_getdynamic sched_yeeld select strchr strerror strstr strtol sysconf yeld])

AC_CONFIG_FILES([Makefile db.h])
AC_OUTPUT
