3#-------------------------------------------------------------------------------
4# Constant names and commands in source tree
5#-------------------------------------------------------------------------------
11BUILDCONF := .setup-config
16#-------------------------------------------------------------------------------
18#-------------------------------------------------------------------------------
19NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL))
20THIS := $(shell echo $(NAME) | tr A-Z a-z)
21VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL))
22RELNAME := $(THIS)-$(VERSION)
23EXECSBASE := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL))
25#-------------------------------------------------------------------------------
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)
34MAIN := $(firstword $(EXECS))
35DOCS := README.html README BUGS
36MANPAGES := $(patsubst %.md,%,$(wildcard $(MANDIR)/man?/*.?.md))
38#-------------------------------------------------------------------------------
39# Variables to setup through environment
40#-------------------------------------------------------------------------------
42# Specify default values.
45# Attempt to set variables from a previous make session.
47# Fallback to defaults but allow to get the values from environment.
51#-------------------------------------------------------------------------------
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#-------------------------------------------------------------------------------
67INSTALL_PROGRAM := $(INSTALL) -m 755
68INSTALL_DATA := $(INSTALL) -m 644
73#-------------------------------------------------------------------------------
75#-------------------------------------------------------------------------------
81# Document process rules.
83 ./$(MAIN) -s -S --toc $< >$@ || rm -f $@
85 ./$(MAIN) -s -w latex $< >$@ || rm -f $@
87 ./$(MAIN) -s -w rtf $< >$@ || rm -f $@
88%.pdf: % $(MAIN) markdown2pdf
89 sh ./markdown2pdf $< || rm -f $@
91 perl -p -e 's/\n/\r\n/' $< > $@ || rm -f $@ # convert to DOS line endings
93 ./$(MAIN) -s -S -w man $< >$@ || rm -f $@
96templates: $(SRCDIR)/templates
97 $(MAKE) -C $(SRCDIR)/templates
99define generate-shell-script
100echo "Generating $@..."; \
103 lead = $$0; sub(/[^ \t].*$$/, "", lead); \
104 t = "$(dir $<)/"$$2; \
105 while (getline line < t > 0) \
116cleanup_files+=$(WRAPPERS)
117$(WRAPPERS): %: $(SRCDIR)/wrappers/%.in $(SRCDIR)/wrappers/*.sh
118 @$(generate-shell-script)
121cleanup_files+=Setup.hi Setup.o $(BUILDCMD) $(BUILDVARS)
122configure: $(BUILDCONF) templates
123$(BUILDCONF): $(CABAL)
124 ghc -package Cabal Setup.hs -o $(BUILDCMD)
125 $(BUILDCMD) configure --prefix=$(PREFIX)
126 # Make configuration time settings persistent (definitely a hack).
127 @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
128 @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
136cleanup_files+=$(EXECS)
139 find $(BUILDDIR) -type f -name "$$f" \
140 -perm +a=x -exec ln -s -f {} . \; ; \
144cleanup_files+=README.html $(MANPAGES)
145build-doc: $(DOCS) $(MANPAGES)
148build-program: build-exec build-doc
150.PHONY: build-lib-doc haddock
152haddock: build-lib-doc
156 $(BUILDCMD) haddock && cp -r $(BUILDDIR)/doc/html .
159build-all: build-program build-lib-doc
161# User documents installation.
162.PHONY: install-doc uninstall-doc
163man_all:=$(patsubst $(MANDIR)/%,%,$(MANPAGES))
164install-doc: build-doc
165 $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
166 for f in $(man_all); do \
167 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
168 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
171 -for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
172 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
175# Library documents installation.
176.PHONY: install-lib-doc uninstall-lib-doc
177install-lib-doc: build-lib-doc
178 $(INSTALL) -d $(LIBDOCPATH) && cp -R html $(LIBDOCPATH)/
180 -rm -rf $(LIBDOCPATH)/html
183# Helper to install the given files $(1) into the path $(2).
184# It also has the ability to follow symlinks.
185install-executable-files = \
186 $(INSTALL) -d $(2); \
188 if [ -L $$f ]; then \
189 f=$$(readlink $$f); \
191 $(INSTALL_PROGRAM) $$f $(2)/; \
194# Program only installation.
195.PHONY: install-exec uninstall-exec
196install-exec: build-exec
198 $(call install-executable-files,$(PROGS),$(BINPATH))
200 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done ;
202# Program + user documents installation.
203.PHONY: install-program uninstall-program
204install-program: install-exec install-doc
205uninstall-program: uninstall-exec uninstall-doc
207.PHONY: install-all uninstall-all
209install-all: build-all install-doc install-lib-doc
210 # Install the library (+ main executable) and register it.
211 destdir=$(DESTDIR); \
212 # Older Cabal versions have no '--destdir' option.
213 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
214 opt="--destdir=$${destdir-/}"; \
216 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
218 $(BUILDCMD) copy $$opt; \
220 # Note that, we are in the position of having to install the wrappers
221 # separately, as Cabal installs the main exec along with the library.
222 $(call install-executable-files,$(WRAPPERS),$(BINPATH))
223uninstall-all: uninstall-program uninstall-lib-doc
224 -pkg_id="$(NAME)-$(VERSION)"; \
225 libdir=$$($(GHC_PKG) field $$pkg_id library-dirs 2>/dev/null | \
226 sed 's/^library-dirs: *//'); \
227 if [ -d "$$libdir" ]; then \
228 $(BUILDCMD) unregister; \
230 rmdir $$(dirname $$libdir); \
232 echo "*** Couldn't locate library files for pkgid: $$pkg_id. ***"; \
235# Default installation recipe for a common deployment scenario.
236.PHONY: install uninstall
237install: install-program
238uninstall: uninstall-program
243freebsd_makefile:=$(freebsd_dest)/Makefile
244freebsd_template:=$(freebsd_makefile).in
245cleanup_files+=$(freebsd_makefile)
246freebsd : $(freebsd_makefile)
247$(freebsd_makefile) : $(freebsd_template)
248 sed -e 's/@VERSION@/$(VERSION)/' $< > $@
252macport_dest:=macports
253portfile:=$(macport_dest)/Portfile
254portfile_template:=$(portfile).in
255cleanup_files+=$(portfile)
257$(portfile) : $(portfile_template) tarball
258 sed -e 's/@VERSION@/$(VERSION)/' $(portfile_template) | \
259 sed -e 's/@TARBALLMD5SUM@/$(word 2, $(shell openssl md5 $(tarball)))/' > \
263win_pkg_name:=$(RELNAME).zip
264win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
265cleanup_files+=$(win_pkg_name) $(win_docs)
266win-pkg: $(win_pkg_name)
267$(win_pkg_name): $(THIS).exe $(win_docs)
268 zip -r $(win_pkg_name) $(THIS).exe $(win_docs)
270.PHONY: test test-markdown
272 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
273compat:=$(PWD)/hsmarkdown
274markdown_test_dirs:=$(wildcard $(TESTDIR)/MarkdownTest_*)
275test-markdown: $(MAIN) $(compat)
276 @for suite in $(markdown_test_dirs); do \
278 suite_version=$$(echo $$suite | sed -e 's/.*_//');\
279 echo "-----------------------------------------";\
280 echo "Running Markdown test suite version $${suite_version}.";\
281 PATH=$(PWD):$$PATH; export PATH; cd $$suite && \
282 perl MarkdownTest.pl -s $(compat) -tidy ; \
286# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
287src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
288cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
290 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
291 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
294tarball:=$(RELNAME).tar.gz
295cleanup_files+=$(tarball)
298 svn export . $(RELNAME)
299 $(MAKE) -C $(RELNAME) templates
300 $(MAKE) -C $(RELNAME) wrappers
301 tar cvzf $(tarball) $(RELNAME)
305deb_name:=$(shell grep ^Package debian/control | cut -d' ' -f2 | head -n 1)
306deb_version:=$(shell head -n 1 debian/changelog | cut -f2 -d' ' | tr -d '()')
308deb_main:=$(deb_name)_$(deb_version)_$(deb_arch).deb
310 @[ -x /usr/bin/fakeroot ] || { \
311 echo "*** Please install fakeroot package. ***"; \
314 @[ -x /usr/bin/dpkg-buildpackage ] || { \
315 echo "*** Please install dpkg-dev package. ***"; \
318 -mv $(BUILDVARS) $(BUILDVARS).old # backup settings
319 if [ -x /usr/bin/debuild ]; then \
320 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
322 echo "*** Please install devscripts package. ***"; \
323 echo "*** Using dpkg-buildpackage for package building. ***"; \
324 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
326 -mv $(BUILDVARS).old $(BUILDVARS) # restore
330web_dest:=pandoc-website
331make_page:=./$(MAIN) -s -S -B $(web_src)/header.html \
332 -A $(web_src)/footer.html \
334cleanup_files+=$(web_dest)
335$(web_dest) : html $(wildcard $(web_src)/*) changelog \
336 INSTALL $(MANPAGES) $(MANDIR)/man1/pandoc.1.md README
340 cp -r html $(web_dest)/doc; \
341 cp $(web_src)/* $(web_dest)/; \
342 sed -e 's#@VERSION@#$(VERSION)#g' $(web_src)/index.txt.in > \
343 $(web_dest)/index.txt; \
344 cp changelog $(web_dest)/ ; \
345 cp README $(web_dest)/ ; \
346 cp INSTALL $(web_dest)/ ; \
347 cp $(MANDIR)/man1/pandoc.1.md $(web_dest)/ ; \
348 cp $(MANDIR)/man1/*.1 $(web_dest)/ ; \
349 ) || { rm -rf $(web_dest); exit 1; }
350website: $(MAIN) $(web_dest)
351 PANDOC_PATH=$(shell pwd) make -C $(web_dest)
353.PHONY: distclean clean
355 if [ -d debian ]; then \
356 chmod +x debian/rules; fakeroot debian/rules clean; \
360 make -C $(SRCDIR)/templates clean
361 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
362 -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