From: Hubert Chathi <uhoreg@debian.org>
Date: Sun, 22 Jan 2023 20:52:34 +0100
Subject: modify source to follow common conventions. Prevent texhash.

Let DESTDIR and INSTALL_PROGRAM have their usual meaning
(so the values set by Debhelper are correct).

Create directories with mkdir -p (reporting unexpected errors).

texhash is run by postinst scripts, no need to run it via Make.

For manual pages, symbolic links are better than hard links.

TODO: the change in src/xdoc/Makefile deserves an explanation here.

src/Makefile is generated from src/Makefile.nw.
It would be trivial to fix it instead,
but the generation is avoided in the Debian build
in order to break a circular dependency.
---
 src/Makefile      | 164 +++++++++++++++++++++++++++---------------------------
 src/icon/Makefile |   6 +-
 src/lib/Makefile  |  10 ++--
 src/xdoc/Makefile |   2 +-
 4 files changed, 90 insertions(+), 92 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 339df3b..d3d6e10 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -29,6 +29,10 @@ ELISP=/dev/null
 # change WEAVE if you want a different version of noweave to be installed
 WEAVE=noweave		
 
+INSTALL = install
+INSTALL_PROGRAM = $(INSTALL)
+INSTALL_DATA = $(INSTALL) -m 644
+
 # Stop editing.	 No user-serviceable parts below.
 SHELL=/bin/sh
 CINAME=
@@ -58,30 +62,30 @@ uninstall: uninstall-code uninstall-man uninstall-tex uninstall-elisp
 	-rmdir $(BIN) $(LIB) 2>/dev/null || true
 
 install-shell:
-	mkdir -p $(BIN) $(LIB)
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noweb > $(BIN)/noweb
-	chmod +x $(BIN)/noweb
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/notangle > $(BIN)/notangle
-	chmod +x $(BIN)/notangle
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/$(WEAVE) > $(BIN)/$(WEAVE)
-	chmod +x $(BIN)/$(WEAVE)
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nountangle > $(BIN)/nountangle
-	chmod +x $(BIN)/nountangle
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nodefs > $(BIN)/nodefs
-	chmod +x $(BIN)/nodefs
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noroots > $(BIN)/noroots
-	chmod +x $(BIN)/noroots
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nuweb2noweb > $(BIN)/nuweb2noweb
-	chmod +x $(BIN)/nuweb2noweb
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/cpif > $(BIN)/cpif
-	chmod +x $(BIN)/cpif
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/htmltoc > $(BIN)/htmltoc
-	chmod +x $(BIN)/htmltoc
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noroff > $(BIN)/noroff
-	chmod +x $(BIN)/noroff
-	sed "s@|LIBDIR|@$(LIBNAME)@" shell/toroff > $(LIB)/toroff
-	chmod +x $(LIB)/toroff
-	cp shell/tmac.w $(LIB)
+	mkdir -p $(DESTDIR)$(BIN) $(DESTDIR)$(LIB)
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noweb > $(DESTDIR)$(BIN)/noweb
+	chmod +x $(DESTDIR)$(BIN)/noweb
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/notangle > $(DESTDIR)$(BIN)/notangle
+	chmod +x $(DESTDIR)$(BIN)/notangle
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/$(WEAVE) > $(DESTDIR)$(BIN)/$(WEAVE)
+	chmod +x $(DESTDIR)$(BIN)/$(WEAVE)
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nountangle > $(DESTDIR)$(BIN)/nountangle
+	chmod +x $(DESTDIR)$(BIN)/nountangle
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nodefs > $(DESTDIR)$(BIN)/nodefs
+	chmod +x $(DESTDIR)$(BIN)/nodefs
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noroots > $(DESTDIR)$(BIN)/noroots
+	chmod +x $(DESTDIR)$(BIN)/noroots
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/nuweb2noweb > $(DESTDIR)$(BIN)/nuweb2noweb
+	chmod +x $(DESTDIR)$(BIN)/nuweb2noweb
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/cpif > $(DESTDIR)$(BIN)/cpif
+	chmod +x $(DESTDIR)$(BIN)/cpif
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/htmltoc > $(DESTDIR)$(BIN)/htmltoc
+	chmod +x $(DESTDIR)$(BIN)/htmltoc
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noroff > $(DESTDIR)$(BIN)/noroff
+	chmod +x $(DESTDIR)$(BIN)/noroff
+	sed "s@|LIBDIR|@$(LIBNAME)@" shell/toroff > $(DESTDIR)$(LIB)/toroff
+	chmod +x $(DESTDIR)$(LIB)/toroff
+	cp shell/tmac.w $(DESTDIR)$(LIB)
 
 uninstall-shell:
 	rm -f $(BIN)/noweb
