--- unix/Makefile.in
+++ unix/Makefile.in
@@ -257,9 +257,10 @@
 CC			= @CC@
 #CC			= purify -best-effort @CC@ -DPURIFY
 
-# Flags to be passed to mkLinks to control whether the manpages
+# Flags to be passed to installManPage to control whether the manpages
 # should be compressed and linked with softlinks
-MKLINKS_FLAGS           = @MKLINKS_FLAGS@
+MAN_FLAGS		= @MAN_FLAGS@
+MANN_PREFIX		= @MANN_PREFIX@
 
 #----------------------------------------------------------------
 # The information below is usually usable as is.  The configure
@@ -680,8 +681,8 @@
 	done;
 
 install-doc: doc
-	@if test ! -x $(UNIX_DIR)/mkLinks; then \
-	    chmod +x $(UNIX_DIR)/mkLinks; \
+	@if test ! -x $(UNIX_DIR)/installManPage; then \
+	    chmod +x $(UNIX_DIR)/installManPage; \
 	    fi
 	@for i in $(MAN_INSTALL_DIR) $(MAN1_INSTALL_DIR) $(MAN3_INSTALL_DIR) $(MANN_INSTALL_DIR) ; \
 	    do \
@@ -692,36 +693,20 @@
 		else true; \
 		fi; \
 	    done;
-	@echo "Installing top-level (.1) docs";
-	@cd $(TOP_DIR)/doc; for i in *.1; \
-	    do \
-	    rm -f $(MAN1_INSTALL_DIR)/$$i; \
-	    sed -e '/man\.macros/r man.macros' -e '/man\.macros/d' \
-		    $$i > $(MAN1_INSTALL_DIR)/$$i; \
-	    chmod 444 $(MAN1_INSTALL_DIR)/$$i; \
-	    done;
-	@echo "Cross-linking top-level (.1) docs";
-	@$(UNIX_DIR)/mkLinks $(MKLINKS_FLAGS) $(MAN1_INSTALL_DIR)
-	@echo "Installing C API (.3) docs";
-	@cd $(TOP_DIR)/doc; for i in *.3; \
-	    do \
-	    rm -f $(MAN3_INSTALL_DIR)/$$i; \
-	    sed -e '/man\.macros/r man.macros' -e '/man\.macros/d' \
-		    $$i > $(MAN3_INSTALL_DIR)/$$i; \
-	    chmod 444 $(MAN3_INSTALL_DIR)/$$i; \
-	    done;
-	@echo "Cross-linking C API (.3) docs";
-	@$(UNIX_DIR)/mkLinks $(MKLINKS_FLAGS) $(MAN3_INSTALL_DIR)
-	@echo "Installing command (.n) docs";
-	@cd $(TOP_DIR)/doc; for i in *.n; \
-	    do \
-	    rm -f $(MANN_INSTALL_DIR)/$$i; \
-	    sed -e '/man\.macros/r man.macros' -e '/man\.macros/d' \
-		    $$i > $(MANN_INSTALL_DIR)/$$i; \
-	    chmod 444 $(MANN_INSTALL_DIR)/$$i; \
-	    done;
-	@echo "Cross-linking command (.n) docs";
-	@$(UNIX_DIR)/mkLinks $(MKLINKS_FLAGS) $(MANN_INSTALL_DIR)
+	@echo "Installing and cross-linking top-level (.1) docs";
+	@cd $(TOP_DIR)/doc; for i in *.1; do \
+	    $(UNIX_DIR)/installManPage $(MAN_FLAGS) $$i $(MAN1_INSTALL_DIR); \
+	done
+
+	@echo "Installing and cross-linking C API (.3) docs";
+	@cd $(TOP_DIR)/doc; for i in *.3; do \
+	    $(UNIX_DIR)/installManPage $(MAN_FLAGS) $$i $(MAN3_INSTALL_DIR); \
+	done
+
+	@echo "Installing and cross-linking command (.n) docs";
+	@cd $(TOP_DIR)/doc; for i in *.n; do \
+	    $(UNIX_DIR)/installManPage $(MAN_FLAGS) $(MANN_PREFIX) $$i $(MANN_INSTALL_DIR); \
+	done
 
 Makefile: $(UNIX_DIR)/Makefile.in $(DLTEST_DIR)/Makefile.in
 	$(SHELL) config.status
