git.iko.soy/typeable/pandoc
on 39eb8cb help sign in
typeable/pandoc/Makefile
393 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)
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 -a html $(LIBDOCPATH)/
182uninstall-lib-doc:
183 -rm -rf $(LIBDOCPATH)/html
184 -rmdir $(LIBDOCPATH)
186# Program only installation.
187.PHONY: install-exec uninstall-exec
188install-exec: build-exec
189 $(INSTALL) -d $(BINPATH); \
190 for f in $(PROGS); do \
191 if [ -L $$f ]; then \
192 f=$$(readlink $$f); \
193 fi; \
194 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
195 done
196uninstall-exec:
197 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done ;
199# Program + user documents installation.
200.PHONY: install-program uninstall-program
201install-program: install-exec install-doc
202uninstall-program: uninstall-exec uninstall-doc
204# Install everything.
205.PHONY: install-all uninstall-all
206install-all: install-doc install-lib-doc
207 destdir=$(DESTDIR); \
208 # Older Cabal versions have no '--destdir' option.
209 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
210 opt="--destdir=$${destdir-/}"; \
211 else \
212 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
213 fi; \
214 $(BUILDCMD) copy $$opt; \
215 $(BUILDCMD) register
216uninstall-all: uninstall-exec uninstall-doc uninstall-lib-doc
217 -pkg_id="$(NAME)-$(VERSION)"; \
218 libdir=$$($(GHC_PKG) field $$pkg_id library-dirs 2>/dev/null | \
219 sed 's/^library-dirs: *//'); \
220 if [ -d "$$libdir" ]; then \
221 $(BUILDCMD) unregister; \
222 rm -rf $$libdir; \
223 rmdir $$(dirname $$libdir); \
224 else \
225 echo "*** Couldn't locate library files for pkgid: $$pkg_id. ***"; \
226 fi
228# Default installation recipe for a common deployment scenario.
229.PHONY: install uninstall
230install: install-program
231uninstall: uninstall-program
233# OSX packages: make osx-pkg-prep, then (as root) make osx-pkg
234.PHONY: osx-pkg osx-pkg-prep
235osx_dest:=osx-pkg-tmp
236osx_src:=osx
237doc_more:=README.rtf COPYRIGHT.rtf $(osx_src)/Welcome.rtf
238osx_pkg_name:=$(RELNAME).pkg
239cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
240osx-pkg-prep: $(osx_dest)
241$(osx_dest)/: build-program $(doc_more)
242 -rm -rf $(osx_dest)
243 $(INSTALL) -d $(osx_dest)
244 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
245 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
246 find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
247 find $(osx_dest) -type f -regex ".*bin/$(notdir $(MAIN))" | xargs $(STRIP)
248 $(INSTALL) -d $(osx_dest)/Resources
249 cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
250 cp COPYRIGHT.rtf $(osx_dest)/Resources/License.rtf
251 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome.rtf > $(osx_dest)/Resources/Welcome.rtf
252 sed -e 's/@VERSION@/$(VERSION)/g' $(osx_src)/Info.plist > $(osx_dest)/Info.plist
253 cp $(osx_src)/Description.plist $(osx_dest)/
254osx-pkg: $(osx_pkg_name)
255$(osx_pkg_name)/: $(osx_dest)
256 if [ "`id -u`" != 0 ]; then \
257 echo "Root permissions needed to create OSX package!"; \
258 exit 1; \
259 fi
260 find $(osx_dest) | xargs chown root:wheel
261 PackageMaker -build -p $(osx_pkg_name) \
262 -f $(osx_dest)/Package_root \
263 -r $(osx_dest)/Resources \
264 -i $(osx_dest)/Info.plist \
265 -d $(osx_dest)/Description.plist
266 chgrp admin $(osx_pkg_name)
267 -rm -rf $(osx_dest)
269.PHONY: osx-dmg
270osx_dmg_name:=$(RELNAME).dmg
271cleanup_files+=$(osx_dmg_name)
272osx_udzo_name:=$(RELNAME).udzo.dmg
273osx_dmg_volume:="$(NAME) $(VERSION)"
274osx-dmg: $(osx_dmg_name)
275$(osx_dmg_name): $(osx_pkg_name)
276 -rm -f $(osx_dmg_name)
277 hdiutil create $(osx_dmg_name) -size 05m -fs HFS+ -volname $(osx_dmg_volume)
278 dev_handle=`hdid $(osx_dmg_name) | grep Apple_HFS | \
279 perl -e '\$$_=<>; /^\\/dev\\/(disk.)/; print \$$1'`; \
280 ditto $(osx_pkg_name) /Volumes/$(osx_dmg_volume)/$(osx_pkg_name); \
281 hdiutil detach $$dev_handle
282 hdiutil convert $(osx_dmg_name) -format UDZO -o $(osx_udzo_name)
283 -rm -f $(osx_dmg_name)
284 mv $(osx_udzo_name) $(osx_dmg_name)
287.PHONY: win-pkg
288win_pkg_name:=$(RELNAME).zip
289win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
290cleanup_files+=$(win_pkg_name) $(win_docs)
291win-pkg: $(win_pkg_name)
292$(win_pkg_name): $(THIS).exe $(win_docs)
293 zip -r $(win_pkg_name) $(THIS).exe $(win_docs)
295.PHONY: test test-markdown
296test: $(MAIN)
297 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
298compat:=$(PWD)/hsmarkdown
299markdown_test_dirs:=$(wildcard $(TESTDIR)/MarkdownTest_*)
300test-markdown: $(MAIN) $(compat)
301 @for suite in $(markdown_test_dirs); do \
302 ( \
303 suite_version=$$(echo $$suite | sed -e 's/.*_//');\
304 echo "\nRunning Markdown test suite version $${suite_version}.";\
305 PATH=$(PWD):$$PATH; export PATH; cd $$suite && \
306 perl MarkdownTest.pl -s $(compat) -tidy ; \
307 ) \
308 done
310# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
311src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
312cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
313tags: $(src_all)
314 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
315 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
317.PHONY: tarball
318tarball_name:=$(RELNAME).tar.gz
319cleanup_files+=$(tarball_name)
320tarball: $(tarball_name)
321$(tarball_name):
322 svn export . $(RELNAME)
323 tar cvzf $(tarball_name) $(RELNAME)
324 -rm -rf $(fullname)
326.PHONY: deb
327deb_name:=$(shell grep ^Package debian/control | cut -d' ' -f2 | head -n 1)
328deb_version:=$(shell head -n 1 debian/changelog | cut -f2 -d' ' | tr -d '()')
329deb_arch:=i386
330deb_main:=$(deb_name)_$(deb_version)_$(deb_arch).deb
331deb: debian
332 @[ -x /usr/bin/fakeroot ] || { \
333 echo "*** Please install fakeroot package. ***"; \
334 exit 1; \
335 }
336 @[ -x /usr/bin/dpkg-buildpackage ] || { \
337 echo "*** Please install dpkg-dev package. ***"; \
338 exit 1; \
339 }
340 if [ -x /usr/bin/debuild ]; then \
341 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
342 else \
343 echo "*** Please install devscripts package. ***"; \
344 echo "*** Using dpkg-buildpackage for package building. ***"; \
345 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
346 fi
348.PHONY: website
349web_src:=web
350web_dest:=web/pandoc
351make_page:=./$(MAIN) -s -B $(web_src)/header.html \
352 -A $(web_src)/footer.html \
353 -H $(web_src)/css
354cleanup_files+=$(web_dest)
355website: $(web_dest)
356$(web_dest)/: $(MAIN) html
357 -rm -rf $(web_dest)
358 ( \
359 mkdir $(web_dest); \
360 cp -r html $(web_dest)/doc; \
361 cp $(web_src)/*.css $(web_dest)/; \
362 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome | \
363 $(make_page) > $(web_dest)/osx-notes.html; \
364 sed -e '/^ --.*/d' -e 's#^# #g' changelog | \
365 sed -e 's/ \(pandoc (.*\)/## \1/g' | \
366 $(make_page) -T "Pandoc changelog" > $(web_dest)/changelog.html; \
367 $(make_page) README > $(web_dest)/README.html; \
368 $(make_page) INSTALL > $(web_dest)/INSTALL.html; \
369 sed -e 's/@TARBALL_NAME@/$(tarball_name)/g' $(web_src)/index.txt | \
370 sed -e 's/@OSX_DMG_NAME@/$(osx_dmg_name)/g' | \
371 sed -e 's/@WINDOWS_PKG_NAME@/$(win_pkg_name)/g' | \
372 sed -e 's/@VERSION@/$(VERSION)/g' | \
373 $(make_page) > $(web_dest)/index.html; \
374 cp README $(web_dest)/ ; \
375 ./$(MAIN) -s -w latex README > $(web_dest)/README.tex ; \
376 cp $(web_src)/myheader.tex $(web_dest)/ ; \
377 cp $(web_src)/S5DEMO $(web_dest)/ ; \
378 cp $(web_src)/header.html $(web_dest)/ ; \
379 cp $(web_src)/footer.html $(web_dest)/ ; \
380 sh $(web_src)/mkdemos.sh $(web_dest) $(shell pwd) | \
381 $(make_page) > $(web_dest)/examples.html; \
382 ) || { rm -rf $(web_dest); exit 1; }
384.PHONY: distclean clean
385distclean: clean
386 if [ -d debian ]; then \
387 chmod +x debian/rules; fakeroot debian/rules clean; \
388 fi
390clean:
391 make -C $(SRCDIR)/templates clean
392 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
393 -rm -rf $(cleanup_files)