diff --git a/Makefile.am b/Makefile.am
index 94063d48eb584d54a3b1fc9936f241e08ac19063..e8a55995c38e4bc2a08ac7a1c92f2745991209ad 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -228,24 +228,24 @@ man/%.in: man/%.sgml stamp-directories $(REPLACE_VARS_SED)
 	sed -f $(REPLACE_VARS_SED) < $< > $@
 
 doc/%.pdf: doc/%.in $(DOCBOOK_WRAPPER)
-	$(DOCBOOK_WRAPPER) $< $@
+	$(DOCBOOK_WRAPPER) "$(DOCBOOK2PDF)" $< $@
 
 doc/%.html: doc/%.in $(DOCBOOK_WRAPPER)
-	$(DOCBOOK_WRAPPER) $< $@
+	$(DOCBOOK_WRAPPER) "$(DOCBOOK2HTML) --nochunks" $< $@
 
 doc/%.html: doc/%.rst
 	$(RST2HTML) $< $@
 
-doc/rapi.pdf doc/rapi.html: doc/rapi-resources.sgml
+doc/rapi.pdf doc/rapi.html doc/rapi.in: doc/rapi-resources.sgml
 
 doc/rapi-resources.sgml: $(BUILD_RAPI_RESOURCE_DOC) lib/rapi/connector.py
 	PYTHONPATH=.:$(top_builddir) $(BUILD_RAPI_RESOURCE_DOC) > $@ || rm -f $@
 
 man/%.7: man/%.in man/footer.sgml $(DOCBOOK_WRAPPER)
-	$(DOCBOOK_WRAPPER) $< $@
+	$(DOCBOOK_WRAPPER) "$(DOCBOOK2MAN)" $< $@
 
 man/%.8: man/%.in man/footer.sgml $(DOCBOOK_WRAPPER)
-	$(DOCBOOK_WRAPPER) $< $@
+	$(DOCBOOK_WRAPPER) "$(DOCBOOK2MAN)" $< $@
 
 man/footer.sgml $(TESTS): srclinks
 
diff --git a/autotools/docbook-wrapper b/autotools/docbook-wrapper
index 9f53b6d976aefa925aa27a99fb8061e13f9d90bc..f525f16a1cb774b24f32a2bdf0d3d498163d172a 100755
--- a/autotools/docbook-wrapper
+++ b/autotools/docbook-wrapper
@@ -2,23 +2,20 @@
 
 set -e
 
-input="${1}"
-output="${2}"
+if test "$#" != 3
+then
+  echo "Wrong number of arguments." >&2
+  exit 1
+fi
+
+cmd="${1}"
+input="${2}"
+output="${3}"
 
 # docbook2man inserts a date formatted using the current locale into its
 # output. Using the "C" locale makes sure it's always in the default format.
 export LC_ALL=C
 
-case "${output}" in
-  *.pdf) cmd=docbook2pdf ;;
-  *.html) cmd='docbook2html --nochunks' ;;
-  *.7|*.8) cmd=docbook2man ;;
-  *)
-    echo "Unknown filetype: ${output}" >&2
-    exit 1
-  ;;
-esac
-
 tmpdir=`mktemp -d`
 trap "rm -rf ${tmpdir}" EXIT
 
@@ -27,7 +24,7 @@ if ! ( cd `dirname ${input}` &&
 then
   echo "Building ${output} failed." >&2
   exit 1
-fi;
+fi
 
 mv "${tmpdir}/`basename "${output}"`" "${output}"