MAN := $(patsubst %.xml, %.9, $(BOOKS))
 mandocs: $(MAN)
+       @dups=$$(sed -n 's/.*<refname>\([^<]*\)<\/refname>.*/\1/p'      \
+                $(obj)/*.xml.noextra | sort | uniq -d);                \
+       if [ -n "$$dups" ]; then                                        \
+               echo >&2 "The following manual pages are generated more than once:"; \
+               printf >&2 '%s\n' "$$dups";                             \
+               exit 1;                                                 \
+       fi
        find $(obj)/man -name '*.9' | xargs gzip -nf
 
 installmandocs: mandocs
             cp $(PNG-$(basename $(notdir $@))) $(patsubst %.html,%,$@); fi
 
 quiet_cmd_db2man = MAN     $@
-      cmd_db2man = if grep -q refentry $<; then xmlto man $(XMLTOFLAGS) -o $(obj)/man $< ; fi
+      cmd_db2man = if grep -q refentry $<; then xmlif excludeextra=1 <$< >$<.noextra && xmlto man $(XMLTOFLAGS) -o $(obj)/man $<.noextra ; fi
 %.9 : %.xml
        @(which xmlto > /dev/null 2>&1) || \
         (echo "*** You need to install xmlto ***"; \
        $(patsubst %.xml, %.ps,   $(DOCBOOKS)) \
        $(patsubst %.xml, %.pdf,  $(DOCBOOKS)) \
        $(patsubst %.xml, %.html, $(DOCBOOKS)) \
+       $(patsubst %, %.noextra,  $(DOCBOOKS)) \
        $(patsubst %.xml, %.9,    $(DOCBOOKS)) \
        $(index)
 
 
 
   <chapter id="snddev">
      <title>Sound Devices</title>
+<?xmlif if excludeextra='1'?>
+<?xmlif else?>
 !Iinclude/sound/core.h
+<?xmlif fi?>
 !Esound/sound_core.c
+<?xmlif if excludeextra='1'?>
+<?xmlif else?>
 !Iinclude/sound/pcm.h
 !Esound/core/pcm.c
 !Esound/core/device.c
 !Esound/core/hwdep.c
 !Esound/core/pcm_native.c
 !Esound/core/memalloc.c
+<?xmlif fi?>
 <!-- FIXME: Removed for now since no structured comments in source
 X!Isound/sound_firmware.c
 -->
 
 
      <sect1><title>String Conversions</title>
 !Elib/vsprintf.c
+<?xmlif if excludeextra='1'?>
+<?xmlif else?>
 !Finclude/linux/kernel.h kstrtol
 !Finclude/linux/kernel.h kstrtoul
+<?xmlif fi?>
 !Elib/kstrtox.c
      </sect1>
      <sect1><title>String Manipulation</title>
   <chapter id="hardware">
      <title>Hardware Interfaces</title>
      <sect1><title>Interrupt Handling</title>
+<?xmlif if excludeextra='1'?>
+<?xmlif else?>
 !Ekernel/irq/manage.c
+<?xmlif fi?>
      </sect1>
 
      <sect1><title>DMA Channels</title>