2006-10-17 16:22:29 +02:00
|
|
|
# Makefile for Pandoc.
|
|
|
|
|
2006-10-28 17:13:18 +02:00
|
|
|
CABAL := Pandoc.cabal
|
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Cabal constants
|
|
|
|
#-------------------------------------------------------------------------------
|
2006-10-28 17:13:18 +02:00
|
|
|
NAME := $(shell sed -ne 's/^[Nn]ame:[[:space:]]*//p' $(CABAL).in)
|
|
|
|
THIS := $(shell echo $(NAME) | tr A-Z a-z)
|
|
|
|
VERSION := $(shell sed -ne 's/^[Vv]ersion:[[:space:]]*//p' $(CABAL).in)
|
|
|
|
BINS := $(shell sed -ne 's/^[Ee]xecutable:[[:space:]]*//p' $(CABAL).in)
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Variables to setup through environment
|
|
|
|
#-------------------------------------------------------------------------------
|
2006-10-28 17:13:18 +02:00
|
|
|
PREFIX ?= /usr/local
|
|
|
|
DESTDIR ?=
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Constant names and commands in source tree
|
|
|
|
#-------------------------------------------------------------------------------
|
2006-10-28 17:13:18 +02:00
|
|
|
SRCDIR := src
|
|
|
|
MANDIR := man
|
|
|
|
BUILDDIR := dist
|
|
|
|
BUILDCONF := .setup-config
|
|
|
|
BUILDCMD := runhaskell Setup.hs
|
|
|
|
CONFIGURE := configure
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Installation paths
|
|
|
|
#-------------------------------------------------------------------------------
|
2006-10-29 13:54:08 +01:00
|
|
|
DESTPATH := $(DESTDIR)$(PREFIX)
|
|
|
|
BINPATH := $(DESTPATH)/bin
|
|
|
|
DATAPATH := $(DESTPATH)/share
|
|
|
|
LIBPATH := $(DESTPATH)/$(NAME)-$(VERSION)
|
2006-10-17 16:22:29 +02:00
|
|
|
DOCPATH := $(DATAPATH)/doc/$(THIS)
|
|
|
|
LIBDOCPATH := $(DATAPATH)/doc/$(THIS)-doc
|
|
|
|
MANPATH := $(DATAPATH)/man
|
|
|
|
PKGPATH := $(DATAPATH)/$(THIS)
|
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Generic Makefile variables
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
INSTALL := install -c
|
2006-10-31 19:40:47 +01:00
|
|
|
INSTALL_PROGRAM := $(INSTALL) -m 755
|
2006-10-17 16:22:29 +02:00
|
|
|
INSTALL_DATA := $(INSTALL) -m 644
|
2006-10-30 07:41:26 +01:00
|
|
|
STRIP := strip
|
2006-10-28 17:13:18 +02:00
|
|
|
GHC := ghc
|
2006-10-29 13:54:08 +01:00
|
|
|
GHC_PKG := ghc-pkg
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
# Recipes
|
|
|
|
#-------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
.PHONY: all
|
2006-10-30 06:40:41 +01:00
|
|
|
all: $(BINS)
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-10-30 09:04:30 +01:00
|
|
|
# Document process rules.
|
|
|
|
%.html: % $(THIS)
|
|
|
|
./$(THIS) -s $< >$@ || rm -f $@
|
|
|
|
%.tex: % $(THIS)
|
|
|
|
./$(THIS) -s -w latex $< >$@ || rm -f $@
|
|
|
|
%.rtf: % $(THIS)
|
|
|
|
./$(THIS) -s -w rtf $< >$@ || rm -f $@
|
|
|
|
%.pdf: % $(THIS)
|
|
|
|
sh ./markdown2pdf $< || rm -f $@
|
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
.PHONY: templates
|
|
|
|
templates: $(SRCDIR)/templates
|
|
|
|
$(SRCDIR)/templates:
|
|
|
|
$(MAKE) -C $(SRCDIR)/templates
|
|
|
|
|
2006-10-28 17:13:18 +02:00
|
|
|
cleanup_files+=$(CABAL)
|
|
|
|
$(CABAL): cabalize $(CABAL).in
|
|
|
|
./cabalize <$(CABAL).in >$(CABAL)
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
.PHONY: configure
|
2006-10-28 17:13:18 +02:00
|
|
|
cleanup_files+=$(BUILDDIR) $(BUILDCONF)
|
2006-10-17 16:22:29 +02:00
|
|
|
configure: $(BUILDCONF)
|
2006-10-28 17:13:18 +02:00
|
|
|
$(BUILDCONF): $(CABAL)
|
2006-10-17 16:22:29 +02:00
|
|
|
$(BUILDCMD) configure --prefix=$(PREFIX)
|
|
|
|
|
|
|
|
.PHONY: build
|
|
|
|
build: templates configure
|
|
|
|
$(BUILDCMD) build
|
|
|
|
|
2006-10-28 17:13:18 +02:00
|
|
|
.PHONY: build-lib-doc haddock
|
2006-10-17 16:22:29 +02:00
|
|
|
build-lib-doc: html
|
2006-10-28 17:13:18 +02:00
|
|
|
haddock: build-lib-doc
|
2006-10-17 16:22:29 +02:00
|
|
|
cleanup_files+=html
|
2006-10-28 17:13:18 +02:00
|
|
|
html/: configure
|
|
|
|
-rm -rf html
|
2006-10-17 16:22:29 +02:00
|
|
|
$(BUILDCMD) haddock && mv $(BUILDDIR)/doc/html .
|
|
|
|
|
2006-10-28 17:13:18 +02:00
|
|
|
cleanup_files+=$(BINS)
|
|
|
|
$(BINS): build
|
2006-10-29 13:54:08 +01:00
|
|
|
find $(BUILDDIR) -type f -name "$(BINS)" -perm +a=x -exec cp {} . \;
|
|
|
|
|
|
|
|
.PHONY: build-all
|
|
|
|
build-all: build $(BINS) build-lib-doc
|
2006-10-17 16:22:29 +02:00
|
|
|
|
|
|
|
# XXX: Note that we don't handle PREFIX correctly at the install-* stages,
|
|
|
|
# i.e. any PREFIX given at the configuration time is lost, unless it is
|
|
|
|
# also supplied (via environment) at these stages.
|
|
|
|
|
2006-10-29 13:54:08 +01:00
|
|
|
# User documents installation.
|
2006-10-17 16:22:29 +02:00
|
|
|
.PHONY: install-doc uninstall-doc
|
|
|
|
doc_all:=README.html README BUGS TODO
|
2006-10-20 19:27:57 +02:00
|
|
|
man_all:=$(patsubst $(MANDIR)/%,%,$(wildcard $(MANDIR)/man?/*.1))
|
2006-10-17 16:22:29 +02:00
|
|
|
cleanup_files+=README.html
|
2006-10-29 13:54:08 +01:00
|
|
|
install-doc: $(BINS) $(doc_all)
|
2006-10-20 19:27:57 +02:00
|
|
|
$(INSTALL) -d $(DOCPATH) && $(INSTALL_DATA) $(doc_all) $(DOCPATH)/
|
2006-10-28 17:13:18 +02:00
|
|
|
for f in $(man_all); do \
|
|
|
|
$(INSTALL) -d $(MANPATH)/$$(dirname $$f); \
|
|
|
|
$(INSTALL_DATA) $(MANDIR)/$$f $(MANPATH)/$$f; \
|
|
|
|
done
|
2006-10-17 16:22:29 +02:00
|
|
|
uninstall-doc:
|
2006-10-20 19:27:57 +02:00
|
|
|
-for f in $(doc_all); do rm -f $(DOCPATH)/$$f; done
|
|
|
|
-for f in $(man_all); do rm -f $(MANPATH)/$$f; done
|
2006-10-29 08:11:37 +01:00
|
|
|
-rmdir $(DOCPATH)
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-10-29 13:54:08 +01:00
|
|
|
# Library documents installation.
|
|
|
|
.PHONY: install-lib-doc uninstall-lib-doc
|
2006-10-17 16:22:29 +02:00
|
|
|
install-lib-doc: build-lib-doc
|
|
|
|
$(INSTALL) -d $(LIBDOCPATH) && cp -a html $(LIBDOCPATH)/
|
2006-10-29 13:54:08 +01:00
|
|
|
uninstall-lib-doc:
|
|
|
|
-rm -rf $(LIBDOCPATH)/html
|
|
|
|
-rmdir $(LIBDOCPATH)
|
|
|
|
|
|
|
|
# Program only installation.
|
|
|
|
.PHONY: install-exec uninstall-exec
|
|
|
|
bin_all:=$(BINS) html2markdown markdown2html latex2markdown markdown2latex markdown2pdf
|
|
|
|
install-exec: $(bin_all)
|
|
|
|
$(INSTALL) -d $(BINPATH); \
|
|
|
|
for f in $(bin_all); do $(INSTALL_PROGRAM) $$f $(BINPATH)/; done
|
|
|
|
uninstall-exec:
|
|
|
|
-for f in $(bin_all); do rm -f $(BINPATH)/$$f; done
|
|
|
|
|
|
|
|
# Program + user documents installation.
|
|
|
|
.PHONY: install-program uninstall-program
|
|
|
|
install-program: install-exec install-doc
|
|
|
|
uninstall-program: uninstall-exec uninstall-doc
|
|
|
|
|
|
|
|
# Install everything.
|
|
|
|
.PHONY: install-all uninstall-all
|
|
|
|
install-all: install-doc install-lib-doc
|
|
|
|
destdir=$(DESTDIR); destdir=$${destdir:-/}; \
|
|
|
|
$(BUILDCMD) copy --destdir=$$destdir; \
|
|
|
|
$(BUILDCMD) register
|
2006-10-30 06:40:41 +01:00
|
|
|
uninstall-all: uninstall-exec uninstall-doc uninstall-lib-doc
|
2006-10-29 13:54:08 +01:00
|
|
|
-pkg_id="$(NAME)-$(VERSION)"; \
|
|
|
|
libdir=$$($(GHC_PKG) field $$pkg_id library-dirs 2>/dev/null | \
|
|
|
|
sed 's/^library-dirs: *//'); \
|
|
|
|
if [ -d "$$libdir" ]; then \
|
|
|
|
$(BUILDCMD) unregister; \
|
|
|
|
rm -rf $$libdir; \
|
|
|
|
rmdir $$(dirname $$libdir); \
|
|
|
|
else \
|
|
|
|
echo "*** Couldn't locate library files for pkgid: $$pkg_id. ***"; \
|
|
|
|
fi
|
|
|
|
|
|
|
|
# Default installation recipe for a common deployment scenario.
|
|
|
|
.PHONY: install uninstall
|
|
|
|
install: install-program
|
|
|
|
uninstall: uninstall-program
|
2006-10-17 16:22:29 +02:00
|
|
|
|
2006-10-30 07:41:26 +01:00
|
|
|
.PHONY: osx-pkg
|
|
|
|
osx_dest:=osx-pkg
|
2006-10-31 18:19:25 +01:00
|
|
|
doc_more:=README.rtf LICENSE.rtf OSX-Welcome.rtf
|
2006-10-30 07:41:26 +01:00
|
|
|
cleanup_files+=$(osx_dest) $(doc_more)
|
2006-10-30 09:04:30 +01:00
|
|
|
osx-pkg: $(osx_dest)
|
|
|
|
$(osx_dest): $(doc_more)
|
2006-10-30 07:41:26 +01:00
|
|
|
-rm -rf $(osx_dest)
|
|
|
|
$(INSTALL) -d $(osx_dest)
|
2006-10-30 17:07:01 +01:00
|
|
|
DESTDIR=$(osx_dest)/Package_root $(MAKE) install-program
|
2006-10-30 07:41:26 +01:00
|
|
|
find $(osx_dest) -type f -regex ".*bin/.*" | xargs chmod +x
|
|
|
|
find $(osx_dest) -type f -regex ".*bin/$(THIS)" | xargs $(STRIP)
|
2006-10-31 19:40:47 +01:00
|
|
|
find $(osx_dest) -type f | xargs chown root:wheel
|
2006-10-30 07:41:26 +01:00
|
|
|
$(INSTALL) -d $(osx_dest)/Resources
|
|
|
|
mv README.rtf $(osx_dest)/Resources/ReadMe.rtf
|
|
|
|
mv LICENSE.rtf $(osx_dest)/Resources/License.rtf
|
2006-10-31 18:19:25 +01:00
|
|
|
sed -e 's#@PREFIX@#$(PREFIX)#g' OSX-Welcome.rtf > $(osx_dest)/Resources/Welcome.rtf
|
2006-10-31 08:06:30 +01:00
|
|
|
sed -e 's/@VERSION@/$(VERSION)/g' Info.plist > $(osx_dest)/Info.plist
|
|
|
|
cp Description.plist $(osx_dest)/
|
2006-10-31 19:40:47 +01:00
|
|
|
PackageMaker -build -p Pandoc_$(VERSION).pkg \
|
|
|
|
-f $(osx_dest)/Package_root \
|
|
|
|
-r $(osx_dest)/Resources \
|
|
|
|
-i $(osx_dest)/Info.plist \
|
|
|
|
-d $(osx_dest)/Description.plist
|
2006-10-30 07:41:26 +01:00
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
.PHONY: test test-markdown
|
2006-10-28 17:13:18 +02:00
|
|
|
test: $(BINS)
|
2006-10-17 16:22:29 +02:00
|
|
|
@cd tests && perl runtests.pl -s $(PWD)/$(THIS)
|
2006-10-28 17:13:18 +02:00
|
|
|
test-markdown: $(BINS)
|
2006-10-17 16:22:29 +02:00
|
|
|
@cd tests/MarkdownTest_1.0.3 && perl MarkdownTest.pl -s $(PWD)/$(THIS) -tidy
|
|
|
|
|
|
|
|
# Stolen and slightly improved from a GPLed Makefile. Credits to John Meacham.
|
|
|
|
src_all:=$(shell find $(SRCDIR) -type f -name '*hs' | egrep -v '^\./(_darcs|lib|test)/')
|
|
|
|
cleanup_files+=$(patsubst %,$(SRCDIR)/%,tags tags.sorted)
|
|
|
|
tags: $(src_all)
|
|
|
|
cd $(SRCDIR) && hasktags -c $(src_all:$(SRCDIR)/%=%); \
|
|
|
|
LC_ALL=C sort tags >tags.sorted; mv tags.sorted tags
|
|
|
|
|
2006-10-30 14:14:06 +01:00
|
|
|
deb: debian
|
2006-10-20 19:27:57 +02:00
|
|
|
[ -x /usr/bin/fakeroot ] || { \
|
|
|
|
echo "*** Please install fakeroot package. ***"; \
|
|
|
|
exit 1; \
|
|
|
|
}
|
|
|
|
[ -x /usr/bin/dpkg-buildpackage ] || { \
|
|
|
|
echo "*** Please install dpkg-dev package. ***"; \
|
|
|
|
exit 1; \
|
|
|
|
}
|
2006-10-17 16:22:29 +02:00
|
|
|
if [ -x /usr/bin/debuild ]; then \
|
2006-10-18 03:00:01 +02:00
|
|
|
debuild -uc -us -i.svn -I.svn -i_darcs -I_darcs --lintian-opts -i; \
|
2006-10-17 16:22:29 +02:00
|
|
|
else \
|
|
|
|
echo "*** Please install devscripts package. ***"; \
|
2006-10-20 19:27:57 +02:00
|
|
|
echo "*** Using dpkg-buildpackage for package building. ***"; \
|
|
|
|
dpkg-buildpackage -rfakeroot -uc -us -i.svn -I.svn -i_darcs -I_darcs; \
|
2006-10-17 16:22:29 +02:00
|
|
|
fi
|
|
|
|
|
|
|
|
.PHONY: distclean clean
|
2006-10-28 17:13:18 +02:00
|
|
|
distclean: clean
|
2006-10-30 13:15:02 +01:00
|
|
|
if [ -d debian ]; then \
|
|
|
|
chmod +x debian/rules; fakeroot debian/rules clean; \
|
|
|
|
fi
|
|
|
|
|
2006-10-17 16:22:29 +02:00
|
|
|
clean:
|
|
|
|
-if [ -f $(BUILDCONF) ]; then $(BUILDCMD) clean; fi
|
|
|
|
-rm -rf $(cleanup_files)
|