doc: properly fix documentation generation

The docbook2man package does not allow output to be written to standard out,
nor does the SGML allow for more than one file to be created. A previous
hack was to use symlinks and hope for the best. Rather than doing this,
retain the symlinks, but explicitly match on them during build and
create symlinks to the output files. Furthermore, clean up the
documentation source files to remove invalid multiple outputs.

Signed-off-by: Jon Masters <jcm@jonmasters.org>
diff --git a/Makefile.am b/Makefile.am
index d4ef32e..3e699e5 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -36,7 +36,8 @@
 modinfo_LDADD = $(LDADD) libmodtools.a
 modindex_LDADD = $(LDADD) libmodtools.a
 
-MAN5 = modprobe.conf.5 modules.dep.5 depmod.conf.5 modprobe.d.5
+MAN5 = depmod.conf.5 depmod.d.5 modprobe.conf.5 modprobe.d.5 \
+	modules.dep.5 modules.dep.bin.5
 MAN8 = depmod.8 insmod.8 lsmod.8 rmmod.8 modprobe.8 modinfo.8
 SGML = $(addprefix doc/,  $(MAN5:%.5=%.sgml) $(MAN8:%.8=%.sgml))
 dist_man_MANS = $(MAN5) $(MAN8)
@@ -68,14 +69,16 @@
 # docbook2man writes file itself, doesn't do stdout.
 %.8: doc/%.sgml
 	if [ "$(DOCBOOKTOMAN)" = "docbook2man" ]; then                     \
-	    $(DOCBOOKTOMAN) $< > /dev/null 2>&1;                       \
+	    $(DOCBOOKTOMAN) $< > /dev/null 2>&1;                           \
 	else                                                               \
 	    $(DOCBOOKTOMAN) $< 2>&1 > $@ | sed 's/^[^:]*://';              \
 	fi
 
 %.5: doc/%.sgml
-	if [ "$(DOCBOOKTOMAN)" = "docbook2man" ]; then                     \
-	    $(DOCBOOKTOMAN) $< > /dev/null 2>&1;                       \
+	if [ -h $< ]; then                                                 \
+	    ln -s $$(basename $$(readlink $<) .sgml).5 $@;                 \
+	elif [ "$(DOCBOOKTOMAN)" = "docbook2man" ]; then                   \
+	    $(DOCBOOKTOMAN) $< > /dev/null 2>&1;                           \
 	else                                                               \
 	    $(DOCBOOKTOMAN) $< 2>&1 > $@ | sed 's/^[^:]*://';              \
 	fi
diff --git a/doc/depmod.conf.sgml b/doc/depmod.conf.sgml
index 4bc399b..d055db1 100644
--- a/doc/depmod.conf.sgml
+++ b/doc/depmod.conf.sgml
@@ -21,8 +21,6 @@
     <date>2010-03-01</date>
   </refentryinfo>
   <refmeta>
-    <refentrytitle>depmod.d</refentrytitle>
-    <manvolnum>5</manvolnum>
     <refentrytitle>depmod.conf</refentrytitle>
     <manvolnum>5</manvolnum>
   </refmeta>
diff --git a/doc/modules.dep.sgml b/doc/modules.dep.sgml
index 6aa4607..a0b68ed 100644
--- a/doc/modules.dep.sgml
+++ b/doc/modules.dep.sgml
@@ -21,8 +21,6 @@
     <date>2010-03-01</date>
   </refentryinfo>
   <refmeta>
-    <refentrytitle>modules.dep.bin</refentrytitle>
-    <manvolnum>5</manvolnum>
     <refentrytitle>modules.dep</refentrytitle>
     <manvolnum>5</manvolnum>
   </refmeta>