From: Mechtilde Stehmann <mechtilde@debian.org>
Date: Sat, 3 Aug 2024 19:12:27 +0200
Subject: Modify source to follow common conventions. Prevent texhash. Applied
 to new upstream version

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      | 174 +++++++++++++++++++++++++++---------------------------
 src/icon/Makefile |   6 +-
 src/lib/Makefile  |  10 ++--
 src/xdoc/Makefile |   2 +-
 4 files changed, 95 insertions(+), 97 deletions(-)

diff --git a/src/Makefile b/src/Makefile
index 1897c09..2ce9213 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -30,7 +30,11 @@ ELISP=/dev/null
 # change WEAVE if you want a different version of noweave to be installed
 WEAVE=noweave
 
-# Stop editing.  No user-serviceable parts below.
+INSTALL = install
+INSTALL_PROGRAM = $(INSTALL)
+INSTALL_DATA = $(INSTALL) -m 644
+
+# Stop editing.	 No user-serviceable parts below.
 SHELL=/bin/sh
 CINAME=
 CIMSG=
@@ -59,30 +63,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)@;s@|GITVERSION|@$(GITVERSION)@" shell/noweb > $(BIN)/noweb
-	chmod +x $(BIN)/noweb
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/notangle > $(BIN)/notangle
-	chmod +x $(BIN)/notangle
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/$(WEAVE) > $(BIN)/$(WEAVE)
-	chmod +x $(BIN)/$(WEAVE)
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/nountangle > $(BIN)/nountangle
-	chmod +x $(BIN)/nountangle
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/nodefs > $(BIN)/nodefs
-	chmod +x $(BIN)/nodefs
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/noroots > $(BIN)/noroots
-	chmod +x $(BIN)/noroots
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/nuweb2noweb > $(BIN)/nuweb2noweb
-	chmod +x $(BIN)/nuweb2noweb
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/cpif > $(BIN)/cpif
-	chmod +x $(BIN)/cpif
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/htmltoc > $(BIN)/htmltoc
-	chmod +x $(BIN)/htmltoc
-	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" 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)@;s@|GITVERSION|@$(GITVERSION)@" shell/noweb > $(DESTDIR)$(BIN)/noweb
+	chmod +x $(DESTDIR)$(BIN)/noweb
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/notangle > $(DESTDIR)$(BIN)/notangle
+	chmod +x $(DESTDIR)$(BIN)/notangle
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/$(WEAVE) > $(DESTDIR)$(BIN)/$(WEAVE)
+	chmod +x $(DESTDIR)$(BIN)/$(WEAVE)
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/nountangle > $(DESTDIR)$(BIN)/nountangle
+	chmod +x $(DESTDIR)$(BIN)/nountangle
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/nodefs > $(DESTDIR)$(BIN)/nodefs
+	chmod +x $(DESTDIR)$(BIN)/nodefs
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/noroots > $(DESTDIR)$(BIN)/noroots
+	chmod +x $(DESTDIR)$(BIN)/noroots
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/nuweb2noweb > $(DESTDIR)$(BIN)/nuweb2noweb
+	chmod +x $(DESTDIR)$(BIN)/nuweb2noweb
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/cpif > $(DESTDIR)$(BIN)/cpif
+	chmod +x $(DESTDIR)$(BIN)/cpif
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" shell/htmltoc > $(DESTDIR)$(BIN)/htmltoc
+	chmod +x $(DESTDIR)$(BIN)/htmltoc
+	sed "s@|LIBDIR|@$(LIBNAME)@;s@|GITVERSION|@$(GITVERSION)@" 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
@@ -99,34 +103,31 @@ 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)
-	(cd $(LIBSRC) && $(MAKE) "ICONT=$(ICONT)" "ICONC=$(ICONC)" LIB=$(LIB) BIN=$(BIN) install)
-	(cd lib && $(MAKE) LIB=$(LIB) install)
+	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
 
 uninstall-code: uninstall-shell
 	rm -f $(LIB)/nt $(LIB)/markup $(LIB)/mnt $(LIB)/finduses
 	(cd $(LIBSRC) && $(MAKE) "ICONT=$(ICONT)" "ICONC=$(ICONC)" LIB=$(LIB) BIN=$(BIN) uninstall)
 	(cd lib && $(MAKE) LIB=$(LIB) uninstall)
 install-man:
-	mkdir -p $(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)$(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)
@@ -144,54 +145,51 @@ uninstall-man:
 	rm -f $(MANDIR)/nountangle.$(MANEXT)
 	rmdir $(MANDIR) $(MAN7DIR) $(MAN) 2>/dev/null || true
 install-gzipped-man:
-	mkdir -p $(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)
+<<<<<<< HEAD
+	mkdir -p $(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 notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
+	(cd $(DESTDIR)$(MANDIR) && ln notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
 install-preformat-man:
 	-echo "Warning: install-preformat-man is obsolete, even on Slackware systems" 1>&2
-	mkdir -p $(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)$(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 notangle.$(MANEXT).gz noweave.$(MANEXT).gz)
+	(cd $(DESTDIR)$(CATDIR) && ln notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
 install-tex:
-	mkdir -p $(TEXINPUTS)
-	sed "s@|GITVERSION|@$(GITVERSION)@" tex/nwmac.tex > $(TEXINPUTS)/nwmac.tex
-	sed "s@|GITVERSION|@$(GITVERSION)@" tex/noweb.sty > $(TEXINPUTS)/noweb.sty
-	-texhash || echo "Program texhash not found or failed"
-
+	mkdir -p $(DESTDIR)$(TEXINPUTS)
+	sed "s@|GITVERSION|@$(GITVERSION)@" tex/nwmac.tex > $(DESTDIR)$(TEXINPUTS)/nwmac.tex
+	sed "s@|GITVERSION|@$(GITVERSION)@" tex/noweb.sty > $(DESTDIR)$(TEXINPUTS)/noweb.sty
+	# we run texhash in the postinst script instead --uhoreg
+	#texhash || echo "Program texhash not found or failed"
 uninstall-tex:
 	rm -f $(TEXINPUTS)/nwmac.tex
 	rm -f $(TEXINPUTS)/noweb.sty
 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
diff --git a/src/icon/Makefile b/src/icon/Makefile
index b8f39ee..c9e2dfe 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 38ae6cc..f69c9af 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 3b103fb..2a1164a 100644
--- a/src/xdoc/Makefile
+++ b/src/xdoc/Makefile
@@ -23,7 +23,7 @@ CIMSG="message for version checked in"
 RCSFILES=*.nw *.tex Makefile
 DOVERSION=./doversion
 
-all: $(SRCS)
+all: $(MANPAGES)
 source: $(SRCS)
 touch: $(SRCS)
 	touch $(SRCS)
