dnl Process this file with autoconf to produce a configure script.
dnl
dnl Copyright 1998 - 2001 Double Precision, Inc.  See COPYING for
dnl distribution information.

AC_INIT(maildir, 0.11, [courier-maildrop@lists.sourceforge.net])

>confdefs.h  # Kill PACKAGE_ macros

AC_CONFIG_SRCDIR(maildirquota.c)
LPATH="$PATH:/usr/local/bin"
AC_CANONICAL_SYSTEM
AM_INIT_AUTOMAKE([foreign no-define])
AM_CONFIG_HEADER(config.h)

dnl Checks for programs.
AC_PROG_AWK
AC_USE_SYSTEM_EXTENSIONS
AC_PROG_CC
AC_PROG_INSTALL
AC_PROG_LN_S
AC_LIBTOOL_DLOPEN
AM_PROG_LIBTOOL

AC_PROG_CXX

AC_PATH_PROGS(PERL, perl5 perl, perl, $LPATH)

if test "$GCC" = "yes"
then
	CFLAGS="$CFLAGS -Wall"
fi

if test "$GXX" = "yes"
then
	CXXFLAGS="$CXXFLAGS -Wall"
fi

CFLAGS="$CFLAGS -I${srcdir}/.. -I.."

dnl Checks for libraries.

dnl Checks for header files.
AC_HEADER_DIRENT
AC_HEADER_STDC
AC_HEADER_TIME
AC_CHECK_HEADERS(sys/stat.h sys/wait.h fcntl.h unistd.h sysexits.h utime.h pcre.h pcre/pcre.h)

AC_CHECK_HEADER([pcre.h],
		[LIBPCRE=-lpcre])

AC_CHECK_HEADER([pcre/pcre.h],
		[LIBPCRE=-lpcre])

AC_SUBST(LIBPCRE)

AC_HEADER_SYS_WAIT

AC_LANG_CPLUSPLUS
AC_CHECK_HEADERS(vector vector.h)
AC_LANG_C

dnl Checks for typedefs, structures, and compiler characteristics.
AC_C_CONST
AC_TYPE_OFF_T
AC_TYPE_SIZE_T
AC_TYPE_UID_T
AC_STRUCT_TM
AC_SYS_LARGEFILE

dnl Checks for library functions.
AC_CHECK_HEADER(fam.h, :, :)
AC_CHECK_FUNCS(symlink readlink strcasecmp utime utimes)
AC_CHECK_LIB(fam, FAMOpen,  [
			LIBFAM=-lfam
			AC_DEFINE_UNQUOTED(HAVE_FAM,1,
			[ Whether libfam.a is available ])

			AC_CHECK_HEADER(fam.h, : , [
AC_MSG_WARN([[The development header files and libraries for fam,]])
AC_MSG_WARN([[the File Alteration Monitor, are not installed.]])
AC_MSG_WARN([[You appear to have the FAM runtime libraries installed,]])
AC_MSG_WARN([[so you need to simply install the additional development]])
AC_MSG_WARN([[package for your operating system.]])
AC_MSG_ERROR([[FAM development libraries not found.]]) ]
					)
		  ])

AC_SUBST(LIBFAM)

echo "$LIBFAM" >maildir.libdeps

AC_CACHE_CHECK([for missing gethostname prototype],maildir_cv_SYS_GETHOSTNAME,

AC_TRY_COMPILE([
#if HAVE_UNISTD_H
#include	<unistd.h>
#endif

extern "C" int gethostname(int,int);
],[
],maildir_cv_SYS_GETHOSTNAME=yes,maildir_cv_SYS_GETHOSTNAME=no
)

)

if test $maildir_cv_SYS_GETHOSTNAME = "no"
then
	AC_DEFINE_UNQUOTED(HAS_GETHOSTNAME,1,
	[ Whether gethostname() is prototyped ])
fi

AC_ARG_WITH(db, [  --with-db=gdbm          Use the GDBM library.
  --with-db=db            Use the libdb.a library.],
	db="$withval", db="")

if test "$db" = "no"
then
	db=""
fi

if test "$db" != ""
then
	AC_DEFINE_UNQUOTED(HAVE_DBOBJ,1,
	[ Whether the top-level configure script defined dbobj ])
fi

AC_ARG_WITH(trashquota, [  --with-trashquota       Count deleted messages as part of the quota],
	trashquota="$withval",
	trashquota="no")

if test "$trashquota" = "yes"
then
	AC_DEFINE_UNQUOTED(TRASHQUOTA,1,
	[ Whether to count deleted messages towards the maildir quota ])
fi

test "x$prefix" = xNONE && prefix=$ac_default_prefix
test "x$exec_prefix" = xNONE && exec_prefix='${prefix}'
eval "prefix=$prefix"
eval "exec_prefix=$exec_prefix"
eval "sysconfdir=$sysconfdir"

AC_PATH_PROGS(MAILBOT, mailbot, mailbot, $LPATH)

if test -d $srcdir/../courier
then
	MAILBOT="$bindir/mailbot"
	AC_DEFINE_UNQUOTED(HAVE_COURIER,1,
				[ Whether building the full Courier suite. ])
fi

AC_SUBST(MAILBOT)
AM_CONDITIONAL(HAVE_SGML, test -d ${srcdir}/../docbook)

if test "$target_os" = "cygwin"
then
	AC_DEFINE_UNQUOTED(MDIRSEP, "!",
	[ Maildir target separator ])
else
	AC_DEFINE_UNQUOTED(MDIRSEP, ":",
	[ Maildir target separator ])
fi

AC_OUTPUT(Makefile sharedindexinstall sharedindexsplit)
