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