#!/usr/bin/make -f

# This has to be exported to make some magic below work.
export DH_OPTIONS

# hack to fix #746913, -O2 somehow breaks the build
export DEB_CFLAGS_MAINT_APPEND = -O0

export HOME = $(CURDIR)/debian/tmp/tmp
export XDG_RUNTIME_DIR = $(CURDIR)/debian/tmp/tmp

%:
	dh $@ --with autoreconf

DB2MAN = http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl

override_dh_auto_build-arch:
	dh_auto_build
	(cd $(CURDIR)/debian && \
		xsltproc --nonet --novalid $(DB2MAN) berdecode.dbk)
	mkdir -p $(CURDIR)/debian/tmp/tmp

override_dh_auto_build-indep:
	# do it here even though it is not needed since dh_auto_test will attempt to run the tests anyway
	# and thus do the build in any case. Didn't want to do intrusive changes like checking whether we actually
	# are called with build-indep in a QA upload, rene - 2022-11-26
	debian/rules build-arch

	(cd $(CURDIR)/doc && unzip eSNACCManuals.zip && libreoffice --headless --convert-to pdf Esnacc.doc)

override_dh_auto_clean:
	dh_auto_clean
	rm -f $(CURDIR)/doc/Esnacc.doc $(CURDIR)/doc/EsnaccOriginalMaterial.doc $(CURDIR)/doc/*.pdf

override_dh_install:
	dh_install
	rm -rf $(CURDIR)/debian/esnacc/usr/share/doc/snacc-doc/ \
	$(CURDIR)/debian/esnacc/usr/share/man/man1/snacced.1*

override_dh_compress:
	dh_compress -X.pdf
