From f07845fc2767373492f8ef12e8d80b9cdb3f7021 Mon Sep 17 00:00:00 2001
From: Stephan Bosch <stephan@rename-it.nl>
Date: Sat, 2 Jan 2010 13:39:38 +0100
Subject: [PATCH] Added support for fully compiling against installed Dovecot
 libraries.

---
 Makefile.am                                   |  9 --
 configure.in                                  | 82 +++++++++++++------
 src/Makefile.am                               | 10 ++-
 src/lib-sieve-tool/Makefile.am                | 10 +--
 src/lib-sieve/Makefile.am                     | 14 +---
 src/lib-sieve/plugins/body/Makefile.am        |  5 +-
 .../comparator-i-ascii-numeric/Makefile.am    |  5 +-
 src/lib-sieve/plugins/copy/Makefile.am        |  5 +-
 src/lib-sieve/plugins/date/Makefile.am        |  5 +-
 src/lib-sieve/plugins/enotify/Makefile.am     |  5 +-
 src/lib-sieve/plugins/environment/Makefile.am |  5 +-
 src/lib-sieve/plugins/include/Makefile.am     |  5 +-
 src/lib-sieve/plugins/mailbox/Makefile.am     |  5 +-
 src/lib-sieve/plugins/notify/Makefile.am      |  5 +-
 src/lib-sieve/plugins/regex/Makefile.am       |  5 +-
 src/lib-sieve/plugins/relational/Makefile.am  |  5 +-
 .../plugins/spamvirustest/Makefile.am         |  5 +-
 src/lib-sieve/plugins/subaddress/Makefile.am  |  5 +-
 src/lib-sieve/plugins/vacation/Makefile.am    |  5 +-
 src/lib-sieve/plugins/variables/Makefile.am   |  5 +-
 src/plugins/lda-sieve/Makefile.am             |  8 +-
 src/sieve-tools/Makefile.am                   | 16 +---
 src/testsuite/Makefile.am                     | 15 +---
 23 files changed, 86 insertions(+), 153 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 0ab9485d6..4bc6b4bd6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -100,18 +100,9 @@ test_cases = \
 	tests/deprecated/notify/execute.svtest \
 	tests/deprecated/notify/denotify.svtest
 
-if HAVE_DOVECOT_LIBS
-
 $(test_cases):
 	@$(TEST_BIN) $@
 
 .PHONY: $(test_cases)
 
 test: $(test_cases)
-
-else
-
-test:
-	@echo "Cannot compile or execute the testsuite without the Dovecot sources."
-
-endif	
diff --git a/configure.in b/configure.in
index fda744cb6..7581b47f0 100644
--- a/configure.in
+++ b/configure.in
@@ -41,15 +41,11 @@ fi
 
 if test -d "$dovecotdir/src"; then
   # compiling against sources
-  have_dovecot_libs=yes
+  have_dovecot_sources=yes
 else
   # compiling against installed headers
-  echo "WARNING: Cannot build Sieve commandline tools without the compiled"
-  echo "         Dovecot sources. Compiling against headers will only build"
-  echo "         the Sieve plugin." 
-  have_dovecot_libs=no
+  have_dovecot_sources=no
 fi
-AM_CONDITIONAL(HAVE_DOVECOT_LIBS, test "$have_dovecot_libs" = "yes")
 
 # Extensions under development
 #
@@ -83,16 +79,6 @@ AC_ARG_ENABLE(header-install,
     want_headers=no)
 AM_CONDITIONAL(INSTALL_HEADERS, test "$want_headers" = "yes")
 
