diff --git a/Makefile.am b/Makefile.am
index f8fea5ac31dbcc184af96f582ae2b68a08041f80..c6800cbdb4aa5b127b7ef6b1e3c737e4ce708c63 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,4 +1,8 @@
-SUBDIRS = src doc
+if BUILD_DOCS
+DOCS = doc
+endif
+
+SUBDIRS = src $(DOCS)
 
 ACLOCAL_AMFLAGS = -I m4 --install
 
diff --git a/configure.in b/configure.in
index 71c9c613ec7f579ac037b1b72327c3c8233910cc..34619d79cbf9a4f7f159424d20b542fe97907476 100644
--- a/configure.in
+++ b/configure.in
@@ -21,10 +21,19 @@ AC_PROG_CC
 AC_PROG_CPP
 AC_PROG_LIBTOOL
 
+# Couple with Dovecot
+#
+
 DC_DOVECOT
 LIBDOVECOT_INCLUDE="$LIBDOVECOT_INCLUDE $LIBDOVECOT_STORAGE_INCLUDE" 
 AC_SUBST(LIBDOVECOT_INCLUDE)
 
+# Defome Sieve documentation install dir
+#
+
+sieve_docdir='${dovecot_docdir}/sieve'
+AC_SUBST(sieve_docdir)
+
 # Extensions under development
 #
 
@@ -57,6 +66,16 @@ AC_ARG_ENABLE(header-install,
     want_headers=no)
 AM_CONDITIONAL(INSTALL_HEADERS, test "$want_headers" = "yes")
 
+AC_ARG_WITH(docs,
+[  --with-docs             Install documentation (default)],
+    if test x$withval = xno; then
+        want_docs=no
+    else
+        want_docs=yes
+    fi,
+    want_docs=yes)
+AM_CONDITIONAL(BUILD_DOCS, test "$want_docs" = "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
diff --git a/doc/Makefile.am b/doc/Makefile.am
index 48f90c36ce926c0d1a6b6eb6a51cf3c5bce545e5..7c673e627bef6f66040ef1ee798be20f7a868d96 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -1,7 +1,13 @@
 SUBDIRS = man example-config
 
+docfiles = spamtest-virustest.txt
+
+if BUILD_DOCS
+sieve_doc_DATA = $(docfiles)
+endif
+
 EXTRA_DIST = \
 	rfc \
 	devel \
-	spamtest-virustest.txt
+	$(docfiles)