git.iko.soy/typeable/pandoc
on fc08eb0 help sign in
typeable/pandoc/Makefile
286 lines 9.6 kB history raw
1# Makefile for Pandoc.
3CABAL := Pandoc.cabal
5#-------------------------------------------------------------------------------
6# Cabal constants
7#-------------------------------------------------------------------------------
8NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
9VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL).in)
10EXECS := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
12# First entry in Cabal's executable stanza is the main executable.
13MAIN := $(word 1, $(EXECS))
15#-------------------------------------------------------------------------------
16# Install targets
17#-------------------------------------------------------------------------------
18PROGS := $(EXECS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
19DOCS := README.html README BUGS TODO
21#-------------------------------------------------------------------------------
22# Constant names and commands in source tree
23#-------------------------------------------------------------------------------
24SRCDIR := src
25MANDIR := man
26BUILDDIR := dist
27BUILDCONF := .setup-config
28BUILDCMD := runhaskell Setup.hs
29BUILDVARS := vars
30CONFIGURE := configure
32#-------------------------------------------------------------------------------
33# Variables to setup through environment
34#-------------------------------------------------------------------------------
36# Specify default values.
37prefix := /usr/local
38destdir :=
39# Attempt to set variables from a previous make session.
40-include $(BUILDVARS)
41# Fallback to defaults but allow to get the values from environment.
42PREFIX ?= $(prefix)
43DESTDIR ?= $(destdir)
45#-------------------------------------------------------------------------------
46# Installation paths
47#-------------------------------------------------------------------------------
48THIS := $(shell echo $(NAME) | tr A-Z a-z)
49DESTPATH := $(DESTDIR)$(PREFIX)
50BINPATH := $(DESTPATH)/bin
51DATAPATH := $(DESTPATH)/share
52LIBPATH := $(DESTPATH)/$(NAME)-$(VERSION)
53DOCPATH := $(DATAPATH)/doc/$(THIS)
54LIBDOCPATH := $(DATAPATH)/doc/$(THIS)-doc
55MANPATH := $(DATAPATH)/man
56PKGPATH := $(DATAPATH)/$(THIS)
58#-------------------------------------------------------------------------------
59# Generic Makefile variables
60#-------------------------------------------------------------------------------
61INSTALL := install -c
62INSTALL_PROGRAM := $(INSTALL) -m 755
63INSTALL_DATA := $(INSTALL) -m 644
64STRIP := strip
65GHC := ghc
66GHC_PKG := ghc-pkg
68#-------------------------------------------------------------------------------
69# Recipes
70#-------------------------------------------------------------------------------
72# Default target.
73.PHONY: all
74all: build-program
76# Document process rules.
77%.html: % $(MAIN)
78 ./$(MAIN) -s $< >$@ || rm -f $@
79%.tex: % $(MAIN)
80 ./$(MAIN) -s -w latex $< >$@ || rm -f $@
81%.rtf: % $(MAIN)
82 ./$(MAIN) -s -w rtf $< >$@ || rm -f $@
83%.pdf: % $(MAIN) markdown2pdf
84 sh ./markdown2pdf $< || rm -f $@
86.PHONY: templates
87templates: $(SRCDIR)/templates
88$(SRCDIR)/templates:
89 $(MAKE) -C $(SRCDIR)/templates
91cleanup_files+=$(CABAL)
92$(CABAL): cabalize $(CABAL).in
93 ./cabalize <$(CABAL).in >$(CABAL)
95.PHONY: configure
96cleanup_files+=$(BUILDDIR) $(BUILDCONF) $(BUILDVARS)
97configure: $(BUILDCONF)
98$(BUILDCONF): $(CABAL)
99 $(BUILDCMD) configure --prefix=$(PREFIX)
100 # Make configuration time settings persistent (definitely a hack).
101 @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
102 @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
104.PHONY: build
105build: $(BUILDDIR)
106$(BUILDDIR)/: templates configure
107 $(BUILDCMD) build
109.PHONY: build-exec
110build-exec: $(EXECS)
111cleanup_files+=$(EXECS)
112$(EXECS): $(BUILDDIR)
113 for f in $@; do \
114 find $(BUILDDIR) -type f -name "$$f" -perm +a=x -exec cp {} . \; ; \
115 done
117.PHONY: build-doc
118cleanup_files+=README.html
119build-doc: $(DOCS)
121.PHONY: build-program
122build-program: build-exec build-doc
124.PHONY: build-lib-doc haddock
125build-lib-doc: html
126haddock: build-lib-doc
127cleanup_files+=html
128html/: configure
129 -rm -rf html
130 $(BUILDCMD) haddock && mv $(BUILDDIR)/doc/html .
132.PHONY: build-all
133build-all: build-program build-lib-doc
135# User documents installation.
136.PHONY: install-doc uninstall-doc
137man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
138install-doc: build-doc
139 $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
140 for f in $(man_all); do \
141 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
142 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
143 done
144uninstall-doc:
145 -for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
146 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
147 -rmdir $(DOCPATH)
149# Library documents installation.
150.PHONY: install-lib-doc uninstall-lib-doc
151install-lib-doc: build-lib-doc
152 $(INSTALL) -d $(LIBDOCPATH) && cp -a html $(LIBDOCPATH)/
153uninstall-lib-doc:
154 -rm -rf $(LIBDOCPATH)/html
155 -rmdir $(LIBDOCPATH)
157# Program only installation.
158.PHONY: install-exec uninstall-exec
159install-exec: build-exec
160 $(INSTALL) -d $(BINPATH); \
161 for f in $(PROGS); do $(INSTALL_PROGRAM) $$f $(BINPATH)/; done
162uninstall-exec:
163 -for f in $(PROGS); do rm -f $(BINPATH)/$$f; done
165# Program + user documents installation.
166.PHONY: install-program uninstall-program
167install-program: install-exec install-doc
168uninstall-program: uninstall-exec uninstall-doc
170# Install everything.
171.PHONY: install-all uninstall-all
172install-all: install-doc install-lib-doc
173 destdir=$(DESTDIR); \
174 # Older Cabal versions have no '--destdir' option.
175 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
176 opt="--destdir=$${destdir-/}"; \
177 else \
178 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
179 fi; \
180 $(BUILDCMD) copy $$opt; \
181 $(BUILDCMD) register
182uninstall-all: uninstall-exec uninstall-doc uninstall-lib-doc
183 -pkg_id="$(NAME)-$(VERSION)"; \
184 libdir=$$($(GHC_PKG) field $$pkg_id library-dirs 2>/dev/null | \
185 sed 's/^library-dirs: *//'); \
186 if [ -d "$$libdir" ]; then \
187 $(BUILDCMD) unregister; \
188 rm -rf $$libdir; \
189 rmdir $$(dirname $$libdir); \
190 else \
191 echo "*** Couldn't locate library files for pkgid: $$pkg_id. ***"; \
192 fi
194# Default installation recipe for a common deployment scenario.
195.PHONY: install uninstall
196install: install-program
197uninstall: uninstall-program
199osx_dest:=osx-pkg-tmp
200osx_src:=osx
201doc_more:=README.rtf LICENSE.rtf $(osx_src)/Welcome.rtf
202osx_pkg_name:=Pandoc_$(VERSION).pkg
203cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
204osx-pkg-prep: build-program $(osx_dest)
205$(osx_dest)/: $(doc_more)
206 -rm -rf $(osx_dest)
207 $(INSTALL) -d $(osx_dest)
208 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
209 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
210 find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
211 find $(osx_dest) -type f -regex ".*bin/$(MAIN)" | xargs $(STRIP)
212 $(INSTALL) -d $(osx_dest)/Resources
213 cp README.rtf $(osx_dest)/Resources/ReadMe.rtf
214 cp LICENSE.rtf $(osx_dest)/Resources/License.rtf
215 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome.rtf > $(osx_dest)/Resources/Welcome.rtf
216 sed -e 's/@VERSION@/$(VERSION)/g' $(osx_src)/Info.plist > $(osx_dest)/Info.plist
217 cp $(osx_src)/Description.plist $(osx_dest)/
218osx-pkg: osx-pkg-prep
219 if [ "`id -u`" != 0 ]; then \
220 echo "Root permissions needed to create OSX package!"; \
221 exit 1; \
222 fi
223 find $(osx_dest) | xargs chown root:wheel
224 PackageMaker -build -p $(osx_pkg_name) \
225 -f $(osx_dest)/Package_root \
226 -r $(osx_dest)/Resources \
227 -i $(osx_dest)/Info.plist \
228 -d $(osx_dest)/Description.plist
229 chgrp admin $(osx_pkg_name)
230 -rm -rf $(osx_dest)
232.PHONY: osx-dmg
233osx_dmg_name:=Pandoc.dmg
234osx_dmg_volume:="Pandoc $(VERSION)"
235cleanup_files+=$(osx_dmg_name)
236osx-dmg: $(osx_dmg_name)
237$(osx_dmg_name): $(osx_pkg_name)
238 -rm -f $(osx_dmg_name)
239 hdiutil create $(osx_dmg_name) -size 05m -fs HFS+ -volname $(osx_dmg_volume)
240 dev_handle=`hdid $(osx_dmg_name) | grep Apple_HFS | \
241 perl -e '\$$_=<>; /^\\/dev\\/(disk.)/; print \$$1'`; \
242 ditto $(osx_pkg_name) /Volumes/$(osx_dmg_volume)/$(osx_pkg_name); \
243 hdiutil detach $$dev_handle
244 hdiutil convert $(osx_dmg_name) -format UDZO -o Pandoc.udzo.dmg
245 -rm -f $(osx_dmg_name)
246 mv Pandoc.udzo.dmg $(osx_dmg_name)
248.PHONY: test test-markdown
249test: $(MAIN)
250 @cd tests && perl runtests.pl -s $(PWD)/$(MAIN)
251test-markdown: $(MAIN)
252 @cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(MAIN) -tidy
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
261deb: debian
262 [ -x /usr/bin/fakeroot ] || { \
263 echo "*** Please install fakeroot package. ***"; \
264 exit 1; \
265 }
266 [ -x /usr/bin/dpkg-buildpackage ] || { \
267 echo "*** Please install dpkg-dev package. ***"; \
268 exit 1; \
269 }
270 if [ -x /usr/bin/debuild ]; then \
271 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
272 else \
273 echo "*** Please install devscripts package. ***"; \
274 echo "*** Using dpkg-buildpackage for package building. ***"; \
275 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
276 fi
278.PHONY: distclean clean
279distclean: clean
280 if [ -d debian ]; then \
281 chmod +x debian/rules; fakeroot debian/rules clean; \
282 fi
284clean:
285 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
286 -rm -rf $(cleanup_files)