-AC_ARG_ENABLE(header-install,
-[  --enable-header-install Install development headers],
-    if test x$enableval = xno; then
-        want_headers=no
-    else
-        want_headers=yes
-    fi,
-    want_headers=no)
-AM_CONDITIONAL(INSTALL_HEADERS, test "$want_headers" = "yes")
-
 AC_ARG_ENABLE(valgrind,
 [AC_HELP_STRING([--enable-valgrind], [Enable Valgrind memory leak checks in testsuite [default=no]])],
     if test x$enableval = xno || test x$enableval = xauto; then
@@ -106,29 +92,73 @@ AM_CONDITIONAL(TESTSUITE_VALGRIND, test "$want_valgrind" = "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
+if test $have_dovecot_sources = yes; then
   dovecot_incdir="$dovecotdir"
+  dovecot_libdir="$dovecotdir"
+
+  dovecot_pkgincludedir='$(includedir)/dovecot'
+  dovecot_pkglibdir='$(libdir)/dovecot'
+
+  LIBDOVECOT='$(dovecot_libdir)/src/lib-dovecot/libdovecot.la'
+  LIBDOVECOT_STORAGE='$(dovecot_libdir)/src/lib-storage/libdovecot-storage.la'
+
+  SIEVE_DOVECOT_INCLUDE=' \
+    -I$(dovecot_incdir) \
+    -I$(dovecot_incdir)/src/lib \
+    -I$(dovecot_incdir)/src/lib-mail \
+    -I$(dovecot_incdir)/src/lib-storage'
+
+  SIEVE_LIB_DOVECOT_INCLUDE=${SIEVE_DOVECOT_INCLUDE}' \
+    -I$(dovecot_incdir)/src/lib-imap \
+    -I$(dovecot_incdir)/src/lib-master'
+
+  SIEVE_LDA_DOVECOT_INCLUDE=${SIEVE_DOVECOT_INCLUDE}' \
+    -I$(dovecot_incdir)/src/lib-dict \
+    -I$(dovecot_incdir)/src/lib-lda \
+    -I$(dovecot_incdir)/src/lda'
+
+  SIEVE_TOOL_DOVECOT_INCLUDE=${SIEVE_DOVECOT_INCLUDE}' \
+    -I$(dovecot_incdir)/src/lib-settings \
+    -I$(dovecot_incdir)/src/lib-imap \
+    -I$(dovecot_incdir)/src/lib-index \
+    -I$(dovecot_incdir)/src/lib-master \
+    -I$(dovecot_incdir)/src/lib-storage/index \
+    -I$(dovecot_incdir)/src/lib-storage/index/raw'
+else
+  dovecot_libdir="$dovecotdir"
+  
+  dovecot_pkgincludedir='$(dovecot_incdir)'
+  dovecot_pkglibdir='$(dovecotdir)'
+
+  LIBDOVECOT='$(dovecot_libdir)/libdovecot.la'
+  LIBDOVECOT_STORAGE='$(dovecot_libdir)/libdovecot-storage.la'
+
+  SIEVE_DOVECOT_INCLUDE='-I$(dovecot_incdir)'
+  SIEVE_LIB_DOVECOT_INCLUDE=${SIEVE_DOVECOT_INCLUDE}
+  SIEVE_LDA_DOVECOT_INCLUDE=${SIEVE_DOVECOT_INCLUDE}
+  SIEVE_TOOL_DOVECOT_INCLUDE=${SIEVE_DOVECOT_INCLUDE}
 fi
 
-AC_SUBST(STORAGE_LIBS)
+dovecot_pkglibexecdir='$(libexecdir)/dovecot'
+dovecot_docdir='$(datadir)/doc/dovecot'
+
 AC_SUBST(LIBICONV)
 AC_SUBST(RAND_LIBS)
 AC_SUBST(MODULE_LIBS)
 AC_SUBST(dovecot_incdir)
+AC_SUBST(dovecot_libdir)
 AC_SUBST(moduledir)
-
-dovecot_pkgincludedir='$(includedir)/dovecot'
 AC_SUBST(dovecot_pkgincludedir)
-
-dovecot_pkglibexecdir='$(libexecdir)/dovecot'
-dovecot_pkglibdir='$(libdir)/dovecot'
-dovecot_pkgincludedir='$(includedir)/dovecot'
-dovecot_docdir='$(datadir)/doc/dovecot'
 AC_SUBST(dovecot_pkglibexecdir)
 AC_SUBST(dovecot_pkglibdir)
-AC_SUBST(dovecot_pkgincludedir)
 AC_SUBST(dovecot_docdir)
 
+AC_SUBST(LIBDOVECOT)
+AC_SUBST(LIBDOVECOT_STORAGE)
+AC_SUBST(SIEVE_LDA_DOVECOT_INCLUDE)
+AC_SUBST(SIEVE_LIB_DOVECOT_INCLUDE)
+AC_SUBST(SIEVE_TOOL_DOVECOT_INCLUDE)
+
 AC_CONFIG_FILES([
 Makefile
 doc/Makefile
diff --git a/src/Makefile.am b/src/Makefile.am
index 6389f2132..5e5dc42e4 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,6 +1,8 @@
-if HAVE_DOVECOT_LIBS
-LIB_DEPEND_DIRS=lib-sieve-tool sieve-tools testsuite
-endif
 
-SUBDIRS = lib-sieve plugins $(LIB_DEPEND_DIRS)
+SUBDIRS = \
+	lib-sieve \
+	plugins \
+	lib-sieve-tool \
+	sieve-tools \
+	testsuite
 
diff --git a/src/lib-sieve-tool/Makefile.am b/src/lib-sieve-tool/Makefile.am
index 575cffd6b..29ac0cb37 100644
--- a/src/lib-sieve-tool/Makefile.am
+++ b/src/lib-sieve-tool/Makefile.am
@@ -2,15 +2,7 @@ noinst_LTLIBRARIES = libsieve-tool.la
 
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib-sieve \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-master \
-	-I$(dovecot_incdir)/src/lib-settings \
-	-I$(dovecot_incdir)/src/lib-index \
-	-I$(dovecot_incdir)/src/lib-storage \
-	-I$(dovecot_incdir)/src/lib-storage/index \
-	-I$(dovecot_incdir)/src/lib-storage/index/raw
+	$(SIEVE_TOOL_DOVECOT_INCLUDE)
 
 libsieve_tool_la_SOURCES = \
 	sieve-tool.c \
diff --git a/src/lib-sieve/Makefile.am b/src/lib-sieve/Makefile.am
index 8d245ff11..6ef551aa1 100644
--- a/src/lib-sieve/Makefile.am
+++ b/src/lib-sieve/Makefile.am
@@ -3,12 +3,7 @@ SUBDIRS = plugins
 dovecot_pkglib_LTLIBRARIES = libdovecot-sieve.la
 
 AM_CPPFLAGS = \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage \
-	-I$(dovecot_incdir)/src/lib-imap \
-	-I$(dovecot_incdir)/src/lib-master \
+	$(SIEVE_LIB_DOVECOT_INCLUDE) \
 	-DMODULEDIR=\""$(moduledir)"\"
 
 tests = \
@@ -149,10 +144,3 @@ if INSTALL_HEADERS
 else
   noinst_HEADERS = $(headers)
 endif
-
-if INSTALL_HEADERS
-  pkginc_libdir=$(dovecot_pkgincludedir)/sieve
-  pkginc_lib_HEADERS = $(headers)
-else
-  noinst_HEADERS = $(headers)
-endif
diff --git a/src/lib-sieve/plugins/body/Makefile.am b/src/lib-sieve/plugins/body/Makefile.am
index b1bbfcf52..1739a0ca5 100644
--- a/src/lib-sieve/plugins/body/Makefile.am
+++ b/src/lib-sieve/plugins/body/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_body.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 tsts = \
 	tst-body.c
diff --git a/src/lib-sieve/plugins/comparator-i-ascii-numeric/Makefile.am b/src/lib-sieve/plugins/comparator-i-ascii-numeric/Makefile.am
index 7a55625e6..32510647f 100644
--- a/src/lib-sieve/plugins/comparator-i-ascii-numeric/Makefile.am
+++ b/src/lib-sieve/plugins/comparator-i-ascii-numeric/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_comparator-i-ascii-numeric.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 libsieve_ext_comparator_i_ascii_numeric_la_SOURCES = \
 	ext-cmp-i-ascii-numeric.c
diff --git a/src/lib-sieve/plugins/copy/Makefile.am b/src/lib-sieve/plugins/copy/Makefile.am
index a4a6bfa24..13c4bae68 100644
--- a/src/lib-sieve/plugins/copy/Makefile.am
+++ b/src/lib-sieve/plugins/copy/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_copy.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 libsieve_ext_copy_la_SOURCES = \
 	ext-copy.c
diff --git a/src/lib-sieve/plugins/date/Makefile.am b/src/lib-sieve/plugins/date/Makefile.am
index 3d761c3f4..c240558e8 100644
--- a/src/lib-sieve/plugins/date/Makefile.am
+++ b/src/lib-sieve/plugins/date/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_date.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 tests = \
 	tst-date.c
diff --git a/src/lib-sieve/plugins/enotify/Makefile.am b/src/lib-sieve/plugins/enotify/Makefile.am
index 36cdf0022..23e9857ad 100644
--- a/src/lib-sieve/plugins/enotify/Makefile.am
+++ b/src/lib-sieve/plugins/enotify/Makefile.am
@@ -3,10 +3,7 @@ noinst_LTLIBRARIES = libsieve_ext_enotify.la
 AM_CPPFLAGS = \
 	-I../../ \
 	-I../variables \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 commands = \
 	cmd-notify.c
diff --git a/src/lib-sieve/plugins/environment/Makefile.am b/src/lib-sieve/plugins/environment/Makefile.am
index e761fd12d..ddb90f313 100644
--- a/src/lib-sieve/plugins/environment/Makefile.am
+++ b/src/lib-sieve/plugins/environment/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_environment.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 tests = \
 	tst-environment.c
diff --git a/src/lib-sieve/plugins/include/Makefile.am b/src/lib-sieve/plugins/include/Makefile.am
index dc6f413a8..4955115cb 100644
--- a/src/lib-sieve/plugins/include/Makefile.am
+++ b/src/lib-sieve/plugins/include/Makefile.am
@@ -3,10 +3,7 @@ noinst_LTLIBRARIES = libsieve_ext_include.la
 AM_CPPFLAGS = \
 	-I../../ \
 	-I../variables \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 cmds = \
 	cmd-include.c \
diff --git a/src/lib-sieve/plugins/mailbox/Makefile.am b/src/lib-sieve/plugins/mailbox/Makefile.am
index 0f4813c85..b0d1f9ac7 100644
--- a/src/lib-sieve/plugins/mailbox/Makefile.am
+++ b/src/lib-sieve/plugins/mailbox/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_mailbox.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 tags = \
 	tag-mailbox-create.c
diff --git a/src/lib-sieve/plugins/notify/Makefile.am b/src/lib-sieve/plugins/notify/Makefile.am
index 2b4f711bd..0bde0ed4f 100644
--- a/src/lib-sieve/plugins/notify/Makefile.am
+++ b/src/lib-sieve/plugins/notify/Makefile.am
@@ -3,10 +3,7 @@ noinst_LTLIBRARIES = libsieve_ext_notify.la
 AM_CPPFLAGS = \
 	-I../../ \
 	-I../variables \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 commands = \
 	cmd-notify.c \
diff --git a/src/lib-sieve/plugins/regex/Makefile.am b/src/lib-sieve/plugins/regex/Makefile.am
index c7d8320c9..13f334b07 100644
--- a/src/lib-sieve/plugins/regex/Makefile.am
+++ b/src/lib-sieve/plugins/regex/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_regex.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 libsieve_ext_regex_la_SOURCES = \
 	mcht-regex.c \
diff --git a/src/lib-sieve/plugins/relational/Makefile.am b/src/lib-sieve/plugins/relational/Makefile.am
index 21a8e9094..c71837140 100644
--- a/src/lib-sieve/plugins/relational/Makefile.am
+++ b/src/lib-sieve/plugins/relational/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_relational.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 libsieve_ext_relational_la_SOURCES = \
 	ext-relational-common.c \
diff --git a/src/lib-sieve/plugins/spamvirustest/Makefile.am b/src/lib-sieve/plugins/spamvirustest/Makefile.am
index 30b6e20ba..9edb0d3fc 100644
--- a/src/lib-sieve/plugins/spamvirustest/Makefile.am
+++ b/src/lib-sieve/plugins/spamvirustest/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_spamvirustest.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 tests = \
 	tst-spamvirustest.c
diff --git a/src/lib-sieve/plugins/subaddress/Makefile.am b/src/lib-sieve/plugins/subaddress/Makefile.am
index 26122999a..5f2970237 100644
--- a/src/lib-sieve/plugins/subaddress/Makefile.am
+++ b/src/lib-sieve/plugins/subaddress/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_subaddress.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 libsieve_ext_subaddress_la_SOURCES = \
 	ext-subaddress.c
diff --git a/src/lib-sieve/plugins/vacation/Makefile.am b/src/lib-sieve/plugins/vacation/Makefile.am
index 1e59ef1ea..95c7cf1d6 100644
--- a/src/lib-sieve/plugins/vacation/Makefile.am
+++ b/src/lib-sieve/plugins/vacation/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_vacation.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 cmds = \
 	cmd-vacation.c
diff --git a/src/lib-sieve/plugins/variables/Makefile.am b/src/lib-sieve/plugins/variables/Makefile.am
index f8fa7cf40..dd0e64e5c 100644
--- a/src/lib-sieve/plugins/variables/Makefile.am
+++ b/src/lib-sieve/plugins/variables/Makefile.am
@@ -2,10 +2,7 @@ noinst_LTLIBRARIES = libsieve_ext_variables.la
 
 AM_CPPFLAGS = \
 	-I../../ \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage 
+	$(SIEVE_LIB_DOVECOT_INCLUDE)
 
 cmds = \
 	cmd-set.c
diff --git a/src/plugins/lda-sieve/Makefile.am b/src/plugins/lda-sieve/Makefile.am
index 616dc56af..9009ddd76 100644
--- a/src/plugins/lda-sieve/Makefile.am
+++ b/src/plugins/lda-sieve/Makefile.am
@@ -1,12 +1,6 @@
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib-sieve \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-dict \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-storage \
-	-I$(dovecot_incdir)/src/lib-lda \
-	-I$(dovecot_incdir)/src/lda
+	$(SIEVE_LDA_DOVECOT_INCLUDE)
 
 lib90_sieve_plugin_la_LDFLAGS = -module -avoid-version
 
diff --git a/src/sieve-tools/Makefile.am b/src/sieve-tools/Makefile.am
index ec35660db..3b2e674f8 100644
--- a/src/sieve-tools/Makefile.am
+++ b/src/sieve-tools/Makefile.am
@@ -10,25 +10,15 @@ AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib-sieve \
 	-I$(top_srcdir)/src/lib-sieve-tool \
 	-I./debug \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-settings \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-imap \
-	-I$(dovecot_incdir)/src/lib-index \
-	-I$(dovecot_incdir)/src/lib-master \
-	-I$(dovecot_incdir)/src/lib-storage \
-	-I$(dovecot_incdir)/src/lib-storage/index \
-	-I$(dovecot_incdir)/src/lib-storage/index/raw
+	$(SIEVE_TOOL_DOVECOT_INCLUDE) 
 
 libs = \
 	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la \
 	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la \
-	$(dovecot_incdir)/src/lib-storage/libdovecot-storage.la \
-	$(dovecot_incdir)/src/lib-dovecot/libdovecot.la \
+	$(LIBDOVECOT_STORAGE) \
+	$(LIBDOVECOT) \
 	./debug/libsieve_ext_debug.la
 
-
 # Sieve Compile Tool
 
 sievec_LDFLAGS = -export-dynamic
diff --git a/src/testsuite/Makefile.am b/src/testsuite/Makefile.am
index 56cd7ea7b..e69e6dbbf 100644
--- a/src/testsuite/Makefile.am
+++ b/src/testsuite/Makefile.am
@@ -3,24 +3,15 @@ noinst_PROGRAMS = testsuite
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib-sieve \
 	-I$(top_srcdir)/src/lib-sieve-tool \
-	-I$(dovecot_incdir) \
-	-I$(dovecot_incdir)/src/lib \
-	-I$(dovecot_incdir)/src/lib-settings \
-	-I$(dovecot_incdir)/src/lib-mail \
-	-I$(dovecot_incdir)/src/lib-imap \
-	-I$(dovecot_incdir)/src/lib-index \
-	-I$(dovecot_incdir)/src/lib-master \
-	-I$(dovecot_incdir)/src/lib-storage \
-	-I$(dovecot_incdir)/src/lib-storage/index \
-	-I$(dovecot_incdir)/src/lib-storage/index/raw
+	$(SIEVE_TOOL_DOVECOT_INCLUDE)
 
 testsuite_LDFLAGS = -export-dynamic
 
 libs = \
 	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la \
 	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la \
-	$(dovecot_incdir)/src/lib-storage/libdovecot-storage.la \
-	$(dovecot_incdir)/src/lib-dovecot/libdovecot.la
+	$(LIBDOVECOT) \
+	$(LIBDOVECOT_STORAGE)
 
 testsuite_LDADD = $(libs)
 testsuite_DEPENDENCIES = $(libs)
-- 
GitLab