git.iko.soy/typeable/pandoc
on master help sign in
More sanitizations in Makefile (needs testing):
2066ec5roktas
Makefile+31−31
@@ -6,15 +6,15 @@ CABAL := Pandoc.cabal
6# Cabal constants
6# Cabal constants
7#-------------------------------------------------------------------------------
7#-------------------------------------------------------------------------------
8NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
8NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
9−THIS := $(shell echo $(NAME) | tr A-Z a-z)
10VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL).in)
9VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL).in)
11EXECS := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
10EXECS := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
11+MAIN := $(word 1, $(EXECS)) # first entry in stanza is the main executable
12
12
13#-------------------------------------------------------------------------------
13#-------------------------------------------------------------------------------
14−# Build targets
14+# Install targets
15#-------------------------------------------------------------------------------
15#-------------------------------------------------------------------------------
16−BINS := $(EXECS)
16+PROGS := $(EXECS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
17−DOCS := README.html
17+DOCS := README.html README BUGS TODO
18
18
19#-------------------------------------------------------------------------------
19#-------------------------------------------------------------------------------
20# Variables to setup through environment
20# Variables to setup through environment
@@ -35,6 +35,7 @@ CONFIGURE := configure
35#-------------------------------------------------------------------------------
35#-------------------------------------------------------------------------------
36# Installation paths
36# Installation paths
37#-------------------------------------------------------------------------------
37#-------------------------------------------------------------------------------
38+THIS := $(shell echo $(NAME) | tr A-Z a-z) # package name
38DESTPATH := $(DESTDIR)$(PREFIX)
39DESTPATH := $(DESTDIR)$(PREFIX)
39BINPATH := $(DESTPATH)/bin
40BINPATH := $(DESTPATH)/bin
40DATAPATH := $(DESTPATH)/share
41DATAPATH := $(DESTPATH)/share
@@ -63,13 +64,13 @@ GHC_PKG := ghc-pkg
63all: build-program
64all: build-program
64
65
65# Document process rules.
66# Document process rules.
66−%.html: % $(THIS)
67+%.html: % $(MAIN)
67− ./$(THIS) -s $< >$@ || rm -f $@
68+ ./$(MAIN) -s $< >$@ || rm -f $@
68−%.tex: % $(THIS)
69+%.tex: % $(MAIN)
69− ./$(THIS) -s -w latex $< >$@ || rm -f $@
70+ ./$(MAIN) -s -w latex $< >$@ || rm -f $@
70−%.rtf: % $(THIS)
71+%.rtf: % $(MAIN)
71− ./$(THIS) -s -w rtf $< >$@ || rm -f $@
72+ ./$(MAIN) -s -w rtf $< >$@ || rm -f $@
72−%.pdf: % $(THIS)
73+%.pdf: % $(MAIN)
73 sh ./markdown2pdf $< || rm -f $@
74 sh ./markdown2pdf $< || rm -f $@
74
75
75.PHONY: templates
76.PHONY: templates
@@ -88,20 +89,21 @@ $(BUILDCONF): $(CABAL)
88 $(BUILDCMD) configure --prefix=$(PREFIX)
89 $(BUILDCMD) configure --prefix=$(PREFIX)
89
90
90.PHONY: build
91.PHONY: build
92+build: $(BUILDDIR)
91−build: templates configure
93+$(BUILDDIR)/: templates configure
92 $(BUILDCMD) build
94 $(BUILDCMD) build
93
95
94.PHONY: build-exec
96.PHONY: build-exec
95−build-exec: $(BINS)
97+build-exec: $(EXECS)
96−cleanup_files+=$(BINS)
98+cleanup_files+=$(EXECS)
97−$(BINS): build
99+$(EXECS): $(BUILDDIR)
100+ for f in $@; do \
98− find $(BUILDDIR) -type f -name "$(BINS)" -perm +a=x -exec cp {} . \;
101+ find $(BUILDDIR) -type f -name "$$f" -perm +a=x -exec cp {} . \; ; \
102+ done
99
103
100.PHONY: build-doc
104.PHONY: build-doc
101−DOCS:=README.html
105+cleanup_files+=README.html
102−cleanup_files+=$(DOCS)
103build-doc: $(DOCS)
106build-doc: $(DOCS)
104−$(DOCS): build-exec
105
107
106.PHONY: build-program
108.PHONY: build-program
107build-program: build-exec build-doc
109build-program: build-exec build-doc
@@ -124,15 +126,14 @@ build-all: all build-lib-doc
124# User documents installation.
126# User documents installation.
125.PHONY: install-doc uninstall-doc
127.PHONY: install-doc uninstall-doc
126man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
128man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
127−doc_all:=$(DOCS) README BUGS TODO
128install-doc: build-doc
129install-doc: build-doc
129− $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(doc_all) $(DOCPATH)/
130+ $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
130 for f in $(man_all); do \
131 for f in $(man_all); do \
131 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
132 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
132 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
133 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
133 done
134 done
134uninstall-doc:
135uninstall-doc:
135− -for f in $(doc_all); do rm -f $(DOCPATH)/$$f; done
136+ -for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
136 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
137 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
137 -rmdir $(DOCPATH)
138 -rmdir $(DOCPATH)
138
139
@@ -146,12 +147,11 @@ uninstall-lib-doc:
146
147
147# Program only installation.
148# Program only installation.
148.PHONY: install-exec uninstall-exec
149.PHONY: install-exec uninstall-exec
149−bin_all:=$(BINS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
150install-exec: build-exec
150install-exec: build-exec
151 $(INSTALL) -d $(BINPATH); \
151 $(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
153uninstall-exec:
153uninstall-exec:
154− -for f in $(bin_all); do rm -f $(BINPATH)/$$f; done
154+ -for f in $(PROGS); do rm -f $(BINPATH)/$$f; done
155
155
156# Program + user documents installation.
156# Program + user documents installation.
157.PHONY: install-program uninstall-program
157.PHONY: install-program uninstall-program
@@ -187,13 +187,13 @@ doc_more:=README.rtf LICENSE.rtf $(osx_src)/Welcome.rtf
187osx_pkg_name:=Pandoc_$(VERSION).pkg
187osx_pkg_name:=Pandoc_$(VERSION).pkg
188cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
188cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
189osx-pkg-prep: $(osx_dest)
189osx-pkg-prep: $(osx_dest)
190−$(osx_dest)/: build-exec $(doc_more)
190+$(osx_dest)/: $(doc_more)
191 -rm -rf $(osx_dest)
191 -rm -rf $(osx_dest)
192 $(INSTALL) -d $(osx_dest)
192 $(INSTALL) -d $(osx_dest)
193 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
193 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
194 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
194 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
195 find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
195 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)
197 $(INSTALL) -d $(osx_dest)/Resources
197 $(INSTALL) -d $(osx_dest)/Resources
198 cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
198 cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
199 cp LICENSE.rtf $(osx_dest)/Resources/License.rtf
199 cp LICENSE.rtf $(osx_dest)/Resources/License.rtf
@@ -231,10 +231,10 @@ $(osx_dmg_name): $(osx_pkg_name)
231 mv Pandoc.udzo.dmg $(osx_dmg_name)
231 mv Pandoc.udzo.dmg $(osx_dmg_name)
232
232
233.PHONY: test test-markdown
233.PHONY: test test-markdown
234−test: build-exec
234+test: $(MAIN)
235− @cd tests && perl runtests.pl -s $(PWD)/$(THIS)
235+ @cd tests && perl runtests.pl -s $(PWD)/$(MAIN)
236−test-markdown: build-exec
236+test-markdown: $(MAIN)
237− @cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(THIS) -tidy
237+ @cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
238
238
239# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
239# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
240src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
240src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')