@@ -18,12 +18,6 @@ MAIN := $(word 1, $(EXECS))
1818PROGS := $(EXECS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
1919DOCS := README.html README BUGS TODO
2020
21−#-------------------------------------------------------------------------------
22−# Variables to setup through environment
23−#-------------------------------------------------------------------------------
24−PREFIX ?= /usr/local
25−DESTDIR ?=
26−
2721#-------------------------------------------------------------------------------
2822# Constant names and commands in source tree
2923#-------------------------------------------------------------------------------
@@ -32,8 +26,22 @@ MANDIR := man
3226BUILDDIR := dist
3327BUILDCONF := .setup-config
3428BUILDCMD := runhaskell Setup.hs
29+BUILDVARS := vars
3530CONFIGURE := configure
3631
32+#-------------------------------------------------------------------------------
33+# Variables to setup through environment
34+#-------------------------------------------------------------------------------
35+
36+# Specify default values.
37+prefix := /usr/local
38+destdir :=
39+# Attempt to set variables from a previous make session.
40+-include $(BUILDVARS)
41+# Fallback to defaults but allow to get the values from environment.
42+PREFIX ?= $(prefix)
43+DESTDIR ?= $(destdir)
44+
3745#-------------------------------------------------------------------------------
3846# Installation paths
3947#-------------------------------------------------------------------------------
@@ -85,10 +93,13 @@ $(CABAL): cabalize $(CABAL).in
8593 ./cabalize <$(CABAL).in >$(CABAL)
8694
8795.PHONY: configure
88−cleanup_files+=$(BUILDDIR) $(BUILDCONF)
96+cleanup_files+=$(BUILDDIR) $(BUILDCONF) $(BUILDVARS)
8997configure: $(BUILDCONF)
9098$(BUILDCONF): $(CABAL)
9199 $(BUILDCMD) configure --prefix=$(PREFIX)
100+ # Make configuration time settings persistent (definitely a hack).
101+ @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
102+ @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
92103
93104.PHONY: build
94105build: $(BUILDDIR)
@@ -121,10 +132,6 @@ html/: configure
121132.PHONY: build-all
122133build-all: all build-lib-doc
123134
124−# XXX: Note that we don't handle PREFIX correctly at the install-* stages,
125−# i.e. any PREFIX given at the configuration time is lost, unless it is
126−# also supplied (via environment) at these stages.
127−
128135# User documents installation.
129136.PHONY: install-doc uninstall-doc
130137man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))