diff --git a/Makefile.am b/Makefile.am
index b2d59e73eb83a2c99a1f6af8a120cee338c562fe..fc1f3913f6801459ff9f73cfeef2b6f08742f46a 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -24,7 +24,7 @@ endif
 
 # Testsuite tests
 
-TESTSUITE_BIN = $(top_srcdir)/src/testsuite/testsuite
+TESTSUITE_BIN = $(top_builddir)/src/testsuite/testsuite
 
 if TESTSUITE_VALGRIND
 TEST_BIN = valgrind -q --error-exitcode=1 --show-reachable=yes --leak-check=full $(TESTSUITE_BIN) 
@@ -128,8 +128,10 @@ test_cases = \
 	$(test_unfinished)
 
 $(test_cases):
-	@$(TEST_BIN) $@
+	@$(TEST_BIN) $(top_srcdir)/$@
 
 .PHONY: $(test_cases)
 
 test: $(test_cases)
+
+check: check-am test all-am
diff --git a/configure.in b/configure.in
index c970bc78d7d3885f234bc277ea545a79927bdf71..6859b7afdbbf79289792320dcc90daf9e622496a 100644
--- a/configure.in
+++ b/configure.in
@@ -31,7 +31,7 @@ CFLAGS="$DOVECOT_CFLAGS"
 LIBS="$DOVECOT_LIBS"
 AC_SUBST(LIBDOVECOT_INCLUDE)
 
-# Defome Sieve documentation install dir
+# Define Sieve documentation install dir
 #
 
 sieve_docdir='${dovecot_docdir}/sieve'
diff --git a/src/lib-sieve/Makefile.am b/src/lib-sieve/Makefile.am
index 6aca9080c7732b68392c9f1606c344db8a0f3b96..21336e1be421319e402c7a1394707e3b1bd56d7d 100644
--- a/src/lib-sieve/Makefile.am
+++ b/src/lib-sieve/Makefile.am
@@ -45,23 +45,24 @@ unfinished_plugins =
 endif
 
 # These are not actual plugins just yet...
+extdir = $(builddir)/plugins
 plugins = \
-	./plugins/vacation/libsieve_ext_vacation.la \
-	./plugins/subaddress/libsieve_ext_subaddress.la \
- 	./plugins/comparator-i-ascii-numeric/libsieve_ext_comparator-i-ascii-numeric.la \
-	./plugins/relational/libsieve_ext_relational.la \
-	./plugins/regex/libsieve_ext_regex.la \
-	./plugins/copy/libsieve_ext_copy.la \
-	./plugins/imap4flags/libsieve_ext_imap4flags.la \
-	./plugins/include/libsieve_ext_include.la \
-	./plugins/body/libsieve_ext_body.la \
-	./plugins/variables/libsieve_ext_variables.la \
-	./plugins/enotify/libsieve_ext_enotify.la \
-	./plugins/notify/libsieve_ext_notify.la \
-	./plugins/environment/libsieve_ext_environment.la \
-	./plugins/mailbox/libsieve_ext_mailbox.la \
-	./plugins/date/libsieve_ext_date.la \
-	./plugins/spamvirustest/libsieve_ext_spamvirustest.la \
+	$(extdir)/vacation/libsieve_ext_vacation.la \
+	$(extdir)/subaddress/libsieve_ext_subaddress.la \
+ 	$(extdir)/comparator-i-ascii-numeric/libsieve_ext_comparator-i-ascii-numeric.la \
+	$(extdir)/relational/libsieve_ext_relational.la \
+	$(extdir)/regex/libsieve_ext_regex.la \
+	$(extdir)/copy/libsieve_ext_copy.la \
+	$(extdir)/imap4flags/libsieve_ext_imap4flags.la \
+	$(extdir)/include/libsieve_ext_include.la \
+	$(extdir)/body/libsieve_ext_body.la \
+	$(extdir)/variables/libsieve_ext_variables.la \
+	$(extdir)/enotify/libsieve_ext_enotify.la \
+	$(extdir)/notify/libsieve_ext_notify.la \
+	$(extdir)/environment/libsieve_ext_environment.la \
+	$(extdir)/mailbox/libsieve_ext_mailbox.la \
+	$(extdir)/date/libsieve_ext_date.la \
+	$(extdir)/spamvirustest/libsieve_ext_spamvirustest.la \
 	$(unfinished_plugins)
 
 libdovecot_sieve_la_DEPENDENCIES = $(plugins)
