#! /usr/bin/make -f
# Made with the aid of dh_make, by Craig Small
# debian/rules that uses debhelper. GNU copyright 1997 by Joey Hess.
# Some lines taken from debmake, by Cristoph Lameter.
# Largely rewritten for the Cabalised happy by Ian Lynagh in 2006.
# Largely rewritten for cdbs and hlibrary.mk by Iain Lane in 2009.

export DEB_SETUP_GHC_CONFIGURE_ARGS := --datasubdir=/usr/share/happy --docdir=/usr/share/doc/happy

ifneq (,$(filter stage1,$(DEB_BUILD_PROFILES)))
export DEB_SETUP_GHC_CONFIGURE_ARGS += --with-happy=/bin/true
endif

execute_after_dh_auto_clean:
	[ ! -f doc/config.mk ] || $(MAKE) -C doc clean

	rm -f debian/get_version.o debian/get_version.hi debian/get_version
	rm -f doc/happy.1

	# Hacks:
	rm -f doc/config.log doc/config.status doc/config.mk doc/configure

execute_after_dh_auto_build:
	# doc/configure is not shipped, generate it
	cd doc && autoconf && rm -r autom4te.cache &&  ./configure --prefix=/usr
	# used in build to stick version into man page
	ghc --make debian/get_version.hs -o debian/get_version

	$(MAKE) -C doc html
	sed -e "s#@LIBDIR@#/usr/share/happy-`debian/get_version`#g" \
	    -e "s#@DOCDIR@#/usr/share/doc/happy#g" \
	    -e "s#@VERSION@#`debian/get_version`#g" \
	  doc/happy.1.in > doc/happy.1

%:
	dh $@
