git.iko.soy/typeable/pandoc
on 339fcbb help sign in
typeable/pandoc/Makefile
390 lines 13 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 := .setup-config
12BUILDCMD := runhaskell Setup.hs
13BUILDVARS := vars
14CONFIGURE := configure
16#-------------------------------------------------------------------------------
17# Cabal constants
18#-------------------------------------------------------------------------------
19NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
20THIS := $(shell echo $(NAME) | tr A-Z a-z)
21VERSION := $(shell sed -ne 's/^version[[:space:]]*=[[:space:]]*"\([^"]*\)"/\1/p' $(SRCDIR)/Main.hs)
22RELNAME := $(THIS)-$(VERSION)
23EXECSBASE := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
25#-------------------------------------------------------------------------------
26# Install targets
27#-------------------------------------------------------------------------------
28WRAPPERS := html2markdown markdown2pdf hsmarkdown
29# Add .exe extensions if we're running Windows/Cygwin.
30EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
31 sed -ne 's/^cygwin.*$$/\.exe/p')
32EXECS := $(addsuffix $(EXTENSION),$(EXECSBASE))
33PROGS := $(EXECS) $(WRAPPERS)
34# First entry in Cabal's executable stanza is the main executable.
35MAIN := $(firstword $(EXECS))
36DOCS := README.html README BUGS
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)
51#-------------------------------------------------------------------------------
52# Installation paths
53#-------------------------------------------------------------------------------
54DESTPATH := $(DESTDIR)$(PREFIX)
55BINPATH := $(DESTPATH)/bin
56DATAPATH := $(DESTPATH)/share
57LIBPATH := $(DESTPATH)/$(NAME)-$(VERSION)
58DOCPATH := $(DATAPATH)/doc/$(THIS)
59LIBDOCPATH := $(DATAPATH)/doc/$(THIS)-doc
60MANPATH := $(DATAPATH)/man
61PKGPATH := $(DATAPATH)/$(THIS)
63#-------------------------------------------------------------------------------
64# Generic Makefile variables
65#-------------------------------------------------------------------------------
66INSTALL := install -c
67INSTALL_PROGRAM := $(INSTALL) -m 755
68INSTALL_DATA := $(INSTALL) -m 644
69STRIP := strip
70GHC := ghc
71GHC_PKG := ghc-pkg
73#-------------------------------------------------------------------------------
74# Recipes
75#-------------------------------------------------------------------------------
77# Default target.
78.PHONY: all
79all: build-program
81# Document process rules.
82%.html: % $(MAIN)
83 ./$(MAIN) -s $< >$@ || 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: templates
94templates: $(SRCDIR)/templates
95 $(MAKE) -C $(SRCDIR)/templates
97define generate-shell-script
98echo "Generating $@..."; \
99awk ' \
100 /^[ \t]*###+ / { \
101 lead = $$0; sub(/[^ \t].*$$/, "", lead); \
102 t = "$(dir $<)/"$$2; \
103 while (getline line < t > 0) \
104 print lead line; \
105 next; \
106 } \
107 { print } \
108' <$< >$@
109chmod +x $@
110endef
112.PHONY: wrappers
113wrappers: $(WRAPPERS)
114wrapper_deps := $(wildcard $(SRCDIR)/wrappers/*.sh)
115cleanup_files+=$(WRAPPERS)
116%: $(SRCDIR)/wrappers/%.in $(wrapper_deps)
117 @$(generate-shell-script)
119cleanup_files+=$(CABAL)
120$(CABAL): cabalize $(CABAL).in $(SRCDIR)/Main.hs
121 ./cabalize <$(CABAL).in >$(CABAL)
123.PHONY: configure
124cleanup_files+=$(BUILDDIR) $(BUILDCONF) $(BUILDVARS)
125configure: $(BUILDCONF) templates
126$(BUILDCONF): $(CABAL)
127 $(BUILDCMD) configure --prefix=$(PREFIX)
128 # Make configuration time settings persistent (definitely a hack).
129 @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
130 @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
132.PHONY: build
133build: configure
134 $(BUILDCMD) build
136.PHONY: build-exec
137build-exec: $(PROGS)
138cleanup_files+=$(EXECS)
139$(EXECS): build
140 for f in $@; do \
141 [ -f $$f ] || { \
142 find $(BUILDDIR) -type f -name "$$f" \
143 -perm +a=x -exec ln -s {} . \; ; \
144 } \
145 done
147.PHONY: build-doc
148cleanup_files+=README.html
149build-doc: $(DOCS)
151.PHONY: build-program
152build-program: build-exec build-doc
154.PHONY: build-lib-doc haddock
155build-lib-doc: html
156haddock: build-lib-doc
157cleanup_files+=html
158html/: configure
159 -rm -rf html
160 $(BUILDCMD) haddock && mv $(BUILDDIR)/doc/html .
162.PHONY: build-all
163build-all: build-program build-lib-doc
165# User documents installation.
166.PHONY: install-doc uninstall-doc
167man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
168install-doc: build-doc
169 $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
170 for f in $(man_all); do \
171 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
172 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
173 done
174uninstall-doc:
175 -for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
176 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
177 -rmdir $(DOCPATH)
179# Library documents installation.
180.PHONY: install-lib-doc uninstall-lib-doc
181install-lib-doc: build-lib-doc
182 $(INSTALL) -d $(LIBDOCPATH) && cp -a html $(LIBDOCPATH)/
183uninstall-lib-doc:
184 -rm -rf $(LIBDOCPATH)/html
185 -rmdir $(LIBDOCPATH)
187# Program only installation.
188.PHONY: install-exec uninstall-exec
189install-exec: build-exec
190 $(INSTALL) -d $(BINPATH); \
191 for f in $(PROGS); do \
192 if [ -L $$f ]; then \
193 f=$$(readlink $$f); \
194 fi; \
195 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
196 done
197uninstall-exec:
198 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done ;
200# Program + user documents installation.
201.PHONY: install-program uninstall-program
202install-program: install-exec install-doc
203uninstall-program: uninstall-exec uninstall-doc
205# Install everything.
206.PHONY: install-all uninstall-all
207install-all: install-doc install-lib-doc
208 destdir=$(DESTDIR); \
209 # Older Cabal versions have no '--destdir' option.
210 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
211 opt="--destdir=$${destdir-/}"; \
212 else \
213 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
214 fi; \
215 $(BUILDCMD) copy $$opt; \
216 $(BUILDCMD) register
217uninstall-all: uninstall-exec uninstall-doc uninstall-lib-doc
218 -pkg_id="$(NAME)-$(VERSION)"; \
219 libdir=$$($(GHC_PKG) field $$pkg_id library-dirs 2>/dev/null | \
220 sed 's/^library-dirs: *//'); \
221 if [ -d "$$libdir" ]; then \
222 $(BUILDCMD) unregister; \
223 rm -rf $$libdir; \
224 rmdir $$(dirname $$libdir); \
225 else \
226 echo "*** Couldn't locate library files for pkgid: $$pkg_id. ***"; \
227 fi
229# Default installation recipe for a common deployment scenario.
230.PHONY: install uninstall
231install: install-program
232uninstall: uninstall-program
234# OSX packages: make osx-pkg-prep, then (as root) make osx-pkg
235.PHONY: osx-pkg osx-pkg-prep
236osx_dest:=osx-pkg-tmp
237osx_src:=osx
238doc_more:=README.rtf COPYRIGHT.rtf $(osx_src)/Welcome.rtf
239osx_pkg_name:=$(RELNAME).pkg
240cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
241osx-pkg-prep: $(osx_dest)
242$(osx_dest)/: build-program $(doc_more)
243 -rm -rf $(osx_dest)
244 $(INSTALL) -d $(osx_dest)
245 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
246 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
247 find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
248 find $(osx_dest) -type f -regex ".*bin/$(notdir $(MAIN))" | xargs $(STRIP)
249 $(INSTALL) -d $(osx_dest)/Resources
250 cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
251 cp COPYRIGHT.rtf $(osx_dest)/Resources/License.rtf
252 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome.rtf > $(osx_dest)/Resources/Welcome.rtf
253 sed -e 's/@VERSION@/$(VERSION)/g' $(osx_src)/Info.plist > $(osx_dest)/Info.plist
254 cp $(osx_src)/Description.plist $(osx_dest)/
255osx-pkg: $(osx_pkg_name)
256$(osx_pkg_name)/: $(osx_dest)
257 if [ "`id -u`" != 0 ]; then \
258 echo "Root permissions needed to create OSX package!"; \
259 exit 1; \
260 fi
261 find $(osx_dest) | xargs chown root:wheel
262 PackageMaker -build -p $(osx_pkg_name) \
263 -f $(osx_dest)/Package_root \
264 -r $(osx_dest)/Resources \
265 -i $(osx_dest)/Info.plist \
266 -d $(osx_dest)/Description.plist
267 chgrp admin $(osx_pkg_name)
268 -rm -rf $(osx_dest)
270.PHONY: osx-dmg
271osx_dmg_name:=$(RELNAME).dmg
272cleanup_files+=$(osx_dmg_name)
273osx_udzo_name:=$(RELNAME).udzo.dmg
274osx_dmg_volume:="$(NAME) $(VERSION)"
275osx-dmg: $(osx_dmg_name)
276$(osx_dmg_name): $(osx_pkg_name)
277 -rm -f $(osx_dmg_name)
278 hdiutil create $(osx_dmg_name) -size 05m -fs HFS+ -volname $(osx_dmg_volume)
279 dev_handle=`hdid $(osx_dmg_name) | grep Apple_HFS | \
280 perl -e '\$$_=<>; /^\\/dev\\/(disk.)/; print \$$1'`; \
281 ditto $(osx_pkg_name) /Volumes/$(osx_dmg_volume)/$(osx_pkg_name); \
282 hdiutil detach $$dev_handle
283 hdiutil convert $(osx_dmg_name) -format UDZO -o $(osx_udzo_name)
284 -rm -f $(osx_dmg_name)
285 mv $(osx_udzo_name) $(osx_dmg_name)
288.PHONY: win-pkg
289win_pkg_name:=$(RELNAME).zip
290win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
291cleanup_files+=$(win_pkg_name) $(win_docs)
292win-pkg: $(win_pkg_name)
293$(win_pkg_name): $(THIS).exe $(win_docs)
294 zip -r $(win_pkg_name) $(THIS).exe $(win_docs)
296.PHONY: test test-markdown
297test: $(MAIN)
298 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
299strict:=$(MAIN)-strict
300cleanup_files+=$(strict)
301$(strict): $(MAIN)
302 echo "#!/bin/sh -e\n$(PWD)/$(MAIN) --strict \"\$$@\"" > $@; \
303 chmod +x $(strict)
304test-markdown: $(strict)
305 @cd $(TESTDIR)/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(strict) -tidy
307# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
308src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
309cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
310tags: $(src_all)
311 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
312 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
314.PHONY: tarball
315tarball_name:=$(RELNAME).tar.gz
316cleanup_files+=$(tarball_name)
317tarball: $(tarball_name)
318$(tarball_name):
319 svn export . $(RELNAME)
320 tar cvzf $(tarball_name) $(RELNAME)
321 -rm -rf $(fullname)
323.PHONY: deb
324deb_name:=$(shell grep ^Package debian/control | cut -d' ' -f2 | head -n 1)
325deb_version:=$(shell head -n 1 debian/changelog | cut -f2 -d' ' | tr -d '()')
326deb_arch:=i386
327deb_main:=$(deb_name)_$(deb_version)_$(deb_arch).deb
328deb: debian
329 @[ -x /usr/bin/fakeroot ] || { \
330 echo "*** Please install fakeroot package. ***"; \
331 exit 1; \
332 }
333 @[ -x /usr/bin/dpkg-buildpackage ] || { \
334 echo "*** Please install dpkg-dev package. ***"; \
335 exit 1; \
336 }
337 if [ -x /usr/bin/debuild ]; then \
338 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
339 else \
340 echo "*** Please install devscripts package. ***"; \
341 echo "*** Using dpkg-buildpackage for package building. ***"; \
342 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
343 fi
345.PHONY: website
346web_src:=web
347web_dest:=web/pandoc
348make_page:=./$(MAIN) -s -B $(web_src)/header.html \
349 -A $(web_src)/footer.html \
350 -H $(web_src)/css
351cleanup_files+=$(web_dest)
352website: $(web_dest)
353$(web_dest)/: $(MAIN) html
354 -rm -rf $(web_dest)
355 ( \
356 mkdir $(web_dest); \
357 cp -r html $(web_dest)/doc; \
358 cp $(web_src)/*.css $(web_dest)/; \
359 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome | \
360 $(make_page) > $(web_dest)/osx-notes.html; \
361 sed -e '/^ --.*/d' -e 's#^# #g' changelog | \
362 sed -e 's/ \(pandoc (.*\)/## \1/g' | \
363 $(make_page) -T "Pandoc changelog" > $(web_dest)/changelog.html; \
364 $(make_page) README > $(web_dest)/README.html; \
365 $(make_page) INSTALL > $(web_dest)/INSTALL.html; \
366 sed -e 's/@TARBALL_NAME@/$(tarball_name)/g' $(web_src)/index.txt | \
367 sed -e 's/@OSX_DMG_NAME@/$(osx_dmg_name)/g' | \
368 sed -e 's/@WINDOWS_PKG_NAME@/$(win_pkg_name)/g' | \
369 sed -e 's/@VERSION@/$(VERSION)/g' | \
370 $(make_page) > $(web_dest)/index.html; \
371 cp README $(web_dest)/ ; \
372 ./$(MAIN) -s -w latex README > $(web_dest)/README.tex ; \
373 cp $(web_src)/myheader.tex $(web_dest)/ ; \
374 cp $(web_src)/S5DEMO $(web_dest)/ ; \
375 cp $(web_src)/header.html $(web_dest)/ ; \
376 cp $(web_src)/footer.html $(web_dest)/ ; \
377 sh $(web_src)/mkdemos.sh $(web_dest) $(abspath .) | \
378 $(make_page) > $(web_dest)/examples.html; \
379 ) || { rm -rf $(web_dest); exit 1; }
381.PHONY: distclean clean
382distclean: clean
383 if [ -d debian ]; then \
384 chmod +x debian/rules; fakeroot debian/rules clean; \
385 fi
387clean:
388 make -C $(SRCDIR)/templates clean
389 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
390 -rm -rf $(cleanup_files)