diff --git a/src/lib-sieve/plugins/body/Makefile.am b/src/lib-sieve/plugins/body/Makefile.am
index 9074541a680a5b5961ea34f74dad6c354f2bfd7e..251b8d69bafc4148f52b66bf042dc6168f916ea1 100644
--- a/src/lib-sieve/plugins/body/Makefile.am
+++ b/src/lib-sieve/plugins/body/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_body.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 tsts = \
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 c0b1626a247b01173300e8209850c1179a116d4c..8e385c5cfd679385576cce162277656224830548 100644
--- a/src/lib-sieve/plugins/comparator-i-ascii-numeric/Makefile.am
+++ b/src/lib-sieve/plugins/comparator-i-ascii-numeric/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_comparator-i-ascii-numeric.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 libsieve_ext_comparator_i_ascii_numeric_la_SOURCES = \
diff --git a/src/lib-sieve/plugins/copy/Makefile.am b/src/lib-sieve/plugins/copy/Makefile.am
index fb5d118398d3b2e428527fb70562526f6bfac196..d2220d70a8b6e03fab9a9a881bff1ee2961fb0d8 100644
--- a/src/lib-sieve/plugins/copy/Makefile.am
+++ b/src/lib-sieve/plugins/copy/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_copy.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 libsieve_ext_copy_la_SOURCES = \
diff --git a/src/lib-sieve/plugins/date/Makefile.am b/src/lib-sieve/plugins/date/Makefile.am
index 5e959a1671b5514bdf6b118a89ee2e67ea94bd59..bf257accaecf0dd723395e68113c355e0fcf1c91 100644
--- a/src/lib-sieve/plugins/date/Makefile.am
+++ b/src/lib-sieve/plugins/date/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_date.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 tests = \
diff --git a/src/lib-sieve/plugins/enotify/Makefile.am b/src/lib-sieve/plugins/enotify/Makefile.am
index 648fe6be1100e6e3eeef79169d8396eb7061718e..a3fc8acef9307e834515e6908369ab547cb43bf7 100644
--- a/src/lib-sieve/plugins/enotify/Makefile.am
+++ b/src/lib-sieve/plugins/enotify/Makefile.am
@@ -3,8 +3,8 @@ SUBDIRS = mailto
 noinst_LTLIBRARIES = libsieve_ext_enotify.la
 
 AM_CPPFLAGS = \
-	-I../../ \
-	-I../variables \
+	-I$(srcdir)/../.. \
+	-I$(srcdir)/../variables \
 	$(LIBDOVECOT_INCLUDE)
 
 commands = \
diff --git a/src/lib-sieve/plugins/enotify/mailto/Makefile.am b/src/lib-sieve/plugins/enotify/mailto/Makefile.am
index 80b04ab9ced2f37ecbaa231f2a663d3545a9774b..06b926293c8713e9469abb103a157836fa2c8e2f 100644
--- a/src/lib-sieve/plugins/enotify/mailto/Makefile.am
+++ b/src/lib-sieve/plugins/enotify/mailto/Makefile.am
@@ -1,8 +1,8 @@
 noinst_LTLIBRARIES = libsieve_ext_enotify_mailto.la
 
 AM_CPPFLAGS = \
