diff --git a/Makefile.am b/Makefile.am
index b0bf1071a4834d95a673e06048bd4819abd90bae..a3ae4056106962a9d0f1027e2a1c139595da1505 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -1,2 +1,2 @@
 ACLOCAL_AMFLAGS = -I m4
-SUBDIRS = src samples @DOC@
+SUBDIRS = src samples doc
diff --git a/configure.ac b/configure.ac
index e6ee1d875461c9a8ba3f39dba228eaf67ffacccc..630835e2dbb07fdc5305c1eac14bae4849fbe4fc 100644
--- a/configure.ac
+++ b/configure.ac
@@ -57,7 +57,7 @@ XMLTO=
 AS_IF([test "x$with_documentation" != "xno"],
     [AC_CHECK_PROG([XMLTO], [xmlto], [xmlto],
         [AC_MSG_ERROR([xmlto needed for building the documentation])])
-     AC_SUBST([DOC], [doc])
+     AM_CONDITIONAL([build_documentation], [test "x$XMLTO" != "x"])
     ])
 
 AC_PROG_YACC
diff --git a/doc/Makefile.am b/doc/Makefile.am
index b7c4c0635c6e56313171bf5ba0db95535cdef0a5..942455da4432bdbd60cb321fd3d4a1459f5aa22e 100644
--- a/doc/Makefile.am
+++ b/doc/Makefile.am
@@ -10,8 +10,12 @@ XML_SOURCES=configuration.xml \
 	    security.xml \
 	    troubleshooting.xml
 
+if build_documentation
+
 htmldir = $(prefix)/share/doc/@PACKAGE@
 dist_html_DATA = @PACKAGE@.html
 
 @PACKAGE@.html: @PACKAGE@.xml $(XML_SOURCES)
 	$(XMLTO) $(XMLTO_FLAGS) html-nochunks @PACKAGE@.xml
+
+fi