git.iko.soy/typeable/pandoc
on 1.0 help sign in
typeable/pandoc/Makefile
301 lines 9.9 kB history raw
1# Makefile for Pandoc.
3#-------------------------------------------------------------------------------
4# Constant names and commands in source tree
5#-------------------------------------------------------------------------------
6CABAL := pandoc.cabal
7SRCDIR := .
8MANDIR := man
9TESTDIR := tests
10BUILDDIR := dist
11BUILDCONF := $(BUILDDIR)/setup-config
12BUILDVARS := vars
13CONFIGURE := configure
14ODTSTYLES := odt-styles
16#-------------------------------------------------------------------------------
17# Cabal constants
18#-------------------------------------------------------------------------------
19PKG := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL) | tr A-Z a-z)
20VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL))
21PKGID := $(PKG)-$(VERSION)
22EXECSBASE := $(shell sed -ne 's/^[Ee]xecutable:\{0,1\}[[:space:]]*//p' $(CABAL))
24#-------------------------------------------------------------------------------
25# Install targets
26#-------------------------------------------------------------------------------
27WRAPPERS := html2markdown hsmarkdown markdown2pdf
28# Add .exe extensions if we're running Windows/Cygwin.
29EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
30 sed -ne 's/^cygwin.*$$/\.exe/p')
31BUILDCMD := $(addsuffix $(EXTENSION), ./setup)
32EXECS := $(addsuffix $(EXTENSION),$(EXECSBASE))
33PROGS := $(EXECS) $(WRAPPERS)
34MAIN := $(firstword $(EXECS))
35DOCS := README.html README BUGS
36MANPAGES := $(patsubst %.md,%,$(wildcard $(MANDIR)/man?/*.?.md))
38#-------------------------------------------------------------------------------
39# Variables to setup through environment
40#-------------------------------------------------------------------------------
42# Specify default values.
43prefix := /usr/local
44destdir :=
45# Attempt to set variables from a previous make session.
46-include $(BUILDVARS)
47# Fallback to defaults but allow to get the values from environment.
48PREFIX ?= $(prefix)
49DESTDIR ?= $(destdir)
50DATADIR ?= $(PKGID)
51DOCDIR ?= $(PKGID)/doc
53#-------------------------------------------------------------------------------
54# Installation paths
55#-------------------------------------------------------------------------------
56DESTPATH := $(DESTDIR)$(PREFIX)
57BINPATH := $(DESTPATH)/bin
58DATAPATH := $(DESTPATH)/share
59MANPATH := $(DATAPATH)/man
60PKGDATAPATH := $(DATAPATH)/$(DATADIR)
61PKGDOCPATH := $(DATAPATH)/$(DOCDIR)
63#-------------------------------------------------------------------------------
64# Generic Makefile variables
65#-------------------------------------------------------------------------------
66INSTALL := install -c
67INSTALL_PROGRAM := $(INSTALL) -m 755
68INSTALL_DATA := $(INSTALL) -m 644
69STRIP := strip
70GHC ?= ghc
71GHC_VERSION := $(shell $(GHC) --version | sed -e 's/[^0-9]*//')
73#-------------------------------------------------------------------------------
74# Recipes
75#-------------------------------------------------------------------------------
77# Default target.
78.PHONY: all
79all: build-program
81# Document process rules.
82%.html: % $(MAIN)
83 ./$(MAIN) -s -S --toc $< >$@ || rm -f $@
84%.tex: % $(MAIN)
85 ./$(MAIN) -s -w latex $< >$@ || rm -f $@
86%.rtf: % $(MAIN)
87 ./$(MAIN) -s -w rtf $< >$@ || rm -f $@
88%.pdf: % $(MAIN) markdown2pdf
89 sh ./markdown2pdf $< || rm -f $@
90%.txt: %
91 perl -p -e 's/\n/\r\n/' $< > $@ || rm -f $@ # convert to DOS line endings
93.PHONY: configure
94cleanup_files+=Setup.hi Setup.o $(BUILDCMD) $(BUILDVARS)
95ifdef GHC_PKG
96 hc_pkg = --with-hc-pkg=$(GHC_PKG)
97else
98 hc_pkg =
99endif
100templates=$(wildcard templates/*.* templates/headers/*.* templates/ui/default/*.*)
101configure: $(BUILDCONF)
102$(BUILDCMD): Setup.hs
103 $(GHC) -package Cabal Setup.hs -o $(BUILDCMD)
104$(BUILDCONF): $(CABAL) $(CABAL_BACKUP) $(BUILDCMD) $(templates)
105 $(BUILDCMD) configure --prefix=$(PREFIX) --with-compiler=$(GHC) $(hc_pkg) $(CABALOPTS)
106 @# Make configuration time settings persistent (definitely a hack).
107 @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
108 @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
110.PHONY: build
111build: configure
112 $(BUILDCMD) build
114.PHONY: build-exec
115build-exec: $(PROGS)
116cleanup_files+=$(EXECS)
117$(EXECS): build
118 for f in $@; do \
119 find $(BUILDDIR) -type f -name "$$f" -perm +a=x \
120 -exec ln -s -f {} . \; ; \
121 done
123.PHONY: build-doc
124cleanup_files+=README.html $(MANPAGES)
125build-doc: $(DOCS) $(MANPAGES)
127.PHONY: build-program
128build-program: build-exec build-doc
130.PHONY: build-lib-doc haddock
131build-lib-doc: html
132haddock: build-lib-doc
133cleanup_files+=html
134html/: configure
135 -rm -rf html
136 $(BUILDCMD) haddock && cp -r $(BUILDDIR)/doc/html .
138.PHONY: build-all
139build-all: build-program build-lib-doc
141# User documents installation.
142.PHONY: install-doc uninstall-doc
143man_all:=$(patsubst $(MANDIR)/%,%,$(MANPAGES))
144install-doc: build-doc
145 $(INSTALL) -d $(PKGDOCPATH) && $(INSTALL_DATA) $(DOCS) $(PKGDOCPATH)/
146 for f in $(man_all); do \
147 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
148 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
149 done
150uninstall-doc:
151 -for f in $(DOCS); do rm -f $(PKGDOCPATH)/$$f; done
152 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
153 rmdir $(PKGDOCPATH) 2>/dev/null ||:
155# Program only installation.
156.PHONY: install-exec uninstall-exec
157install-exec: build-exec
158 $(STRIP) $(EXECS)
159 $(INSTALL) -d $(BINPATH); \
160 for f in $(PROGS); do \
161 if [ -L $$f ]; then \
162 f=$$(readlink $$f); \
163 fi; \
164 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
165 done
166uninstall-exec:
167 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done
169# Program + user documents installation.
170.PHONY: install-program uninstall-program
171install-program: install-exec install-doc
172uninstall-program: uninstall-exec uninstall-doc
174.PHONY: install-all uninstall-all
175# Full installation through Cabal: main + wrappers + user docs + lib + lib docs
176install-all: build-all install-program
177 destdir=$(DESTDIR); \
178 # Older Cabal versions have no '--destdir' option.
179 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
180 opt="--destdir=$${destdir-/}"; \
181 else \
182 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
183 fi; \
184 $(BUILDCMD) copy $$opt; $(BUILDCMD) register
185# Cabal lacks an 'uninstall' command. We have to remove some cruft manually.
186uninstall-all: uninstall-program configure
187 @libdir=$$($(GHC_PKG) field $(PKGID) library-dirs 2>/dev/null | \
188 sed 's/^library-dirs: *//'); \
189 htmldir=$$($(GHC_PKG) field $(PKGID) haddock-html 2>/dev/null | \
190 sed 's/^haddock-html: *//'); \
191 if [ -d $$libdir ]; then \
192 $(BUILDCMD) unregister ||:; \
193 else \
194 echo >&2 "*** Couldn't locate library for pkgid: $(PKGID). ***"; \
195 fi; \
196 for d in $$libdir $$htmldir; do \
197 [ -d $$d ] && { \
198 rm -rf $$d; rmdir $$(dirname $$d) 2>/dev/null ||:; \
199 } \
200 done; \
201 rmdir $(PKGDOCPATH) $(PKGDATAPATH) 2>/dev/null ||:
203# Default installation recipe for a common deployment scenario.
204.PHONY: install uninstall
205install: install-program
206uninstall: uninstall-program
208# FreeBSD port
209.PHONY: freebsd
210freebsd_dest:=freebsd
211freebsd_makefile:=$(freebsd_dest)/Makefile
212freebsd_template:=$(freebsd_makefile).in
213cleanup_files+=$(freebsd_makefile)
214freebsd : $(freebsd_makefile)
215$(freebsd_makefile) : $(freebsd_template)
216 sed -e 's/@VERSION@/$(VERSION)/' $< > $@
218# MacPort
219.PHONY: macport
220macport_dest:=macports
221portfile:=$(macport_dest)/Portfile
222portfile_template:=$(portfile).in
223cleanup_files+=$(portfile)
224macport : $(portfile)
225$(portfile) : $(portfile_template) tarball
226 sed -e 's/@VERSION@/$(VERSION)/' $(portfile_template) | \
227 sed -e 's/@TARBALLMD5SUM@/$(word 2, $(shell openssl md5 $(tarball)))/' > \
228 $(portfile)
230.PHONY: win-pkg
231win_pkg_name:=$(PKGID).zip
232win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
233cleanup_files+=$(win_pkg_name) $(win_docs)
234win-pkg: $(win_pkg_name)
235$(win_pkg_name): $(PKG).exe $(win_docs)
236 zip -r $(win_pkg_name) $(PKG).exe $(win_docs)
238.PHONY: test test-markdown
239test: $(MAIN)
240 $(BUILDCMD) test
241compat:=$(PWD)/hsmarkdown
242markdown_test_dirs:=$(wildcard $(TESTDIR)/MarkdownTest_*)
243test-markdown: $(MAIN) $(compat)
244 @for suite in $(markdown_test_dirs); do \
245 ( \
246 suite_version=$$(echo $$suite | sed -e 's/.*_//');\
247 echo >&2 "-----------------------------------------";\
248 echo >&2 "Running Markdown test suite version $${suite_version}.";\
249 PATH=$(PWD):$$PATH; export PATH; cd $$suite && \
250 perl MarkdownTest.pl -s $(compat) -tidy ; \
251 ) \
252 done
254# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
255src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
256cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
257tags: $(src_all)
258 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
259 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
261.PHONY: tarball
262tarball:=$(PKGID).tar.gz
263cleanup_files+=$(tarball)
264tarball: $(tarball)
265$(tarball):
266 $(BUILDCMD) sdist
267 cp $(BUILDDIR)/$(tarball) .
269.PHONY: website
270web_src:=web
271web_dest:=pandoc-website
272make_page:=./$(MAIN) -s -S -B $(web_src)/header.html \
273 -A $(web_src)/footer.html \
274 -H $(web_src)/css
275cleanup_files+=$(web_dest)
276$(web_dest) : html $(wildcard $(web_src)/*) changelog \
277 INSTALL $(MANPAGES) $(MANDIR)/man1/pandoc.1.md README
278 rm -rf $(web_dest) && { \
279 mkdir $(web_dest); \
280 cp -r html $(web_dest)/doc; \
281 cp $(web_src)/* $(web_dest)/; \
282 sed -e 's#@VERSION@#$(VERSION)#g' $(web_src)/index.txt.in > \
283 $(web_dest)/index.txt; \
284 cp changelog $(web_dest)/changelog.txt ; \
285 cp README $(web_dest)/ ; \
286 cp INSTALL $(web_dest)/ ; \
287 cp $(MANDIR)/man1/pandoc.1.md $(web_dest)/ ; \
288 cp $(MANPAGES) $(web_dest)/ ; \
289 } || { rm -rf $(web_dest); exit 1; }
290website: $(MAIN) $(web_dest)
291 PANDOC_PATH=$(shell pwd) make -C $(web_dest)
293.PHONY: distclean clean
294distclean: clean
295 if [ -d debian ]; then \
296 chmod +x debian/rules; fakeroot debian/rules clean; \
297 fi
299clean:
300 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
301 -rm -rf $(cleanup_files)