-	-I../ \
-	-I../../../ \
+	-I$(srcdir)/.. \
+	-I$(srcdir)/../../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 libsieve_ext_enotify_mailto_la_SOURCES = \
diff --git a/src/lib-sieve/plugins/environment/Makefile.am b/src/lib-sieve/plugins/environment/Makefile.am
index 2dbe522de6bd74129b37aa2acc42c9990fb9ce7b..a19012863397ada732a89ecf4c4e4f89342fe3b5 100644
--- a/src/lib-sieve/plugins/environment/Makefile.am
+++ b/src/lib-sieve/plugins/environment/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_environment.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 tests = \
diff --git a/src/lib-sieve/plugins/imap4flags/Makefile.am b/src/lib-sieve/plugins/imap4flags/Makefile.am
index 867ec831f2de7469428cf5272cdd6bd237e0734b..c9c099811ff9f1d73f8dff2d9c7afe50d290a06d 100644
--- a/src/lib-sieve/plugins/imap4flags/Makefile.am
+++ b/src/lib-sieve/plugins/imap4flags/Makefile.am
@@ -1,8 +1,8 @@
 noinst_LTLIBRARIES = libsieve_ext_imap4flags.la
 
 AM_CPPFLAGS = \
-	-I../../ \
-    -I../variables \
+	-I$(srcdir)/../.. \
+	-I$(srcdir)/../variables  \
 	$(LIBDOVECOT_INCLUDE)
 
 commands = \
diff --git a/src/lib-sieve/plugins/include/Makefile.am b/src/lib-sieve/plugins/include/Makefile.am
index 9d0f164e5e0263645f401aaf7854fa812bddae34..5ce1599be0faeac008f980c66edf9a7ea4bce7b9 100644
--- a/src/lib-sieve/plugins/include/Makefile.am
+++ b/src/lib-sieve/plugins/include/Makefile.am
@@ -1,8 +1,8 @@
 noinst_LTLIBRARIES = libsieve_ext_include.la
 
 AM_CPPFLAGS = \
-	-I../../ \
-	-I../variables \
+	-I$(srcdir)/../.. \
+	-I$(srcdir)/../variables \
 	$(LIBDOVECOT_INCLUDE)
 
 cmds = \
diff --git a/src/lib-sieve/plugins/mailbox/Makefile.am b/src/lib-sieve/plugins/mailbox/Makefile.am
index 79739dba310804dd15c940be781731323de2263d..95dcf00b768a3de2eb47d23fee64bc3475012a43 100644
--- a/src/lib-sieve/plugins/mailbox/Makefile.am
+++ b/src/lib-sieve/plugins/mailbox/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_mailbox.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 tags = \
diff --git a/src/lib-sieve/plugins/notify/Makefile.am b/src/lib-sieve/plugins/notify/Makefile.am
index bb343ebf3eb0f514be2cefa2830b588fe804f6c8..b5165b9c58aa875a652071113443b74fd2cf0ce8 100644
--- a/src/lib-sieve/plugins/notify/Makefile.am
+++ b/src/lib-sieve/plugins/notify/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_notify.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 commands = \
diff --git a/src/lib-sieve/plugins/regex/Makefile.am b/src/lib-sieve/plugins/regex/Makefile.am
index 9cc7ef16ad7d60a3e3bd24d5b86707d788e8bc81..eeb735ef31b6a502583ad32045f1e4a07c4d66c4 100644
--- a/src/lib-sieve/plugins/regex/Makefile.am
+++ b/src/lib-sieve/plugins/regex/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_regex.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 libsieve_ext_regex_la_SOURCES = \
diff --git a/src/lib-sieve/plugins/relational/Makefile.am b/src/lib-sieve/plugins/relational/Makefile.am
index 59a1770090ed3c85afc0ddba098312a519509f6d..69f8d5a94d850efe61ac268de09b9f4d8047e6f2 100644
--- a/src/lib-sieve/plugins/relational/Makefile.am
+++ b/src/lib-sieve/plugins/relational/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_relational.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 libsieve_ext_relational_la_SOURCES = \
diff --git a/src/lib-sieve/plugins/spamvirustest/Makefile.am b/src/lib-sieve/plugins/spamvirustest/Makefile.am
index 3117517f31c4f7550a3ca18eff1ca81b5824a0fa..6a15bdd148d53cceea365ed8c6b58c6d2d2d5cc6 100644
--- a/src/lib-sieve/plugins/spamvirustest/Makefile.am
+++ b/src/lib-sieve/plugins/spamvirustest/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_spamvirustest.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 tests = \
diff --git a/src/lib-sieve/plugins/subaddress/Makefile.am b/src/lib-sieve/plugins/subaddress/Makefile.am
index 49fcf718dee622b5e12bd2c820c359a6c32f39ea..02386f290d91e6779af8a274a4eb31cdbb70de8b 100644
--- a/src/lib-sieve/plugins/subaddress/Makefile.am
+++ b/src/lib-sieve/plugins/subaddress/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_subaddress.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../../ \
 	$(LIBDOVECOT_INCLUDE)
 
 libsieve_ext_subaddress_la_SOURCES = \
