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 -q -r $(notdir $@) * -x $(notdir $@)
119cleanup_files+=$(WRAPPERS)
120$(WRAPPERS): %: $(SRCDIR)/wrappers/%.in $(SRCDIR)/wrappers/*.sh
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) $(ODTREF)
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# Program only installation.
193.PHONY: install-exec uninstall-exec
194install-exec: build-exec
196 $(INSTALL) -d $(BINPATH); \
197 for f in $(PROGS); do \
198 if [ -L $$f ]; then \
199 f=$$(readlink $$f); \
201 $(INSTALL_PROGRAM) $$f $(BINPATH)/; \
204 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done
206# Program + user documents installation.
207.PHONY: install-program uninstall-program
208install-program: install-exec install-doc
209uninstall-program: uninstall-exec uninstall-doc
211.PHONY: install-all uninstall-all
212# Full installation through Cabal: main + wrappers + user docs + lib + lib docs
213install-all: build-all install-program
214 destdir=$(DESTDIR); \
215 # Older Cabal versions have no '--destdir' option.
216 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
217 opt="--destdir=$${destdir-/}"; \
219 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
221 $(BUILDCMD) copy $$opt; $(BUILDCMD) register
222# Cabal lacks an 'uninstall' command. We have to remove some cruft manually.
223uninstall-all: uninstall-program
224 @libdir=$$($(GHC_PKG) field $(PKGID) library-dirs 2>/dev/null | \
225 sed 's/^library-dirs: *//'); \
226 htmldir=$$($(GHC_PKG) field $(PKGID) haddock-html 2>/dev/null | \
227 sed 's/^haddock-html: *//'); \
228 if [ -d $$libdir ]; then \
229 $(BUILDCMD) unregister ||:; \
231 echo >&2 "*** Couldn't locate library for pkgid: $(PKGID). ***"; \
233 for d in $$libdir $$htmldir; do \
235 rm -rf $$d; rmdir $$(dirname $$d) 2>/dev/null ||:; \
238 rmdir $(PKGDOCPATH) $(PKGDATAPATH) 2>/dev/null ||:
240# Default installation recipe for a common deployment scenario.
241.PHONY: install uninstall
242install: install-program
243uninstall: uninstall-program
248freebsd_makefile:=$(freebsd_dest)/Makefile
249freebsd_template:=$(freebsd_makefile).in
250cleanup_files+=$(freebsd_makefile)
251freebsd : $(freebsd_makefile)
252$(freebsd_makefile) : $(freebsd_template)
253 sed -e 's/@VERSION@/$(VERSION)/' $< > $@
257macport_dest:=macports
258portfile:=$(macport_dest)/Portfile
259portfile_template:=$(portfile).in
260cleanup_files+=$(portfile)
262$(portfile) : $(portfile_template) tarball
263 sed -e 's/@VERSION@/$(VERSION)/' $(portfile_template) | \
264 sed -e 's/@TARBALLMD5SUM@/$(word 2, $(shell openssl md5 $(tarball)))/' > \
268win_pkg_name:=$(PKGID).zip
269win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
270cleanup_files+=$(win_pkg_name) $(win_docs)
271win-pkg: $(win_pkg_name)
272$(win_pkg_name): $(PKG).exe $(win_docs)
273 zip -r $(win_pkg_name) $(PKG).exe $(win_docs)
275.PHONY: test test-markdown
277 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
278compat:=$(PWD)/hsmarkdown
279markdown_test_dirs:=$(wildcard $(TESTDIR)/MarkdownTest_*)
280test-markdown: $(MAIN) $(compat)
281 @for suite in $(markdown_test_dirs); do \
283 suite_version=$$(echo $$suite | sed -e 's/.*_//');\
284 echo >&2 "-----------------------------------------";\
285 echo >&2 "Running Markdown test suite version $${suite_version}.";\
286 PATH=$(PWD):$$PATH; export PATH; cd $$suite && \
287 perl MarkdownTest.pl -s $(compat) -tidy ; \
291# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
292src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
293cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
295 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
296 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
299tarball:=$(PKGID).tar.gz
300cleanup_files+=$(tarball)
303 svn export . $(PKGID)
304 $(MAKE) -C $(PKGID) wrappers
305 tar cvzf $(tarball) $(PKGID)
309deb_name:=$(shell grep ^Package debian/control | cut -d' ' -f2 | head -n 1)
310deb_version:=$(shell head -n 1 debian/changelog | cut -f2 -d' ' | tr -d '()')
312deb_main:=$(deb_name)_$(deb_version)_$(deb_arch).deb
314 @[ -x /usr/bin/fakeroot ] || { \
315 echo >&2 "*** Please install fakeroot package. ***"; \
318 @[ -x /usr/bin/dpkg-buildpackage ] || { \
319 echo >&2 "*** Please install dpkg-dev package. ***"; \
322 mv $(BUILDVARS) $(BUILDVARS).old 2>/dev/null ||: # backup settings
323 if [ -x /usr/bin/debuild ]; then \
324 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
326 echo >&2 "*** Please install devscripts package. ***"; \
327 echo >&2 "*** Using dpkg-buildpackage for package building. ***"; \
328 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
330 mv $(BUILDVARS).old $(BUILDVARS) 2>/dev/null ||: # restore
334web_dest:=pandoc-website
335make_page:=./$(MAIN) -s -S -B $(web_src)/header.html \
336 -A $(web_src)/footer.html \
338cleanup_files+=$(web_dest)
339$(web_dest) : html $(wildcard $(web_src)/*) debian/changelog \
340 INSTALL $(MANPAGES) $(MANDIR)/man1/pandoc.1.md README
341 rm -rf $(web_dest) && { \
343 cp -r html $(web_dest)/doc; \
344 cp $(web_src)/* $(web_dest)/; \
345 sed -e 's#@VERSION@#$(VERSION)#g' $(web_src)/index.txt.in > \
346 $(web_dest)/index.txt; \
347 cp debian/changelog $(web_dest)/changelog.txt ; \
348 cp README $(web_dest)/ ; \
349 cp INSTALL $(web_dest)/ ; \
350 cp $(MANDIR)/man1/pandoc.1.md $(web_dest)/ ; \
351 cp $(MANPAGES) $(web_dest)/ ; \
352 } || { rm -rf $(web_dest); exit 1; }
353website: $(MAIN) $(web_dest)
354 PANDOC_PATH=$(shell pwd) make -C $(web_dest)
356.PHONY: distclean clean
358 if [ -d debian ]; then \
359 chmod +x debian/rules; fakeroot debian/rules clean; \
363 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
364 -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