#!/usr/bin/make -f

include /usr/share/cdbs/1/rules/upstream-tarball.mk
include /usr/share/cdbs/1/rules/utils.mk
include /usr/share/cdbs/1/rules/debhelper.mk
include /usr/share/cdbs/1/class/hlibrary.mk

# ABI by default follows upstream version (without repackaging suffix)
abi = $(DEB_UPSTREAM_TARBALL_VERSION)

DEB_UPSTREAM_URL = http://pandoc.googlecode.com/files
DEB_UPSTREAM_TARBALL_MD5 = bfccc042ae0cf0901bbca1f87748f969

DEB_COPYRIGHT_CHECK_IGNORE_REGEX = ^.*\.(gif|jpg|odt)|\./debian/(changelog|copyright(|_hints|_newhints))$

DEB_INSTALL_MANPAGES_pandoc = man/man1/*.1 debian/hsmarkdown.1

DEB_SETUP_GHC6_CONFIGURE_ARGS = -fhighlighting

# Use threaded RTS only when supported
DEB_SETUP_GHC6_CONFIGURE_ARGS += $(if $(wildcard /usr/lib/ghc-$(GHC6_VERSION)/libHSrts_thr.a),,--flags=-threaded)

# Disable timer to help build on slow arches like hppa
DEB_SETUP_GHC6_CONFIGURE_ARGS += --ghc-options="+RTS -V0 -RTS"

# Generate (and cleanup) files containing variables static per build
infiles = $(filter-out debian/control.in, $(wildcard debian/*.in))
outfiles = $(basename $(infiles))
DEB_PHONY_RULES += $(outfiles)
pre-build:: $(outfiles)
$(outfiles): %: %.in
	perl -pe 's/__ABI__/$(abi)/g' <$< >$@
clean::
	rm -f $(outfiles)

# Let Haskell cleanup after itself (apparently forgotten in hlibrary.mk)
DEB_PHONY_RULES += haskell-clean
cleanbuilddir:: haskell-clean
haskell-clean:
	[ ! -x "$(DEB_SETUP_BIN_NAME)" ] || $(DEB_SETUP_BIN_NAME) clean

deps_doc = ghc6-doc (>= 6.8.2)
deps_doc += , libghc6-highlighting-kate-doc (>= 0.2.3), libghc6-xhtml-doc, libghc6-parsec2-doc (>= 2.1), haskell-pcre-light-doc

# Needed by upstream build process
CDBS_BUILD_DEPENDS += , ghc6 (>= 6.8.2)
CDBS_BUILD_DEPENDS += , libghc6-mtl-dev, libghc6-network-dev, libghc6-parsec2-dev (>= 2.1), libghc6-network-dev, libghc6-utf8-string-dev, libghc6-xhtml-dev, libghc6-zip-archive-dev (>= 0.1.1.4), libghc6-http-dev (>= 40000005), libghc6-texmath-dev, libghc6-xml-dev (>= 1.3.5), libghc6-xml-dev (<< 1.4), libghc6-extensible-exceptions-dev
CDBS_BUILD_DEPENDS += , libghc6-highlighting-kate-dev (>= 0.2.3)
CDBS_BUILD_DEPENDS += , hscolour (>= 1.8)
CDBS_BUILD_DEPENDS += , $(deps_doc)

# Needed for our packaging
CDBS_BUILD_DEPENDS += , haskell-devscripts (>=0.5.12)

# Needed (always/often/seldom) at runtime
#  texlive-* needed for markdown2pdf script
#  (texlive-latex-recommended mostly ok except ucs.sty - see bug#571678)
CDBS_SUGGESTS_pandoc = texlive-latex-recommended, texlive-latex-extra, texlive-xetex
CDBS_SUGGESTS_libghc6-pandoc-doc = $(deps_doc)