diff --git a/src/lib-sieve/plugins/vacation/Makefile.am b/src/lib-sieve/plugins/vacation/Makefile.am
index 40639eff23ef6e4e0a82eb2676d75ddf06d726b2..d516af5606d220b80fb77ec9cee30386cb440c24 100644
--- a/src/lib-sieve/plugins/vacation/Makefile.am
+++ b/src/lib-sieve/plugins/vacation/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_vacation.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../../ \
 	$(LIBDOVECOT_INCLUDE)
 
 cmds = \
diff --git a/src/lib-sieve/plugins/variables/Makefile.am b/src/lib-sieve/plugins/variables/Makefile.am
index f3d456420ee86e5acf49bb79a90e234a0cbf68e9..bb9e44efd1c4bcb8de450de90725453c70ea6432 100644
--- a/src/lib-sieve/plugins/variables/Makefile.am
+++ b/src/lib-sieve/plugins/variables/Makefile.am
@@ -1,7 +1,7 @@
 noinst_LTLIBRARIES = libsieve_ext_variables.la
 
 AM_CPPFLAGS = \
-	-I../../ \
+	-I$(srcdir)/../.. \
 	$(LIBDOVECOT_INCLUDE)
 
 cmds = \
diff --git a/src/managesieve-login/Makefile.am b/src/managesieve-login/Makefile.am
index 84652eace275efdf7d4c4d4801585306b49fa8f9..b0ef65d58a4cb6e11abae250be889eee6b2faf8e 100644
--- a/src/managesieve-login/Makefile.am
+++ b/src/managesieve-login/Makefile.am
@@ -22,7 +22,7 @@ libmanagesieve_login_settings_la_CFLAGS = \
 	$(AM_CFLAGS) $(LIBDOVECOT_CONFIG_INCLUDE) -DPKG_LIBEXECDIR=\""$(dovecot_pkglibexecdir)"\"
 
 libs = \
-	$(top_srcdir)/src/lib-managesieve/libmanagesieve.a
+	$(top_builddir)/src/lib-managesieve/libmanagesieve.a
 
 managesieve_login_LDADD = $(libs) $(LIBDOVECOT_LOGIN) $(LIBDOVECOT)
 managesieve_login_DEPENDENCIES = $(libs) $(LIBDOVECOT_LOGIN_DEPS) $(LIBDOVECOT_DEPS)
diff --git a/src/managesieve/Makefile.am b/src/managesieve/Makefile.am
index 972e544e26d329037eff798577f6011211dbaaf0..28b758ecfbbe7fa1bc28537fdd4e4c072943425e 100644
--- a/src/managesieve/Makefile.am
+++ b/src/managesieve/Makefile.am
@@ -23,9 +23,9 @@ managesieve_LDFLAGS = -export-dynamic
 
 libs = \
 	managesieve-settings.lo \
