AC_INIT([Dovecot Sieve], [0.1.0], [dovecot@dovecot.org], [dovecot-1.2-sieve])
AC_CONFIG_SRCDIR([src])

AC_CONFIG_HEADERS([dsieve-config.h])
AM_INIT_AUTOMAKE

AM_MAINTAINER_MODE

AC_PROG_CC
AC_PROG_CPP
AM_PROG_LIBTOOL

AC_ARG_WITH(dovecot,
[AC_HELP_STRING([--with-dovecot=DIR], [Dovecot base directory [../dovecot]])],
	dovecotdir="$withval",
	dovecotdir=../dovecot
)
old=`pwd`
cd $dovecotdir
dovecotdir=`pwd`
cd $old
AC_SUBST(dovecotdir)

if ! test -f "$dovecotdir/dovecot-config"; then
  echo
  echo "dovecot-config not found from $dovecotdir, use --with-dovecot=PATH"
  echo "to give path to compiled Dovecot sources or to a directory with the"
  echo "installed dovecot-config file."
  AC_MSG_ERROR([dovecot-config not found])
fi

if test -d "$dovecotdir/src"; then
  # compiling against sources
  have_dovecot_libs=yes
else
  # compiling against installed headers
  echo 
  echo "Cannot compile against the installed headers only."
  AC_MSG_ERROR([dovecot-source not found]);
fi
AM_CONDITIONAL(HAVE_DOVECOT_LIBS, test "$have_dovecot_libs" = "yes")

# Extensions under development
#

AC_ARG_WITH(enotify,
[AC_HELP_STRING([--with-enotify], [Build enotify extension (under development) [default=no]])],
        if test x$withval = xno || test x$withval = xauto; then
                want_enotify=$withval
        else
                want_enotify=yes
        fi,
        want_enotify=no)
AM_CONDITIONAL(BUILD_ENOTIFY, test "$want_enotify" = "yes")

#
#

dnl replace relative ../ paths in the file with full paths
eval `cat $dovecotdir/dovecot-config|sed 's,\$(top_builddir)/,$dovecotdir/,g'`

if test $have_dovecot_libs = yes; then
  dovecot_incdir="$dovecotdir"
fi

AC_SUBST(STORAGE_LIBS)
AC_SUBST(LIBICONV)
AC_SUBST(RAND_LIBS)
AC_SUBST(MODULE_LIBS)
AC_SUBST(dovecot_incdir)
AC_SUBST(moduledir)

AC_CONFIG_FILES([
Makefile
src/Makefile
src/lib-sieve/Makefile
src/lib-sieve/plugins/Makefile
src/lib-sieve/plugins/vacation/Makefile
src/lib-sieve/plugins/subaddress/Makefile
src/lib-sieve/plugins/comparator-i-ascii-numeric/Makefile
src/lib-sieve/plugins/relational/Makefile
src/lib-sieve/plugins/regex/Makefile
src/lib-sieve/plugins/imapflags/Makefile
src/lib-sieve/plugins/copy/Makefile
src/lib-sieve/plugins/include/Makefile
src/lib-sieve/plugins/body/Makefile
src/lib-sieve/plugins/variables/Makefile
src/lib-sieve/plugins/enotify/Makefile
src/lib-util/Makefile
src/plugins/Makefile
src/plugins/lda-sieve/Makefile
src/sieve-bin/Makefile
src/testsuite/Makefile
stamp.h])

AC_OUTPUT

echo "NOTE: This is the UNSTABLE development branch."