@@ -1196,11 +1184,6 @@
 	mv RPMS/i386/*.rpm .
 	rm -rf RPMS THIS.TCL.SPEC
 
-mklinks:
-	$(TCL_EXE) $(UNIX_DIR)/mkLinks.tcl \
-		$(UNIX_DIR)/../doc/*.[13n] > $(UNIX_DIR)/mkLinks
-	chmod +x $(UNIX_DIR)/mkLinks
-
 #
 # Target to create a proper Tcl distribution from information in the
 # master source directory.  DISTDIR must be defined to indicate where
@@ -1212,7 +1195,7 @@
 ZIPNAME	 = tcl${MAJOR_VERSION}${MINOR_VERSION}${PATCH_LEVEL}-src.zip
 DISTDIR	 = $(DISTROOT)/$(DISTNAME)
 
-dist: mklinks
+dist:
 	rm -rf $(DISTDIR)
 	mkdir -p $(DISTDIR)/unix
 	cp -p $(UNIX_DIR)/*.c $(UNIX_DIR)/*.h $(DISTDIR)/unix
@@ -1222,7 +1205,7 @@
 		$(UNIX_DIR)/tcl.m4 $(UNIX_DIR)/aclocal.m4 \
 		$(UNIX_DIR)/tclConfig.sh.in $(UNIX_DIR)/install-sh \
 		$(UNIX_DIR)/README $(UNIX_DIR)/ldAix $(UNIX_DIR)/tcl.spec \
-		$(UNIX_DIR)/mkLinks \
+		$(UNIX_DIR)/installManPage \
 		$(DISTDIR)/unix
 	chmod 775 $(DISTDIR)/unix/configure $(DISTDIR)/unix/configure.in
 	chmod 775 $(DISTDIR)/unix/ldAix
--- unix/installManPage
+++ unix/installManPage
@@ -0,0 +1,51 @@
+#!/bin/sh
+
+ZIP=:
+while true; do
+    case $1 in
+	-s | --symlinks  )      S="-s ";;
+	-z | --compress  )    ZIP=$2;  shift ;;
+	-e | --extension )      Z=$2;  shift ;;
+	-p | --prefix    ) PREFIX=$2;  shift ;;
+	*)  break ;;
+    esac
+    shift
+done
+if test "$#" != 2; then
+    echo "Usage: installManPages <options> file dir"
+    exit 1
+fi
+
+MANPAGE=$1
+DIR=$2
+test -z "$S" && S="$DIR/"
+
+# Backslashes are trippled in the sed script, because it is in backticks
+# which don't pass backslashes literally.
+NAMES=`sed -n '
+    /^\\.SH NAME/{    # Look for a line, that starts with .SH NAME
+	s/^.*$//      # Delete the content of this line
+	n             # Read next line
+	s/,\|\\\ //g  # Remove all commas
+	s/ \\\-.*//   # Delete from \- to the end of line
+	p             # print the result
+	q             # quit - we only want to handle the first .SH NAME in the file
+    }' $MANPAGE`
+
+SECTION=`echo $MANPAGE | sed 's/.*\(.\)$/\1/'`
+SRCDIR=`dirname $MANPAGE`
+FIRST=""
+for f in $NAMES; do
+    f=$PREFIX${f#$PREFIX}.$SECTION
+    if test -z "$FIRST" ; then
+	FIRST=$f
+	rm -f $DIR/$FIRST $DIR/$FIRST.*
+	sed -e "/man\.macros/r $SRCDIR/man.macros" -e "/man\.macros/d" \
+	    $MANPAGE > $DIR/$FIRST
+	chmod 444 $DIR/$FIRST
+	$ZIP $DIR/$FIRST
+    else
+	rm -f $DIR/$f $DIR/$f.*
+	ln $S$FIRST$Z $DIR/$f$Z
+    fi
+done
--- unix/tcl.m4
+++ unix/tcl.m4
@@ -603,6 +603,8 @@
 #	
 #	Decide whether to use symlinks for linking the manpages and
 #	whether to compress the manpages after installation.
+#       If compression is enabled also find out what file name suffix
+#       the given compression program is using.
 #
 # Arguments:
 #	none
@@ -612,11 +614,12 @@
 #	Adds the following arguments to configure:
 #		--enable-man-symlinks
 #		--enable-man-compression=PROG
+#		--enable-man-prefix=STRING
 #
 #	Defines the following variable:
 #
-#	MKLINKS_FLAGS -		The apropriate flags for mkLinks
-#				according to the user's selection.
+#	MAN_FLAGS -	The apropriate flags for installManPage
+#			according to the user's selection.
 #
 #--------------------------------------------------------------------
 AC_DEFUN(SC_CONFIG_MANPAGES, [
@@ -624,20 +627,39 @@
 	AC_MSG_CHECKING([whether to use symlinks for manpages])
 	AC_ARG_ENABLE(man-symlinks,
 		[  --enable-man-symlinks   use symlinks for the manpages],
-		test "$enableval" != "no" && MKLINKS_FLAGS="$MKLINKS_FLAGS --symlinks",
+		test "$enableval" != "no" && MAN_FLAGS="$MAN_FLAGS --symlinks",
 		enableval="no")
 	AC_MSG_RESULT([$enableval])
 
-	AC_MSG_CHECKING([compression for manpages])
+	AC_MSG_CHECKING([whether to compress the manpages])
 	AC_ARG_ENABLE(man-compression,
 		[  --enable-man-compression=PROG
-                          compress the manpages with PROG],
-		test "$enableval" = "yes" && echo && AC_MSG_ERROR([missing argument to --enable-man-compression])
-		test "$enableval" != "no" && MKLINKS_FLAGS="$MKLINKS_FLAGS --compress $enableval",
+			  compress the manpages with PROG],
+		test "$enableval" = "yes" && AC_MSG_ERROR([missing argument to --enable-man-compression])
+		test "$enableval" != "no" && MAN_FLAGS="$MAN_FLAGS --compress $enableval",
+		enableval="no")
+	AC_MSG_RESULT([$enableval])
+	if test "$enableval" != "no"; then
+		AC_MSG_CHECKING([for compressed file suffix])
+		touch TeST
+		$enableval TeST
+		Z=`ls TeST* | sed 's/^....//'`
+		rm -f TeST*
+		MAN_FLAGS="$MAN_FLAGS --extension $Z"
+		AC_MSG_RESULT([$Z])
+	fi
+
+	AC_MSG_CHECKING([whether to use a file name prefix for the manpages])
+	AC_ARG_ENABLE(man-prefix,
+		[  --enable-man-prefix=STRING
+			  use STRING as a prefix to manpage file names],
+		test "$enableval" = "yes" && enableval="tcl_"
+		test "$enableval" != "no" && MANN_PREFIX="--prefix $enableval",
 		enableval="no")
 	AC_MSG_RESULT([$enableval])
 
-	AC_SUBST(MKLINKS_FLAGS)
+	AC_SUBST(MAN_FLAGS)
+	AC_SUBST(MANN_PREFIX)
 ])
 
 #--------------------------------------------------------------------
