diff --git a/Makefile.am b/Makefile.am
index 0ab9485d60f71683c28ebdffa9e891e23d2c4fa4..4bc6b4bd66452ab52ed7d62d79794b859c56af58 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 fda744cb6de71b5004fc431b28e0aebcd0e79d0a..7581b47f0e9f19b7e56f743cee6b345fa1ea0b40 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 6389f2132a228b4f511bbde4387ee2fc0ed1bac5..5e5dc42e4401c29b88d8419b513c98836a067aa9 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 575cffd6b4092c41b858d899601a8f349c4d8891..29ac0cb3785e8cd841856112193b76f6d84c859e 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 8d245ff11fc7757467037b78f483c5b56adedd66..6ef551aa1116e28cf155421ca06e87eb1e62393e 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 b1bbfcf527ebd12de8cbd93b79ebe4374446b92d..1739a0ca51ce956fa8f8c0fd9cd2ac836385715e 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 7a55625e6f1d63a07ffa68292cf01f455e03a1f9..32510647f8adde2559a285c4d4b6b7c92a83b025 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 a4a6bfa24bd86144fa2d31883befae793c4bef10..13c4bae68f60a1fe6eb4e5fd92d32f573b0654b8 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 3d761c3f4ba2da2a455d04bf52cb3b7872b9890a..c240558e8a67e26fd78c1fb8a7311df12166df15 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 36cdf00222def3ce8d7547641970d91a578eebc9..23e9857ad5e77e5dd284ac21053167337a10d0f6 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 e761fd12dad7b7c4f4812ad4c67991cab0fb574b..ddb90f313432319c194b9e4fb00d23ca03c04b7b 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 dc6f413a8e99f8e151e1851112b30521ee074f43..4955115cbad45e43e9d2bdbbac42e91ef5c9f067 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 0f4813c85ec4fb96235c183bc5f56610811f0f50..b0d1f9ac7e43c84041bef5284f7a1c2d4e83bde4 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 2b4f711bd6583a438fdb8ffff0614b389fe3f3bf..0bde0ed4fd99e0fbd911a294f0140b36ded19606 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 c7d8320c9a85409799ace14944a0335d80f8d09f..13f334b0779b2de80c9ec845a21202fcdff8ecd0 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 21a8e9094078d9ca4308650bfb0e4d2837a70807..c7183714031b3cd808a4f4684bb22c6be7d50d67 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 30b6e20bafcf763e5b6df68eb4c7721d7b4d124f..9edb0d3fcc91fd250c60dfe35490e37887386617 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 26122999aaacce98e283491a6bd379f591982f81..5f29702370ab65e21ebdce8e77f9603bd5f941ad 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 1e59ef1ead9f37bebbf4af0f2a7f901dc7063d83..95c7cf1d6f0bd1e3f9b7851a7c7f83313668e137 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 f8fa7cf409035d7331c20f0bd392ccc5500712a3..dd0e64e5c8ef506e774d6b97f8069b49e7ce7d2e 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 616dc56afc90c21557e65077dee2749f42952756..9009ddd76b4250767e00d9ed5b74bb77d7c7baa4 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 ec35660dbc3d122f1974369e6d0482be4001d143..3b2e674f89147896dbe288b85b245f771b8cf3d7 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 56cd7ea7b856cee669d7e25b52ba919124e8d688..e69e6dbbf901ec73b9fb9734b3b055d93d66437b 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)