-	$(top_srcdir)/src/lib-managesieve/libmanagesieve.a \
-	$(top_srcdir)/src/lib-sievestorage/libsievestorage.a \
-	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la
+	$(top_builddir)/src/lib-managesieve/libmanagesieve.a \
+	$(top_builddir)/src/lib-sievestorage/libsievestorage.a \
+	$(top_builddir)/src/lib-sieve/libdovecot-sieve.la
 
 managesieve_LDADD = $(libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT_LDA) $(LIBDOVECOT)
 
diff --git a/src/plugins/lda-sieve/Makefile.am b/src/plugins/lda-sieve/Makefile.am
index 5f8c23ff038b7ec808fa00ff78f33e2a5531c164..9994a64de05055eb8747cd9b28a89f9b024ce6cd 100644
--- a/src/plugins/lda-sieve/Makefile.am
+++ b/src/plugins/lda-sieve/Makefile.am
@@ -9,7 +9,7 @@ lib90_sieve_plugin_la_LDFLAGS = -module -avoid-version
 dovecot_module_LTLIBRARIES = lib90_sieve_plugin.la
 
 lib90_sieve_plugin_la_LIBADD = \
-	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la
+	$(top_builddir)/src/lib-sieve/libdovecot-sieve.la
 
 lib90_sieve_plugin_la_SOURCES = \
 	lda-sieve-log.c \
diff --git a/src/sieve-tools/Makefile.am b/src/sieve-tools/Makefile.am
index 7c204f2c595ddbafe527683f623929c32f28759a..5ce234292f348dc257aa1a480d74d5b62a92d8c4 100644
--- a/src/sieve-tools/Makefile.am
+++ b/src/sieve-tools/Makefile.am
@@ -9,14 +9,14 @@ endif
 AM_CPPFLAGS = \
 	-I$(top_srcdir)/src/lib-sieve \
 	-I$(top_srcdir)/src/lib-sieve-tool \
-	-I./debug \
+	-I$(srcdir)/debug \
 	$(LIBDOVECOT_INCLUDE) \
 	$(LIBDOVECOT_SERVICE_INCLUDE)
 
 libs = \
-	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la \
-	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la \
-	./debug/libsieve_ext_debug.la
+	$(top_builddir)/src/lib-sieve/libdovecot-sieve.la \
+	$(top_builddir)/src/lib-sieve-tool/libsieve-tool.la \
+	$(builddir)/debug/libsieve_ext_debug.la
 
 libs_ldadd = $(libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT_LDA) $(LIBDOVECOT)
 libs_deps = $(libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_LDA_DEPS) $(LIBDOVECOT_DEPS)
diff --git a/src/testsuite/Makefile.am b/src/testsuite/Makefile.am
index d9c693f91ca26f9d8ce26de41bfdb4a69cbcdd19..a57771cfa0262971815aa030002b08221265c6b9 100644
--- a/src/testsuite/Makefile.am
+++ b/src/testsuite/Makefile.am
@@ -9,8 +9,8 @@ AM_CPPFLAGS = \
 testsuite_LDFLAGS = -export-dynamic
 
 libs = \
-	$(top_srcdir)/src/lib-sieve/libdovecot-sieve.la \
-	$(top_srcdir)/src/lib-sieve-tool/libsieve-tool.la
+	$(top_builddir)/src/lib-sieve/libdovecot-sieve.la \
+	$(top_builddir)/src/lib-sieve-tool/libsieve-tool.la
 
 testsuite_LDADD = $(libs) $(LIBDOVECOT_STORAGE) $(LIBDOVECOT_LDA) $(LIBDOVECOT)
 testsuite_DEPENDENCIES = $(libs) $(LIBDOVECOT_STORAGE_DEPS) $(LIBDOVECOT_LDA_DEPS) $(LIBDOVECOT_DEPS)