@@ -98,9 +102,8 @@ uninstall-shell:
 	rm -f $(LIB)/tmac.w
 
 install-code: install-shell
-	mkdir -p $(BIN) $(LIB)
-	strip c/nt c/markup c/mnt c/finduses c/nwmktemp
-	cp c/nt c/markup c/mnt c/finduses c/nwmktemp $(LIB)
+	mkdir -p $(DESTDIR)$(BIN) $(DESTDIR)$(LIB)
+	$(INSTALL_PROGRAM) -s c/nt c/markup c/mnt c/finduses c/nwmktemp $(DESTDIR)$(LIB)
 	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
 	cd lib; make LIB=$(LIB) install
 
@@ -109,23 +112,21 @@ uninstall-code: uninstall-shell
 	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
 	cd lib; make LIB=$(LIB) uninstall
 install-man:
-	mkdir -p $(MAN) $(MANDIR) $(MAN7DIR)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.1 > $(MANDIR)/cpif.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.1 > $(MANDIR)/nodefs.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.1 > $(MANDIR)/noroots.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.1 > $(MANDIR)/noweb.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.1 > $(MANDIR)/noindex.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.1 > $(MANDIR)/nuweb2noweb.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.1 > $(MANDIR)/notangle.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.1 > $(MANDIR)/noroff.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.1 > $(MANDIR)/sl2h.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.1 > $(MANDIR)/htmltoc.$(MANEXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.7 > $(MAN7DIR)/nowebstyle.$(MAN7EXT)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.7 > $(MAN7DIR)/nowebfilters.$(MAN7EXT)
-	rm -f $(MANDIR)/noweave.$(MANEXT)
-	(cd $(MANDIR); ln notangle.$(MANEXT) noweave.$(MANEXT))
-	rm -f $(MANDIR)/nountangle.$(MANEXT)
-	(cd $(MANDIR); ln notangle.$(MANEXT) nountangle.$(MANEXT))
+	mkdir -p $(DESTDIR)$(MAN) $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.1 > $(DESTDIR)$(MANDIR)/cpif.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.1 > $(DESTDIR)$(MANDIR)/nodefs.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.1 > $(DESTDIR)$(MANDIR)/noroots.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.1 > $(DESTDIR)$(MANDIR)/noweb.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.1 > $(DESTDIR)$(MANDIR)/noindex.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.1 > $(DESTDIR)$(MANDIR)/nuweb2noweb.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.1 > $(DESTDIR)$(MANDIR)/notangle.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.1 > $(DESTDIR)$(MANDIR)/noroff.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.1 > $(DESTDIR)$(MANDIR)/sl2h.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.1 > $(DESTDIR)$(MANDIR)/htmltoc.$(MANEXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.7 > $(DESTDIR)$(MAN7DIR)/nowebstyle.$(MAN7EXT)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.7 > $(DESTDIR)$(MAN7DIR)/nowebfilters.$(MAN7EXT)
+	(cd $(DESTDIR)$(MANDIR); ln -fs notangle.$(MANEXT) noweave.$(MANEXT))
+	(cd $(DESTDIR)$(MANDIR); ln -fs notangle.$(MANEXT) nountangle.$(MANEXT))
 uninstall-man:
 	rm -f $(MANDIR)/cpif.$(MANEXT)
 	rm -f $(MANDIR)/nodefs.$(MANEXT)
@@ -143,53 +144,50 @@ uninstall-man:
 	rm -f $(MANDIR)/nountangle.$(MANEXT)
 	-rmdir $(MANDIR) $(MAN7DIR) $(MAN) 2>/dev/null || true
 install-gzipped-man:
-	mkdir -p $(MAN) $(MANDIR) $(MAN7DIR)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.1  | gzip -9 > $(MANDIR)/cpif.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.1  | gzip -9 > $(MANDIR)/nodefs.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.1  | gzip -9 > $(MANDIR)/noroots.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.1  | gzip -9 > $(MANDIR)/noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.1  | gzip -9 > $(MANDIR)/noindex.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.1  | gzip -9 > $(MANDIR)/nuweb2noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.1  | gzip -9 > $(MANDIR)/notangle.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.1  | gzip -9 > $(MANDIR)/noroff.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.1  | gzip -9 > $(MANDIR)/sl2h.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.1  | gzip -9 > $(MANDIR)/htmltoc.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.7  | gzip -9 > $(MAN7DIR)/nowebstyle.$(MAN7EXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.7  | gzip -9 > $(MAN7DIR)/nowebfilters.$(MAN7EXT).gz
-	rm -f $(MANDIR)/noweave.$(MANEXT).gz
-	(cd $(MANDIR); ln notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
-	rm -f $(MANDIR)/nountangle.$(MANEXT).gz
-	(cd $(MANDIR); ln notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
+	mkdir -p $(DESTDIR)$(MAN) $(DESTDIR)$(MANDIR) $(DESTDIR)$(MAN7DIR)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.1  | gzip -9 > $(DESTDIR)$(MANDIR)/cpif.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.1  | gzip -9 > $(DESTDIR)$(MANDIR)/nodefs.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noroots.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noindex.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.1  | gzip -9 > $(DESTDIR)$(MANDIR)/nuweb2noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.1  | gzip -9 > $(DESTDIR)$(MANDIR)/notangle.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.1  | gzip -9 > $(DESTDIR)$(MANDIR)/noroff.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.1  | gzip -9 > $(DESTDIR)$(MANDIR)/sl2h.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.1  | gzip -9 > $(DESTDIR)$(MANDIR)/htmltoc.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.7  | gzip -9 > $(DESTDIR)$(MAN7DIR)/nowebstyle.$(MAN7EXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.7  | gzip -9 > $(DESTDIR)$(MAN7DIR)/nowebfilters.$(MAN7EXT).gz
+	(cd $(DESTDIR)$(MANDIR); ln -fs notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
+	(cd $(DESTDIR)$(MANDIR); ln -fs notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
 install-preformat-man:
 	-echo "Warning: install-preformat-man is obsolete, even on Slackware systems" 1>&2
-	mkdir -p $(MAN) $(CATDIR) $(CAT7DIR)
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.txt  | gzip > $(CATDIR)/cpif.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.txt  | gzip > $(CATDIR)/nodefs.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.txt  | gzip > $(CATDIR)/noroots.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.txt  | gzip > $(CATDIR)/noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.txt  | gzip > $(CATDIR)/noindex.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.txt  | gzip > $(CATDIR)/nuweb2noweb.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.txt  | gzip > $(CATDIR)/notangle.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.txt  | gzip > $(CATDIR)/noroff.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.txt  | gzip > $(CATDIR)/sl2h.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.txt  | gzip > $(CATDIR)/htmltoc.$(MANEXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.txt  | gzip > $(CAT7DIR)/nowebstyle.$(MAN7EXT).gz
-	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.txt  | gzip > $(CAT7DIR)/nowebfilters.$(MAN7EXT).gz
-	rm -f $(CATDIR)/noweave.$(MANEXT).gz
-	(cd $(CATDIR); ln notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
-	rm -f $(CATDIR)/nountangle.$(MANEXT).gz
-	(cd $(CATDIR); ln notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
+	mkdir -p $(DESTDIR)$(MAN) $(DESTDIR)$(CATDIR) $(DESTDIR)$(CAT7DIR)
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/cpif.txt  | gzip > $(DESTDIR)$(CATDIR)/cpif.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nodefs.txt  | gzip > $(DESTDIR)$(CATDIR)/nodefs.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroots.txt  | gzip > $(DESTDIR)$(CATDIR)/noroots.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noweb.txt  | gzip > $(DESTDIR)$(CATDIR)/noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noindex.txt  | gzip > $(DESTDIR)$(CATDIR)/noindex.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nuweb2noweb.txt  | gzip > $(DESTDIR)$(CATDIR)/nuweb2noweb.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/notangle.txt  | gzip > $(DESTDIR)$(CATDIR)/notangle.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/noroff.txt  | gzip > $(DESTDIR)$(CATDIR)/noroff.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/sl2h.txt  | gzip > $(DESTDIR)$(CATDIR)/sl2h.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/htmltoc.txt  | gzip > $(DESTDIR)$(CATDIR)/htmltoc.$(MANEXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebstyle.txt  | gzip > $(DESTDIR)$(CAT7DIR)/nowebstyle.$(MAN7EXT).gz
+	sed -e "s@|LIBDIR|@$(LIBNAME)@" -e "s@|TEXINPUTS|@$(TEXNAME)@" xdoc/nowebfilters.txt  | gzip > $(DESTDIR)$(CAT7DIR)/nowebfilters.$(MAN7EXT).gz
+	(cd $(DESTDIR)$(CATDIR); ln -fs notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
+	(cd $(DESTDIR)$(CATDIR); ln -fs notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
 install-tex:
-	mkdir -p $(TEXINPUTS)
-	cp tex/nwmac.tex tex/noweb.sty $(TEXINPUTS)
-	-texhash || echo "Program texhash not found or failed"
+	mkdir -p $(DESTDIR)$(TEXINPUTS)
+	cp tex/nwmac.tex tex/noweb.sty $(DESTDIR)$(TEXINPUTS)
+	# we run texhash in the postinst script instead --uhoreg
+	#texhash || echo "Program texhash not found or failed"
 
 uninstall-tex:
 	rm -f $(TEXINPUTS)/nwmac.tex $(TEXINPUTS)/noweb.sty || true
 
 install-elisp:
-	if [ "/dev/null" != "$(ELISP)" ]; then mkdir -p $(ELISP); fi
-	cp elisp/noweb-mode.el $(ELISP)
+	mkdir -p $(DESTDIR)$(ELISP)
+	cp elisp/noweb-mode.el $(DESTDIR)$(ELISP)
 
 uninstall-elisp:
 	rm -f $(ELISP)/noweb-mode.el || true
diff --git a/src/icon/Makefile b/src/icon/Makefile
index 7d9b8db..4c12d3f 100644
--- a/src/icon/Makefile
+++ b/src/icon/Makefile
@@ -35,9 +35,9 @@ boot:
 	touch $(SRCS)
 
 install: $(EXECS)
-	cp $(LIBEXECS) $(LIB)
-	cp $(BINEXECS) $(BIN)
-	cp $(LIBSPECIAL) $(LIB)/autodefs.c
+	cp $(LIBEXECS) $(DESTDIR)$(LIB)
+	cp $(BINEXECS) $(DESTDIR)$(BIN)
+	cp $(LIBSPECIAL) $(DESTDIR)$(LIB)/autodefs.c
 
 uninstall:
 	for i in $(LIBEXECS); do rm -f $(LIB)/$$i; done
diff --git a/src/lib/Makefile b/src/lib/Makefile
index 47cb6f4..d16a150 100644
--- a/src/lib/Makefile
+++ b/src/lib/Makefile
@@ -11,11 +11,11 @@ all: toascii
 	chmod +x unmarkup emptydefn toascii nwmtime pipedocs h2a btdefn
 
 install: all
-	cp unmarkup emptydefn nwmtime btdefn $(LIB)
-	sed 's@|LIBDIR|@$(LIB)@g' pipedocs > $(LIB)/pipedocs
-	sed 's@|LIBDIR|@$(LIB)@g' toascii > $(LIB)/toascii
-	sed 's@|LIBDIR|@$(LIB)@g' h2a > $(LIB)/h2a
-	chmod +x $(LIB)/pipedocs $(LIB)/toascii $(LIB)/h2a
+	cp unmarkup emptydefn toascii nwmtime h2a btdefn $(DESTDIR)$(LIB)
+	sed 's@|LIBDIR|@$(LIBNAME)@g' pipedocs > $(DESTDIR)$(LIB)/pipedocs
+	sed 's@|LIBDIR|@$(LIB)@g' toascii > $(DESTDIR)$(LIB)/toascii
+	sed 's@|LIBDIR|@$(LIB)@g' h2a > $(DESTDIR)$(LIB)/h2a
+	chmod +x $(DESTDIR)$(LIB)/pipedocs $(DESTDIR)$(LIB)/toascii $(DESTDIR)$(LIB)/h2a
 
 uninstall: 
 	for i in unmarkup emptydefn toascii nwmtime h2a btdefn; do rm -f $(LIB)/$$i; done
diff --git a/src/xdoc/Makefile b/src/xdoc/Makefile
index 402b3cf..35fc406 100644
--- a/src/xdoc/Makefile
+++ b/src/xdoc/Makefile
@@ -19,7 +19,7 @@ CIMSG="message for version checked in"
 RCSFILES=*.nw *.tex Makefile
 DOVERSION=./doversion
 
-all: $(SRCS)
+all: $(MANPAGES)
 source: $(SRCS)
 touch: $(SRCS)
 	touch $(SRCS)
