--- a/Makefile.in
+++ b/Makefile.in
@@ -6,10 +6,10 @@
 
 # $Id$
 #
-# Copyright (C) 2006, Keith Marshall
+# Copyright (C) 2006, 2007, Keith Marshall
 #
 # Written by Keith Marshall  <keithmarshall@users.sourceforge.net>
-# Last modification: 30-Dec-2006
+# Last modification: 20-Jun-2007
 #
 #
 # This is free software.  It is provided AS IS, in the hope that it may
@@ -27,7 +27,7 @@
 # MA 02110-1301, USA.
 
 srcdir = @srcdir@
-VPATH = ${srcdir}:${srcdir}/include:${srcdir}/repl
+VPATH = ${srcdir}:${srcdir}/include:${srcdir}/repl:${srcdir}/man
 
 prefix = @prefix@
 exec_prefix = @exec_prefix@
@@ -94,6 +94,36 @@
 OTHER_SOURCES   = COPYING ChangeLog mkinstalldirs install-sh $(MISC_SOURCES)
 MISC_SOURCES	= $(CONFIG_HEADERS) $(CONFIG_SOURCES) $(INSTALL_PROGS)
 
+MANPAGE_SOURCES	= catopen.man catgets.man catclose.man gencat.man
+
+# MANSECTS specifies the set of *standard* man section identifiers, to
+# which this collection of man pages will be distributed, or to which
+# references are made in any man page in the collection.
+#
+MANSECTS = 1 2 3
+
+# The set of MAN<n>EXT macros allows us to define local aliases for each
+# of the standard man section identifiers; these will be used instead of
+# the standard identifiers, as extensions for the installed man page
+# directories and file names.
+#
+MAN1EXT = 1
+MAN2EXT = 2
+MAN3EXT = 3
+
+# The following set of macros facilitate identification of the man
+# section to which each generated `page.n' file belongs; this requires
+# the `TH' record in each corresponding `page.man' source file to
+# identify the appropriate section with a `@MAN<n>EXT@' tag.
+#
+mansect_lookup = '/^\.TH/{s/.*\(@MAN[0-9][^@]*EXT@\).*/\1/'
+mansect_transform = $(foreach s,$(MANSECTS),-e s/@MAN$sEXT@/$(MAN$sEXT)/g)
+mansect = -e $(mansect_lookup) $(mansect_transform) -e q -e \} -e d
+manpage = ${mandir}/man$$section/$$pagename.$$section
+
+# Generic rule to create `page.n' from `page.man'...
+#
+%.n: %.man; sed $(mansect_transform) $< > $@
 
 BUILD_PROGS	= gencat$(EXEEXT)
 BUILD_LIBS	= libcatgets.a
@@ -102,14 +132,16 @@
 
 INSTALL_PROGS	= gendefs.awk
 
+# Generic rule, replacing the built-in default, to create an object file
+# from a C source file...
+#
 %.$(OBJEXT): %.c
 	$(CC) -c $(CFLAGS) $(INCLUDES) $(DEFS) $(LDFLAGS) $<
 
+# Generic rule to create a local header from a template...
+#
 %.h: %.h.in Makefile
 	sed $(HEADER_TRANSFORM_SCRIPT) $< > $@
-
-%.h: repl/include/%.h
-	$(LN_S) $< $@
 
 HEADER_TRANSFORM_SCRIPT = \
   -e 's,@HOST_PREFIX@,${canonical_prefix},g' \
@@ -118,15 +150,29 @@
 
 AUTOGENERATED = Automatically generated from $<; do not edit!
 
+# Generic rule to make a replacement header available for use...
+#
+%.h: repl/include/%.h
+	$(LN_S) $< $@
+
 all-dll = @MAKE_DLL@
 
-all: all-libs $(all-dll) all-bin
+all: all-libs $(all-dll) all-bin all-doc
 
 all-bin: $(BUILD_PROGS)
 
 all-dll: $(BUILD_DLLS)
 
 all-libs: $(BUILD_LIBS)
+
+all-doc: all-man all-info all-htmldoc all-pdf all-ps
+
+all-man: $(subst .man,.n,$(MANPAGE_SOURCES))
+
+all-info:
+all-htmldoc:
+all-pdf:
+all-ps:
 
 gencat$(EXEEXT): $(GENCAT_OBJECTS)
 	$(CC) -o $@ $(CFLAGS) $(LDFLAGS) $^ $(LIBICONV) $(LIBS)
@@ -184,7 +230,13 @@
 
 install-doc: install-man install-info install-htmldoc install-pdf install-ps
 
-install-man:
+install-man: $(subst .man,.n,$(MANPAGE_SOURCES))
+	for file in $^; do \
+	  pagename=`echo $$file | sed 's/\.n//'`; \
+	  section=`sed $(mansect) ${srcdir}/$$pagename.man`; \
+	  echo $(INSTALL_DATA) $$file $(manpage); \
+	done
+
 install-info:
 install-htmldoc:
 install-pdf:
@@ -198,7 +250,7 @@
 dist: srcdist bindist
 dist_srcdir = @abs_top_srcdir@
 
-DISTDIRS = include m4 repl repl/include
+DISTDIRS = include m4 repl repl/include man
 DISTFILES = $(GENCAT_SOURCES) $(CATGETS_SOURCES) $(OTHER_SOURCES)
 DISTNAME = $(PACKAGE)-$(VERSION)
 
@@ -233,9 +285,9 @@
 
 clean:
 	rm -f nlspath.h $(LOCAL_HEADERS) $(REPLACEMENT_HEADERS)
-	rm -f *.$(OBJEXT) *~ gencat$(EXEEXT)
+	rm -f *.$(OBJEXT) *~ gencat$(EXEEXT) *.n *.a *.dll
 
 distclean: clean
 	rm -rf Makefile config.h config.[ls]* autom4te.cache
 
-# $RCSfile$Revision: 1.1.1.1 $: end of file
+# $RCSfile$Revision: 1.2 $: end of file