--- Makefile.orig	2008-02-24 01:38:45.000000000 +0100
+++ Makefile	2008-02-24 02:19:05.000000000 +0100
@@ -6,9 +6,9 @@
 CFLAGS=
 # If you have Icon, you should use the Icon versions of the noweb pipeline.
 # Set LIBSRC=icon
-LIBSRC=awk
+LIBSRC=icon
 # If you have no Icon compiler, but do have icont, make ICONC=icont
-ICONC=iconc
+ICONC=icont
 ICONT=icont
 
 # BIN is where the commands (notangle, noweave, nountangle, noroots) land
@@ -18,13 +18,15 @@
 # MAN7EXT is the extension for the nowebstyle man page (usually 7)
 # TEXINPUTS is the directory for TeX macro files
 # ELISP is the directory for emacs lisp files, or /dev/null not to install
-BIN=/usr/local/noweb
-LIB=/usr/local/noweb/lib
-MAN=/usr/local/noweb/man
+PREFIX?=@PREFIX@
+NOWEBPREFIX=$(DESTDIR)$(PREFIX)
+BIN=$(NOWEBPREFIX)/bin
+LIB=$(NOWEBPREFIX)/libexec/noweb
+MAN=$(NOWEBPREFIX)/share/man
 MANEXT=1
 MAN7EXT=7
-TEXINPUTS=/usr/local/tex/inputs
-ELISP=/dev/null
+TEXINPUTS=$(NOWEBPREFIX)/share/texmf/tex/generic/noweb
+ELISP=$(NOWEBPREFIX)/share/emacs/site-lisp
 
 # change WEAVE if you want a different version of noweave to be installed
 WEAVE=noweave		
@@ -37,8 +39,9 @@
 MAN7DIR=$(MAN)/man$(MAN7EXT)
 CATDIR=$(MAN)/cat$(MANEXT)
 CAT7DIR=$(MAN)/cat$(MAN7EXT)
-LIBNAME=$(LIB)
-TEXNAME=$(TEXINPUTS)
+LIBNAME=$(PREFIX)/libexec/noweb
+TEXNAME=$(PREFIX)/share/texmf/tex/generic/noweb
+INSTALLDIR=install -d
 
 all: 
 	cd c; make "CC=$(CC)" "CFLAGS=$(CFLAGS)" all 
@@ -58,7 +61,7 @@
 	-rmdir $(BIN) $(LIB) 2>/dev/null
 
 install-shell:
-	-mkdir $(BIN) $(LIB) 2>/dev/null
+	-$(INSTALLDIR) $(BIN) $(LIB) 2>/dev/null
 	sed "s@|LIBDIR|@$(LIBNAME)@" shell/noweb > $(BIN)/noweb
 	chmod +x $(BIN)/noweb
 	sed "s@|LIBDIR|@$(LIBNAME)@" shell/notangle > $(BIN)/notangle
@@ -98,7 +101,7 @@
 	rm $(LIB)/tmac.w
 
 install-code: install-shell
-	-mkdir $(BIN) $(LIB) 2>/dev/null
+	-$(INSTALLDIR) $(BIN) $(LIB) 2>/dev/null
 	strip c/nt c/markup c/mnt c/finduses
 	cp c/nt c/markup c/mnt c/finduses $(LIB)
 	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) install
@@ -109,7 +112,7 @@
 	cd $(LIBSRC); make ICONT=$(ICONT) ICONC=$(ICONC) LIB=$(LIB) BIN=$(BIN) uninstall
 	cd lib; make LIB=$(LIB) uninstall
 install-man:
-	-mkdir $(MAN) $(MANDIR) $(MAN7DIR) 2>/dev/null
+	-$(INSTALLDIR) $(MAN) $(MANDIR) $(MAN7DIR) 2>/dev/null
 	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)
@@ -142,7 +145,7 @@
 	rm -f $(MANDIR)/noweave.$(MANEXT)
 	rm -f $(MANDIR)/nountangle.$(MANEXT)
 install-gzipped-man:
-	-mkdir $(MAN) $(MANDIR) $(MAN7DIR) 2>/dev/null
+	-$(INSTALLDIR) $(MAN) $(MANDIR) $(MAN7DIR) 2>/dev/null
 	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
@@ -161,7 +164,7 @@
 	(cd $(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 $(MAN) $(CATDIR) $(CAT7DIR) 2>/dev/null
+	-$(INSTALLDIR) $(MAN) $(CATDIR) $(CAT7DIR) 2>/dev/null
 	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
@@ -179,7 +182,7 @@
 	rm -f $(CATDIR)/nountangle.$(MANEXT).gz
 	(cd $(CATDIR); ln notangle.$(MANEXT).gz nountangle.$(MANEXT).gz)
 install-tex:
-	-mkdir $(TEXINPUTS) 2>/dev/null
+	-$(INSTALLDIR) $(TEXINPUTS) 2>/dev/null
 	cp tex/nwmac.tex tex/noweb.sty $(TEXINPUTS)
 	-texhash || echo "Program texhash not found or failed"
 
@@ -187,7 +190,7 @@
 	rm -f $(TEXINPUTS)/nwmac.tex $(TEXINPUTS)/noweb.sty
 
 install-elisp:
-	-mkdir $(ELISP) 2>/dev/null
+	-$(INSTALLDIR) $(ELISP) 2>/dev/null
 	cp elisp/noweb-mode.el $(ELISP)
 
 uninstall-elisp:
