3#-------------------------------------------------------------------------------
4# Constant names and commands in source tree
5#-------------------------------------------------------------------------------
11BUILDCONF := $(BUILDDIR)/setup-config
14ODTSTYLES := odt-styles
16#-------------------------------------------------------------------------------
18#-------------------------------------------------------------------------------
19PKG := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL) | tr A-Z a-z)
20VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL))
21PKGID := $(PKG)-$(VERSION)
22EXECSBASE := $(shell sed -ne 's/^[Ee]xecutable:\{0,1\}[[:space:]]*//p' $(CABAL))
24#-------------------------------------------------------------------------------
26#-------------------------------------------------------------------------------
27WRAPPERS := html2markdown markdown2pdf hsmarkdown
28# Add .exe extensions if we're running Windows/Cygwin.
29EXTENSION := $(shell uname | tr '[:upper:]' '[:lower:]' | \
30 sed -ne 's/^cygwin.*$$/\.exe/p')
31BUILDCMD := $(addsuffix $(EXTENSION), ./setup)
32EXECS := $(addsuffix $(EXTENSION),$(EXECSBASE))
33PROGS := $(EXECS) $(WRAPPERS)
34MAIN := $(firstword $(EXECS))
35DOCS := README.html README BUGS
36MANPAGES := $(patsubst %.md,%,$(wildcard $(MANDIR)/man?/*.?.md))
37ODTREF := $(ODTSTYLES)/reference.odt
39#-------------------------------------------------------------------------------
40# Variables to setup through environment
41#-------------------------------------------------------------------------------
43# Specify default values.
46# Attempt to set variables from a previous make session.
48# Fallback to defaults but allow to get the values from environment.
54#-------------------------------------------------------------------------------
56#-------------------------------------------------------------------------------
57DESTPATH := $(DESTDIR)$(PREFIX)
58BINPATH := $(DESTPATH)/bin
59DATAPATH := $(DESTPATH)/share
60MANPATH := $(DATAPATH)/man
61PKGDATAPATH := $(DATAPATH)/$(DATADIR)
62PKGDOCPATH := $(DATAPATH)/$(DOCDIR)
64#-------------------------------------------------------------------------------
65# Generic Makefile variables
66#-------------------------------------------------------------------------------
68INSTALL_PROGRAM := $(INSTALL) -m 755
69INSTALL_DATA := $(INSTALL) -m 644
72GHC_VERSION := $(shell $(GHC) --version | sed -e 's/[^0-9]*//')
74#-------------------------------------------------------------------------------
76#-------------------------------------------------------------------------------
82# Document process rules.
84 ./$(MAIN) -s -S --toc $< >$@ || rm -f $@
86 ./$(MAIN) -s -w latex $< >$@ || rm -f $@
88 ./$(MAIN) -s -w rtf $< >$@ || rm -f $@
89%.pdf: % $(MAIN) markdown2pdf
90 sh ./markdown2pdf $< || rm -f $@
92 perl -p -e 's/\n/\r\n/' $< > $@ || rm -f $@ # convert to DOS line endings
94 ./$(MAIN) -s -S -w man $< >$@ || rm -f $@
96define generate-shell-script
97echo >&2 "Generating $@..."; \
100 lead = $$0; sub(/[^ \t].*$$/, "", lead); \
101 t = "$(dir $<)/"$$2; \
102 while (getline line < t > 0) \
111cleanup_files+=$(ODTREF)
112$(ODTREF): $(addprefix $(ODTSTYLES)/, layout-cache meta.xml styles.xml content.xml mimetype \
113 settings.xml Configurations2 Thumbnails META-INF)
115 zip -9 -r $(notdir $@) * -x $(notdir $@)
119cleanup_files+=$(WRAPPERS)
120$(WRAPPERS): %: $(SRCDIR)/wrappers/%.in $(SRCDIR)/wrappers/*.sh $(ODTREFSH)
121 @$(generate-shell-script)
123CABAL_BACKUP=$(CABAL).orig
125 cp $(CABAL) $(CABAL_BACKUP) ; \
126 if echo $(GHC_VERSION) | grep -q '^6.6'; then \
127 cp $(CABAL).ghc66 $(CABAL); \
131cleanup_files+=Setup.hi Setup.o $(BUILDCMD) $(BUILDVARS)
133 hc_pkg = --with-hc-pkg=$(GHC_PKG)
137templates=$(wildcard templates/*.* templates/headers/*.* templates/ui/default/*.*)
138configure: $(BUILDCONF)
140 $(GHC) -package Cabal Setup.hs -o $(BUILDCMD)
141$(BUILDCONF): $(CABAL) $(CABAL_BACKUP) $(BUILDCMD) $(templates)
142 $(BUILDCMD) configure --prefix=$(PREFIX) --with-compiler=$(GHC) $(hc_pkg) $(CABALOPTS)
143 @# Make configuration time settings persistent (definitely a hack).
144 @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
145 @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
153cleanup_files+=$(EXECS)
156 find $(BUILDDIR) -type f -name "$$f" -perm +a=x \
157 -exec ln -s -f {} . \; ; \
161cleanup_files+=README.html $(MANPAGES)
162build-doc: $(DOCS) $(MANPAGES)
165build-program: build-exec build-doc
167.PHONY: build-lib-doc haddock
169haddock: build-lib-doc
173 $(BUILDCMD) haddock && cp -r $(BUILDDIR)/doc/html .
176build-all: build-program build-lib-doc
178# User documents installation.
179.PHONY: install-doc uninstall-doc
180man_all:=$(patsubst $(MANDIR)/%,%,$(MANPAGES))
181install-doc: build-doc
182 $(INSTALL) -d $(PKGDOCPATH) && $(INSTALL_DATA) $(DOCS) $(PKGDOCPATH)/
183 for f in $(man_all); do \
184 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
185 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
188 -for f in $(DOCS); do rm -f $(PKGDOCPATH)/$$f; done
189 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
190 rmdir $(PKGDOCPATH) 2>/dev/null ||:
192# Data file installation.
193.PHONY: install-data uninstall-data
194install-data: $(ODTREF)
195 $(INSTALL) -d $(PKGDATAPATH) && $(INSTALL_DATA) $(ODTREF) $(PKGDATAPATH)/
197 -rm -f $(PKGDATAPATH)/$(notdir $(ODTREF))
198 rmdir $(PKGDATAPATH) 2>/dev/null ||:
200# Program only installation.
201.PHONY: install-exec uninstall-exec
202install-exec: build-exec
204 $(INSTALL) -d $(BINPATH); \
205 for f in $(PROGS); do \
206 if [ -L $$f ]; then \
207 f=$$(readlink $$f); \
209 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
212 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done
214# Program + user documents installation.
215.PHONY: install-program uninstall-program
216install-program: install-exec install-data install-doc
217uninstall-program: uninstall-exec uninstall-doc uninstall-data
219.PHONY: install-all uninstall-all
220# Full installation through Cabal: main + wrappers + user docs + lib + lib docs
221install-all: build-all install-program
222 destdir=$(DESTDIR); \
223 # Older Cabal versions have no '--destdir' option.
224 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
225 opt="--destdir=$${destdir-/}"; \
227 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
229 $(BUILDCMD) copy $$opt; $(BUILDCMD) register
230# Cabal lacks an 'uninstall' command. We have to remove some cruft manually.
231uninstall-all: uninstall-program
232 @libdir=$$($(GHC_PKG) field $(PKGID) library-dirs 2>/dev/null | \
233 sed 's/^library-dirs: *//'); \
234 htmldir=$$($(GHC_PKG) field $(PKGID) haddock-html 2>/dev/null | \
235 sed 's/^haddock-html: *//'); \
236 if [ -d $$libdir ]; then \
237 $(BUILDCMD) unregister ||:; \
239 echo >&2 "*** Couldn't locate library for pkgid: $(PKGID). ***"; \
241 for d in $$libdir $$htmldir; do \
243 rm -rf $$d; rmdir $$(dirname $$d) 2>/dev/null ||:; \
246 rmdir $(PKGDOCPATH) $(PKGDATAPATH) 2>/dev/null ||:
248# Default installation recipe for a common deployment scenario.
249.PHONY: install uninstall
250install: install-program
251uninstall: uninstall-program
256freebsd_makefile:=$(freebsd_dest)/Makefile
257freebsd_template:=$(freebsd_makefile).in
258cleanup_files+=$(freebsd_makefile)
259freebsd : $(freebsd_makefile)
260$(freebsd_makefile) : $(freebsd_template)
261 sed -e 's/@VERSION@/$(VERSION)/' $< > $@
265macport_dest:=macports
266portfile:=$(macport_dest)/Portfile
267portfile_template:=$(portfile).in
268cleanup_files+=$(portfile)
270$(portfile) : $(portfile_template) tarball
271 sed -e 's/@VERSION@/$(VERSION)/' $(portfile_template) | \
272 sed -e 's/@TARBALLMD5SUM@/$(word 2, $(shell openssl md5 $(tarball)))/' > \
276win_pkg_name:=$(PKGID).zip
277win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
278cleanup_files+=$(win_pkg_name) $(win_docs)
279win-pkg: $(win_pkg_name)
280$(win_pkg_name): $(PKG).exe $(win_docs)
281 zip -r $(win_pkg_name) $(PKG).exe $(win_docs)
283.PHONY: test test-markdown
285 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
286compat:=$(PWD)/hsmarkdown
287markdown_test_dirs:=$(wildcard $(TESTDIR)/MarkdownTest_*)
288test-markdown: $(MAIN) $(compat)
289 @for suite in $(markdown_test_dirs); do \
291 suite_version=$$(echo $$suite | sed -e 's/.*_//');\
292 echo >&2 "-----------------------------------------";\
293 echo >&2 "Running Markdown test suite version $${suite_version}.";\
294 PATH=$(PWD):$$PATH; export PATH; cd $$suite && \
295 perl MarkdownTest.pl -s $(compat) -tidy ; \
299# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
300src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
301cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
303 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
304 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
307tarball:=$(PKGID).tar.gz
308cleanup_files+=$(tarball)
311 svn export . $(PKGID)
312 $(MAKE) -C $(PKGID) wrappers
313 tar cvzf $(tarball) $(PKGID)
317deb_name:=$(shell grep ^Package debian/control | cut -d' ' -f2 | head -n 1)
318deb_version:=$(shell head -n 1 debian/changelog | cut -f2 -d' ' | tr -d '()')
320deb_main:=$(deb_name)_$(deb_version)_$(deb_arch).deb
322 @[ -x /usr/bin/fakeroot ] || { \
323 echo >&2 "*** Please install fakeroot package. ***"; \
326 @[ -x /usr/bin/dpkg-buildpackage ] || { \
327 echo >&2 "*** Please install dpkg-dev package. ***"; \
330 mv $(BUILDVARS) $(BUILDVARS).old 2>/dev/null ||: # backup settings
331 if [ -x /usr/bin/debuild ]; then \
332 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
334 echo >&2 "*** Please install devscripts package. ***"; \
335 echo >&2 "*** Using dpkg-buildpackage for package building. ***"; \
336 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
338 mv $(BUILDVARS).old $(BUILDVARS) 2>/dev/null ||: # restore
342web_dest:=pandoc-website
343make_page:=./$(MAIN) -s -S -B $(web_src)/header.html \
344 -A $(web_src)/footer.html \
346cleanup_files+=$(web_dest)
347$(web_dest) : html $(wildcard $(web_src)/*) debian/changelog \
348 INSTALL $(MANPAGES) $(MANDIR)/man1/pandoc.1.md README
349 rm -rf $(web_dest) && { \
351 cp -r html $(web_dest)/doc; \
352 cp $(web_src)/* $(web_dest)/; \
353 sed -e 's#@VERSION@#$(VERSION)#g' $(web_src)/index.txt.in > \
354 $(web_dest)/index.txt; \
355 cp debian/changelog $(web_dest)/changelog.txt ; \
356 cp README $(web_dest)/ ; \
357 cp INSTALL $(web_dest)/ ; \
358 cp $(MANDIR)/man1/pandoc.1.md $(web_dest)/ ; \
359 cp $(MANPAGES) $(web_dest)/ ; \
360 } || { rm -rf $(web_dest); exit 1; }
361website: $(MAIN) $(web_dest)
362 PANDOC_PATH=$(shell pwd) make -C $(web_dest)
364.PHONY: distclean clean
366 if [ -d debian ]; then \
367 chmod +x debian/rules; fakeroot debian/rules clean; \
371 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
372 -rm -rf $(cleanup_files)
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list