@@ -1,28 +1,30 @@
11# Makefile for Pandoc.
22
3+CABAL := Pandoc.cabal
4+
35#-------------------------------------------------------------------------------
46# Cabal constants
57#-------------------------------------------------------------------------------
6−CABAL := $(wildcard *.cabal)
7−NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL))
8−THIS := $(shell echo $(NAME) | tr A-Z a-z)
9−VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL))
10−EXECUTABLES := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL))
8+NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
9+THIS := $(shell echo $(NAME) | tr A-Z a-z)
10+VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL).in)
11+BINS := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
1112
1213#-------------------------------------------------------------------------------
1314# Variables to setup through environment
1415#-------------------------------------------------------------------------------
15−PREFIX ?= /usr/local
16−DESTDIR ?=
16+PREFIX ?= /usr/local
17+DESTDIR ?=
1718
1819#-------------------------------------------------------------------------------
1920# Constant names and commands in source tree
2021#-------------------------------------------------------------------------------
21−SRCDIR := src
22−MANDIR := man
23−BUILDDIR := dist
24−BUILDCONF := .setup-config
25−BUILDCMD := runhaskell Setup.hs
22+SRCDIR := src
23+MANDIR := man
24+BUILDDIR := dist
25+BUILDCONF := .setup-config
26+BUILDCMD := runhaskell Setup.hs
27+CONFIGURE := configure
2628
2729#-------------------------------------------------------------------------------
2830# Installation paths
@@ -40,6 +42,7 @@ PKGPATH := $(DATAPATH)/$(THIS)
4042INSTALL := install -c
4143INSTALL_PROGRAM := $(INSTALL) -m 755
4244INSTALL_DATA := $(INSTALL) -m 644
45+GHC := ghc
4346
4447#-------------------------------------------------------------------------------
4548# Recipes
@@ -53,39 +56,39 @@ templates: $(SRCDIR)/templates
5356$(SRCDIR)/templates:
5457 $(MAKE) -C $(SRCDIR)/templates
5558
56−.PHONY: prep
57−prep:
58− # Darcs cannot preserve file permissions.
59− -for f in configure debian/rules; do chmod +x $$f; done
59+cleanup_files+=$(CABAL)
60+$(CABAL): cabalize $(CABAL).in
61+ ./cabalize <$(CABAL).in >$(CABAL)
6062
6163.PHONY: configure
62−cleanup_files+=$(BUILDDIR) $(BUILDCONF) $(CABAL:%.cabal=%).buildinfo
64+cleanup_files+=$(BUILDDIR) $(BUILDCONF)
6365configure: $(BUILDCONF)
64−$(BUILDCONF): prep
66+$(BUILDCONF): $(CABAL)
6567 $(BUILDCMD) configure --prefix=$(PREFIX)
6668
6769.PHONY: build
6870build: templates configure
6971 $(BUILDCMD) build
7072
71−.PHONY: build-lib-doc
73+.PHONY: build-lib-doc haddock
7274build-lib-doc: html
75+haddock: build-lib-doc
7376cleanup_files+=html
74−html: $(BUILDCONF)
77+html/: configure
78+ -rm -rf html
7579 $(BUILDCMD) haddock && mv $(BUILDDIR)/doc/html .
7680
77−cleanup_files+=$(EXECUTABLES)
78−$(EXECUTABLES): build
81+cleanup_files+=$(BINS)
82+$(BINS): build
7983 # Ugly kludge to seperate program and library installations.
8084 # Leave the library installation to Cabal ('install-lib' target).
81− find $(BUILDDIR) -type f -name "$(EXECUTABLES)" -perm +a=x -exec mv {} . \;
82−
85+ find $(BUILDDIR) -type f -name "$(BINS)" -perm +a=x -exec mv {} . \;
8386
8487# XXX: Note that we don't handle PREFIX correctly at the install-* stages,
8588# i.e. any PREFIX given at the configuration time is lost, unless it is
8689# also supplied (via environment) at these stages.
8790.PHONY: install-exec uninstall-exec
88−bin_all:=$(EXECUTABLES) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
91+bin_all:=$(BINS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
8992install-exec: $(bin_all)
9093 $(INSTALL) -d $(BINPATH); \
9194 for f in $(bin_all); do $(INSTALL_PROGRAM) $$f $(BINPATH)/; done
@@ -98,8 +101,10 @@ man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
98101cleanup_files+=README.html
99102install-doc: $(doc_all)
100103 $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(doc_all) $(DOCPATH)/
101− $(INSTALL) -d $(MANPATH); \
102− for f in $(man_all); do $(INSTALL_DATA) -D $(MANDIR)/$$f $(MANPATH)/$$f; done
104+ for f in $(man_all); do \
105+ $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
106+ $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
107+ done
103108uninstall-doc:
104109 -for f in $(doc_all); do rm -f $(DOCPATH)/$$f; done
105110 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
@@ -118,9 +123,9 @@ install-lib-doc: build-lib-doc
118123 $(INSTALL) -d $(LIBDOCPATH) && cp -a html $(LIBDOCPATH)/
119124
120125.PHONY: test test-markdown
121−test: $(EXECUTABLES)
126+test: $(BINS)
122127 @cd tests && perl runtests.pl -s $(PWD)/$(THIS)
123−test-markdown: $(EXECUTABLES)
128+test-markdown: $(BINS)
124129 @cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(THIS) -tidy
125130%.html: %
126131 ./$(THIS) -s $^ >$@ || rm -f $@
@@ -132,7 +137,7 @@ tags: $(src_all)
132137 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
133138 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
134139
135−deb: debian prep
140+deb: debian
136141 [ -x /usr/bin/fakeroot ] || { \
137142 echo "*** Please install fakeroot package. ***"; \
138143 exit 1; \
@@ -150,7 +155,7 @@ deb: debian prep
150155 fi
151156
152157.PHONY: distclean clean
153−distclean: clean prep
158+distclean: clean
154159 if [ -d debian ]; then fakeroot debian/rules clean; fi
155160clean:
156161 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi