@@ -6,15 +6,15 @@ CABAL := Pandoc.cabal
66# Cabal constants
77#-------------------------------------------------------------------------------
88NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
9−THIS := $(shell echo $(NAME) | tr A-Z a-z)
109VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL).in)
1110EXECS := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
11+MAIN := $(word 1, $(EXECS)) # first entry in stanza is the main executable
1212
1313#-------------------------------------------------------------------------------
14−# Build targets
14+# Install targets
1515#-------------------------------------------------------------------------------
16−BINS := $(EXECS)
17−DOCS := README.html
16+PROGS := $(EXECS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
17+DOCS := README.html README BUGS TODO
1818
1919#-------------------------------------------------------------------------------
2020# Variables to setup through environment
@@ -35,6 +35,7 @@ CONFIGURE := configure
3535#-------------------------------------------------------------------------------
3636# Installation paths
3737#-------------------------------------------------------------------------------
38+THIS := $(shell echo $(NAME) | tr A-Z a-z) # package name
3839DESTPATH := $(DESTDIR)$(PREFIX)
3940BINPATH := $(DESTPATH)/bin
4041DATAPATH := $(DESTPATH)/share
@@ -63,13 +64,13 @@ GHC_PKG := ghc-pkg
6364all: build-program
6465
6566# Document process rules.
66−%.html: % $(THIS)
67− ./$(THIS) -s $< >$@ || rm -f $@
68−%.tex: % $(THIS)
69− ./$(THIS) -s -w latex $< >$@ || rm -f $@
70−%.rtf: % $(THIS)
71− ./$(THIS) -s -w rtf $< >$@ || rm -f $@
72−%.pdf: % $(THIS)
67+%.html: % $(MAIN)
68+ ./$(MAIN) -s $< >$@ || rm -f $@
69+%.tex: % $(MAIN)
70+ ./$(MAIN) -s -w latex $< >$@ || rm -f $@
71+%.rtf: % $(MAIN)
72+ ./$(MAIN) -s -w rtf $< >$@ || rm -f $@
73+%.pdf: % $(MAIN)
7374 sh ./markdown2pdf $< || rm -f $@
7475
7576.PHONY: templates
@@ -88,20 +89,21 @@ $(BUILDCONF): $(CABAL)
8889 $(BUILDCMD) configure --prefix=$(PREFIX)
8990
9091.PHONY: build
91−build: templates configure
92+build: $(BUILDDIR)
93+$(BUILDDIR)/: templates configure
9294 $(BUILDCMD) build
9395
9496.PHONY: build-exec
95−build-exec: $(BINS)
96−cleanup_files+=$(BINS)
97−$(BINS): build
98− find $(BUILDDIR) -type f -name "$(BINS)" -perm +a=x -exec cp {} . \;
97+build-exec: $(EXECS)
98+cleanup_files+=$(EXECS)
99+$(EXECS): $(BUILDDIR)
100+ for f in $@; do \
101+ find $(BUILDDIR) -type f -name "$$f" -perm +a=x -exec cp {} . \; ; \
102+ done
99103
100104.PHONY: build-doc
101−DOCS:=README.html
102−cleanup_files+=$(DOCS)
105+cleanup_files+=README.html
103106build-doc: $(DOCS)
104−$(DOCS): build-exec
105107
106108.PHONY: build-program
107109build-program: build-exec build-doc
@@ -124,15 +126,14 @@ build-all: all build-lib-doc
124126# User documents installation.
125127.PHONY: install-doc uninstall-doc
126128man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
127−doc_all:=$(DOCS) README BUGS TODO
128129install-doc: build-doc
129− $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(doc_all) $(DOCPATH)/
130+ $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
130131 for f in $(man_all); do \
131132 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
132133 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
133134 done
134135uninstall-doc:
135− -for f in $(doc_all); do rm -f $(DOCPATH)/$$f; done
136+ -for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
136137 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
137138 -rmdir $(DOCPATH)
138139
@@ -146,12 +147,11 @@ uninstall-lib-doc:
146147
147148# Program only installation.
148149.PHONY: install-exec uninstall-exec
149−bin_all:=$(BINS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
150150install-exec: build-exec
151151 $(INSTALL) -d $(BINPATH); \
152− for f in $(bin_all); do $(INSTALL_PROGRAM) $$f $(BINPATH)/; done
152+ for f in $(PROGS); do $(INSTALL_PROGRAM) $$f $(BINPATH)/; done
153153uninstall-exec:
154− -for f in $(bin_all); do rm -f $(BINPATH)/$$f; done
154+ -for f in $(PROGS); do rm -f $(BINPATH)/$$f; done
155155
156156# Program + user documents installation.
157157.PHONY: install-program uninstall-program
@@ -187,13 +187,13 @@ doc_more:=README.rtf LICENSE.rtf $(osx_src)/Welcome.rtf
187187osx_pkg_name:=Pandoc_$(VERSION).pkg
188188cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
189189osx-pkg-prep: $(osx_dest)
190−$(osx_dest)/: build-exec $(doc_more)
190+$(osx_dest)/: $(doc_more)
191191 -rm -rf $(osx_dest)
192192 $(INSTALL) -d $(osx_dest)
193193 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
194194 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
195195 find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
196− find $(osx_dest) -type f -regex ".*bin/$(THIS)" | xargs $(STRIP)
196+ find $(osx_dest) -type f -regex ".*bin/$(MAIN)" | xargs $(STRIP)
197197 $(INSTALL) -d $(osx_dest)/Resources
198198 cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
199199 cp LICENSE.rtf $(osx_dest)/Resources/License.rtf
@@ -231,10 +231,10 @@ $(osx_dmg_name): $(osx_pkg_name)
231231 mv Pandoc.udzo.dmg $(osx_dmg_name)
232232
233233.PHONY: test test-markdown
234−test: build-exec
235− @cd tests && perl runtests.pl -s $(PWD)/$(THIS)
236−test-markdown: build-exec
237− @cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(THIS) -tidy
234+test: $(MAIN)
235+ @cd tests && perl runtests.pl -s $(PWD)/$(MAIN)
236+test-markdown: $(MAIN)
237+ @cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
238238
239239# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
240240src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')