git.iko.soy/typeable/pandoc
on f99cedd help sign in
typeable/pandoc/Makefile
406 lines 14 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)
114cleanup_files+=$(WRAPPERS)
115$(WRAPPERS): %: $(SRCDIR)/wrappers/%.in $(SRCDIR)/wrappers/*.sh
116 @$(generate-shell-script)
118cleanup_files+=$(CABAL)
119$(CABAL): cabalize $(CABAL).in $(SRCDIR)/Main.hs
120 ./cabalize <$(CABAL).in >$(CABAL)
122.PHONY: configure
123cleanup_files+=$(BUILDDIR) $(BUILDCONF) $(BUILDVARS)
124configure: $(BUILDCONF) templates
125$(BUILDCONF): $(CABAL)
126 $(BUILDCMD) configure --prefix=$(PREFIX)
127 # Make configuration time settings persistent (definitely a hack).
128 @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
129 @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
131.PHONY: build
132build: configure
133 $(BUILDCMD) build
135.PHONY: build-exec
136build-exec: $(PROGS)
137cleanup_files+=$(EXECS)
138$(EXECS): build
139 for f in $@; do \
140 [ -f $$f ] || { \
141 find $(BUILDDIR) -type f -name "$$f" \
142 -perm +a=x -exec ln -s {} . \; ; \
143 } \
144 done
146.PHONY: build-doc
147cleanup_files+=README.html
148build-doc: $(DOCS)
150.PHONY: build-program
151build-program: build-exec build-doc
153.PHONY: build-lib-doc haddock
154build-lib-doc: html
155haddock: build-lib-doc
156cleanup_files+=html
157html/: configure
158 -rm -rf html
159 $(BUILDCMD) haddock && mv $(BUILDDIR)/doc/html .
161.PHONY: build-all
162build-all: build-program build-lib-doc
164# User documents installation.
165.PHONY: install-doc uninstall-doc
166man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
167install-doc: build-doc
168 $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
169 for f in $(man_all); do \
170 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
171 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
172 done
173uninstall-doc:
174 -for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
175 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
176 -rmdir $(DOCPATH)
178# Library documents installation.
179.PHONY: install-lib-doc uninstall-lib-doc
180install-lib-doc: build-lib-doc
181 $(INSTALL) -d $(LIBDOCPATH) && cp -R html $(LIBDOCPATH)/
182uninstall-lib-doc:
183 -rm -rf $(LIBDOCPATH)/html
184 -rmdir $(LIBDOCPATH)
186# Helper to install the given files $(1) into the path $(2).
187# It also has the ability to follow symlinks.
188install-executable-files = \
189 $(INSTALL) -d $(2); \
190 for f in $(1); do \
191 if [ -L $$f ]; then \
192 f=$$(readlink $$f); \
193 fi; \
194 $(INSTALL_PROGRAM) $$f $(2)/; \
195 done
197# Program only installation.
198.PHONY: install-exec uninstall-exec
199install-exec: build-exec
200 $(STRIP) $(EXECS)
201 $(call install-executable-files,$(PROGS),$(BINPATH))
202uninstall-exec:
203 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done ;
205# Program + user documents installation.
206.PHONY: install-program uninstall-program
207install-program: install-exec install-doc
208uninstall-program: uninstall-exec uninstall-doc
210# Install everything.
211.PHONY: install-all uninstall-all
212install-all: build-exec install-doc install-lib-doc
213 # Install the library (+ main executable) and register it.
214 destdir=$(DESTDIR); \
215 # Older Cabal versions have no '--destdir' option.
216 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
217 opt="--destdir=$${destdir-/}"; \
218 else \
219 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
220 fi; \
221 $(BUILDCMD) copy $$opt; \
222 $(BUILDCMD) register
223 # Note that, we are in the position of having to install the wrappers
224 # separately, as Cabal installs the main exec along with the library.
225 $(call install-executable-files,$(WRAPPERS),$(BINPATH))
226uninstall-all: uninstall-exec uninstall-doc uninstall-lib-doc
227 -pkg_id="$(NAME)-$(VERSION)"; \
228 libdir=$$($(GHC_PKG) field $$pkg_id library-dirs 2>/dev/null | \
229 sed 's/^library-dirs: *//'); \
230 if [ -d "$$libdir" ]; then \
231 $(BUILDCMD) unregister; \
232 rm -rf $$libdir; \
233 rmdir $$(dirname $$libdir); \
234 else \
235 echo "*** Couldn't locate library files for pkgid: $$pkg_id. ***"; \
236 fi
238# Default installation recipe for a common deployment scenario.
239.PHONY: install uninstall
240install: install-program
241uninstall: uninstall-program
243# OSX packages: make osx-pkg-prep, then (as root) make osx-pkg
244.PHONY: osx-pkg osx-pkg-prep
245osx_dest:=osx-pkg-tmp
246osx_src:=osx
247doc_more:=README.rtf COPYRIGHT.rtf $(osx_src)/Welcome.rtf
248osx_pkg_name:=$(RELNAME).pkg
249cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
250osx-pkg-prep: $(osx_dest)
251$(osx_dest)/: build-program $(doc_more)
252 -rm -rf $(osx_dest)
253 $(INSTALL) -d $(osx_dest)
254 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
255 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
256 find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
257 find $(osx_dest) -type f -regex ".*bin/$(notdir $(MAIN))" | xargs $(STRIP)
258 $(INSTALL) -d $(osx_dest)/Resources
259 cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
260 cp COPYRIGHT.rtf $(osx_dest)/Resources/License.rtf
261 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome.rtf > $(osx_dest)/Resources/Welcome.rtf
262 sed -e 's/@VERSION@/$(VERSION)/g' $(osx_src)/Info.plist > $(osx_dest)/Info.plist
263 cp $(osx_src)/Description.plist $(osx_dest)/
264osx-pkg: $(osx_pkg_name)
265$(osx_pkg_name)/: $(osx_dest)
266 if [ "`id -u`" != 0 ]; then \
267 echo "Root permissions needed to create OSX package!"; \
268 exit 1; \
269 fi
270 find $(osx_dest) | xargs chown root:wheel
271 PackageMaker -build -p $(osx_pkg_name) \
272 -f $(osx_dest)/Package_root \
273 -r $(osx_dest)/Resources \
274 -i $(osx_dest)/Info.plist \
275 -d $(osx_dest)/Description.plist
276 chgrp admin $(osx_pkg_name)
277 -rm -rf $(osx_dest)
279.PHONY: osx-dmg
280osx_dmg_name:=$(RELNAME).dmg
281cleanup_files+=$(osx_dmg_name)
282osx_udzo_name:=$(RELNAME).udzo.dmg
283osx_dmg_volume:="$(NAME) $(VERSION)"
284osx-dmg: $(osx_dmg_name)
285$(osx_dmg_name): $(osx_pkg_name)
286 -rm -f $(osx_dmg_name)
287 hdiutil create $(osx_dmg_name) -size 05m -fs HFS+ -volname $(osx_dmg_volume)
288 dev_handle=`hdid $(osx_dmg_name) | grep Apple_HFS | \
289 perl -e '\$$_=<>; /^\\/dev\\/(disk.)/; print \$$1'`; \
290 ditto $(osx_pkg_name) /Volumes/$(osx_dmg_volume)/$(osx_pkg_name); \
291 hdiutil detach $$dev_handle
292 hdiutil convert $(osx_dmg_name) -format UDZO -o $(osx_udzo_name)
293 -rm -f $(osx_dmg_name)
294 mv $(osx_udzo_name) $(osx_dmg_name)
297.PHONY: win-pkg
298win_pkg_name:=$(RELNAME).zip
299win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
300cleanup_files+=$(win_pkg_name) $(win_docs)
301win-pkg: $(win_pkg_name)
302$(win_pkg_name): $(THIS).exe $(win_docs)
303 zip -r $(win_pkg_name) $(THIS).exe $(win_docs)
305.PHONY: test test-markdown
306test: $(MAIN)
307 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
308compat:=$(PWD)/hsmarkdown
309markdown_test_dirs:=$(wildcard $(TESTDIR)/MarkdownTest_*)
310test-markdown: $(MAIN) $(compat)
311 @for suite in $(markdown_test_dirs); do \
312 ( \
313 suite_version=$$(echo $$suite | sed -e 's/.*_//');\
314 echo "-----------------------------------------";\
315 echo "Running Markdown test suite version $${suite_version}.";\
316 PATH=$(PWD):$$PATH; export PATH; cd $$suite && \
317 perl MarkdownTest.pl -s $(compat) -tidy ; \
318 ) \
319 done
321# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
322src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
323cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
324tags: $(src_all)
325 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
326 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
328.PHONY: tarball
329tarball_name:=$(RELNAME).tar.gz
330cleanup_files+=$(tarball_name)
331tarball: $(tarball_name)
332$(tarball_name):
333 svn export . $(RELNAME)
334 tar cvzf $(tarball_name) $(RELNAME)
335 -rm -rf $(fullname)
337.PHONY: deb
338deb_name:=$(shell grep ^Package debian/control | cut -d' ' -f2 | head -n 1)
339deb_version:=$(shell head -n 1 debian/changelog | cut -f2 -d' ' | tr -d '()')
340deb_arch:=i386
341deb_main:=$(deb_name)_$(deb_version)_$(deb_arch).deb
342deb: debian
343 @[ -x /usr/bin/fakeroot ] || { \
344 echo "*** Please install fakeroot package. ***"; \
345 exit 1; \
346 }
347 @[ -x /usr/bin/dpkg-buildpackage ] || { \
348 echo "*** Please install dpkg-dev package. ***"; \
349 exit 1; \
350 }
351 if [ -x /usr/bin/debuild ]; then \
352 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
353 else \
354 echo "*** Please install devscripts package. ***"; \
355 echo "*** Using dpkg-buildpackage for package building. ***"; \
356 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
357 fi
359.PHONY: website
360web_src:=web
361web_dest:=web/pandoc
362make_page:=./$(MAIN) -s -S -B $(web_src)/header.html \
363 -A $(web_src)/footer.html \
364 -H $(web_src)/css
365cleanup_files+=$(web_dest)
366website: $(MAIN) html
367 -rm -rf $(web_dest)
368 ( \
369 mkdir $(web_dest); \
370 cp -r html $(web_dest)/doc; \
371 cp $(web_src)/*.css $(web_dest)/; \
372 cp $(web_src)/css $(web_dest)/; \
373 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome > \
374 $(web_dest)/osx-notes.txt; \
375 sed -e '/^ --.*/d' -e 's#^# #g' changelog | \
376 sed -e 's/ \(pandoc (.*\)/## \1/g' > \
377 $(web_dest)/changelog.txt; \
378 cp README $(web_dest)/ ; \
379 cp INSTALL $(web_dest)/ ; \
380 sed -e 's/@TARBALL_NAME@/$(tarball_name)/g' $(web_src)/index.txt | \
381 sed -e 's/@OSX_DMG_NAME@/$(osx_dmg_name)/g' | \
382 sed -e 's/@WINDOWS_PKG_NAME@/$(win_pkg_name)/g' | \
383 sed -e 's/@VERSION@/$(VERSION)/g' > $(web_dest)/index.txt; \
384 cp $(web_src)/features.txt $(web_dest)/ ; \
385 cp $(web_src)/myheader.tex $(web_dest)/ ; \
386 cp $(web_src)/S5DEMO $(web_dest)/ ; \
387 cp $(web_src)/header.html $(web_dest)/ ; \
388 cp $(web_src)/footer.html $(web_dest)/ ; \
389 cp $(web_src)/mkdemos.pl $(web_dest)/ ; \
390 cp $(web_src)/demos $(web_dest)/ ; \
391 cp $(web_src)/docbook.css $(web_dest)/ ; \
392 cp $(web_src)/config.xsl $(web_dest)/ ; \
393 cp $(web_src)/Makefile $(web_dest)/ ; \
394 PANDOC_PATH=$(shell pwd) make -C $(web_dest) ; \
395 ) || { rm -rf $(web_dest); exit 1; }
397.PHONY: distclean clean
398distclean: clean
399 if [ -d debian ]; then \
400 chmod +x debian/rules; fakeroot debian/rules clean; \
401 fi
403clean:
404 make -C $(SRCDIR)/templates clean
405 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
406 -rm -rf $(cleanup_files)