3#-------------------------------------------------------------------------------
4# Constant names and commands in source tree
5#-------------------------------------------------------------------------------
11BUILDCONF := .setup-config
12BUILDCMD := runhaskell Setup.hs
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/^version[[:space:]]*=[[:space:]]*"\([^"]*\)"/\1/p' $(SRCDIR)/Main.hs)
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+=$(BUILDDIR) $(BUILDCONF) $(BUILDVARS)
122configure: $(BUILDCONF) templates
123$(BUILDCONF): $(CABAL)
124 $(BUILDCMD) configure --prefix=$(PREFIX)
125 # Make configuration time settings persistent (definitely a hack).
126 @echo "PREFIX?=$(PREFIX)" >$(BUILDVARS)
127 @echo "DESTDIR?=$(DESTDIR)" >>$(BUILDVARS)
135cleanup_files+=$(EXECS)
138 find $(BUILDDIR) -type f -name "$$f" \
139 -perm +a=x -exec ln -s -f {} . \; ; \
143cleanup_files+=README.html $(MANPAGES)
144build-doc: $(DOCS) $(MANPAGES)
147build-program: build-exec build-doc
149.PHONY: build-lib-doc haddock
151haddock: build-lib-doc
155 $(BUILDCMD) haddock && cp -r $(BUILDDIR)/doc/html .
158build-all: build-program build-lib-doc
160# User documents installation.
161.PHONY: install-doc uninstall-doc
162man_all:=$(patsubst $(MANDIR)/%,%,$(MANPAGES))
163install-doc: build-doc
164 $(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(DOCS) $(DOCPATH)/
165 for f in $(man_all); do \
166 $(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
167 $(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
170 -for f in $(DOCS); do rm -f $(DOCPATH)/$$f; done
171 -for f in $(man_all); do rm -f $(MANPATH)/$$f; done
174# Library documents installation.
175.PHONY: install-lib-doc uninstall-lib-doc
176install-lib-doc: build-lib-doc
177 $(INSTALL) -d $(LIBDOCPATH) && cp -R html $(LIBDOCPATH)/
179 -rm -rf $(LIBDOCPATH)/html
182# Helper to install the given files $(1) into the path $(2).
183# It also has the ability to follow symlinks.
184install-executable-files = \
185 $(INSTALL) -d $(2); \
187 if [ -L $$f ]; then \
188 f=$$(readlink $$f); \
190 $(INSTALL_PROGRAM) $$f $(2)/; \
193# Program only installation.
194.PHONY: install-exec uninstall-exec
195install-exec: build-exec
197 $(call install-executable-files,$(PROGS),$(BINPATH))
199 -for f in $(notdir $(PROGS)); do rm -f $(BINPATH)/$$f; done ;
201# Program + user documents installation.
202.PHONY: install-program uninstall-program
203install-program: install-exec install-doc
204uninstall-program: uninstall-exec uninstall-doc
206.PHONY: install-all uninstall-all
208install-all: build-all install-doc install-lib-doc
209 # Install the library (+ main executable) and register it.
210 destdir=$(DESTDIR); \
211 # Older Cabal versions have no '--destdir' option.
212 if $(BUILDCMD) copy --help | grep -q '\-\-destdir'; then \
213 opt="--destdir=$${destdir-/}"; \
215 opt="--copy-prefix=$${destdir}$(PREFIX)"; \
217 $(BUILDCMD) copy $$opt; \
219 # Note that, we are in the position of having to install the wrappers
220 # separately, as Cabal installs the main exec along with the library.
221 $(call install-executable-files,$(WRAPPERS),$(BINPATH))
222uninstall-all: uninstall-program uninstall-lib-doc
223 -pkg_id="$(NAME)-$(VERSION)"; \
224 libdir=$$($(GHC_PKG) field $$pkg_id library-dirs 2>/dev/null | \
225 sed 's/^library-dirs: *//'); \
226 if [ -d "$$libdir" ]; then \
227 $(BUILDCMD) unregister; \
229 rmdir $$(dirname $$libdir); \
231 echo "*** Couldn't locate library files for pkgid: $$pkg_id. ***"; \
234# Default installation recipe for a common deployment scenario.
235.PHONY: install uninstall
236install: install-program
237uninstall: uninstall-program
239# OSX packages: make osx-pkg-prep, then (as root) make osx-pkg
240.PHONY: osx-pkg osx-pkg-prep
243doc_more:=COPYRIGHT.rtf $(osx_src)/Welcome.rtf
244osx_pkg_name:=$(RELNAME).pkg
245cleanup_files+=$(osx_dest) $(doc_more) $(osx_pkg_name)
246osx-pkg-prep: $(osx_dest)
247$(osx_dest)/: build-program $(doc_more)
249 $(INSTALL) -d $(osx_dest)
250 DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
251 cp $(osx_src)/uninstall-pandoc $(osx_dest)/Package_root/usr/local/bin/
252 find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
253 find $(osx_dest) -type f -regex ".*bin/$(notdir $(MAIN))" | xargs $(STRIP)
254 $(INSTALL) -d $(osx_dest)/Resources
255 ./$(MAIN) -s -S README -o $(osx_dest)/Resources/ReadMe.html
256 cp COPYRIGHT.rtf $(osx_dest)/Resources/License.rtf
257 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome.rtf > $(osx_dest)/Resources/Welcome.rtf
258 sed -e 's/@VERSION@/$(VERSION)/g' $(osx_src)/Info.plist > $(osx_dest)/Info.plist
259 cp $(osx_src)/Description.plist $(osx_dest)/
260osx-pkg: $(osx_pkg_name)
261$(osx_pkg_name)/: $(osx_dest)
262 if [ "`id -u`" != 0 ]; then \
263 echo "Root permissions needed to create OSX package!"; \
266 find $(osx_dest) | xargs chown root:wheel
267 PackageMaker -build -p $(osx_pkg_name) \
268 -f $(osx_dest)/Package_root \
269 -r $(osx_dest)/Resources \
270 -i $(osx_dest)/Info.plist \
271 -d $(osx_dest)/Description.plist
272 chgrp admin $(osx_pkg_name)
276osx_dmg_name:=$(RELNAME).dmg
277cleanup_files+=$(osx_dmg_name)
278osx_udzo_name:=$(RELNAME).udzo.dmg
279osx_dmg_volume:="$(NAME) $(VERSION)"
280osx-dmg: $(osx_dmg_name)
281$(osx_dmg_name): $(osx_pkg_name)
282 -rm -f $(osx_dmg_name)
283 hdiutil create $(osx_dmg_name) -size 05m -fs HFS+ -volname $(osx_dmg_volume)
284 dev_handle=`hdid $(osx_dmg_name) | grep Apple_HFS | \
285 perl -e '\$$_=<>; /^\\/dev\\/(disk.)/; print \$$1'`; \
286 ditto $(osx_pkg_name) /Volumes/$(osx_dmg_volume)/$(osx_pkg_name); \
287 hdiutil detach $$dev_handle
288 hdiutil convert $(osx_dmg_name) -format UDZO -o $(osx_udzo_name)
289 -rm -f $(osx_dmg_name)
290 mv $(osx_udzo_name) $(osx_dmg_name)
294win_pkg_name:=$(RELNAME).zip
295win_docs:=COPYING.txt COPYRIGHT.txt BUGS.txt README.txt README.html
296cleanup_files+=$(win_pkg_name) $(win_docs)
297win-pkg: $(win_pkg_name)
298$(win_pkg_name): $(THIS).exe $(win_docs)
299 zip -r $(win_pkg_name) $(THIS).exe $(win_docs)
301.PHONY: test test-markdown
303 @cd $(TESTDIR) && perl runtests.pl -s $(PWD)/$(MAIN)
304compat:=$(PWD)/hsmarkdown
305markdown_test_dirs:=$(wildcard $(TESTDIR)/MarkdownTest_*)
306test-markdown: $(MAIN) $(compat)
307 @for suite in $(markdown_test_dirs); do \
309 suite_version=$$(echo $$suite | sed -e 's/.*_//');\
310 echo "-----------------------------------------";\
311 echo "Running Markdown test suite version $${suite_version}.";\
312 PATH=$(PWD):$$PATH; export PATH; cd $$suite && \
313 perl MarkdownTest.pl -s $(compat) -tidy ; \
317# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
318src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
319cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
321 cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
322 LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
325tarball_name:=$(RELNAME).tar.gz
326cleanup_files+=$(tarball_name)
327tarball: $(tarball_name)
329 svn export . $(RELNAME)
330 $(MAKE) -C $(RELNAME) templates
331 $(MAKE) -C $(RELNAME) wrappers
332 tar cvzf $(tarball_name) $(RELNAME)
336deb_name:=$(shell grep ^Package debian/control | cut -d' ' -f2 | head -n 1)
337deb_version:=$(shell head -n 1 debian/changelog | cut -f2 -d' ' | tr -d '()')
339deb_main:=$(deb_name)_$(deb_version)_$(deb_arch).deb
341 @[ -x /usr/bin/fakeroot ] || { \
342 echo "*** Please install fakeroot package. ***"; \
345 @[ -x /usr/bin/dpkg-buildpackage ] || { \
346 echo "*** Please install dpkg-dev package. ***"; \
349 -mv $(BUILDVARS) $(BUILDVARS).old # backup settings
350 if [ -x /usr/bin/debuild ]; then \
351 debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
353 echo "*** Please install devscripts package. ***"; \
354 echo "*** Using dpkg-buildpackage for package building. ***"; \
355 dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
357 -mv $(BUILDVARS).old $(BUILDVARS) # restore
362make_page:=./$(MAIN) -s -S -B $(web_src)/header.html \
363 -A $(web_src)/footer.html \
365cleanup_files+=$(web_dest)
370 cp -r html $(web_dest)/doc; \
371 cp $(web_src)/* $(web_dest)/; \
372 sed -e 's#@PREFIX@#$(PREFIX)#g' $(osx_src)/Welcome > \
373 $(web_dest)/osx-notes.txt; \
374 cp changelog $(web_dest)/ ; \
375 cp README $(web_dest)/ ; \
376 cp INSTALL $(web_dest)/ ; \
377 cp $(MANDIR)/man1/pandoc.1.md $(web_dest)/ ; \
378 cp $(MANDIR)/man1/*.1 $(web_dest)/ ; \
379 PANDOC_PATH=$(shell pwd) make -C $(web_dest) ; \
380 ) || { rm -rf $(web_dest); exit 1; }
382.PHONY: distclean clean
384 if [ -d debian ]; then \
385 chmod +x debian/rules; fakeroot debian/rules clean; \
389 make -C $(SRCDIR)/templates clean
390 -if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
391 -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