#!/usr/bin/make -f

# let aqbanking benefit from symbol visibility feature of gcc
# this explicit setting is needed because the corresponding test in
# configure.ac checks for the basename of the called $CC binary.
CC=gcc
ifneq (,$(findstring nodocs,$(DEB_BUILD_OPTIONS)))
	DEB_BUILD_APIDOC=0
else
	DEB_BUILD_APIDOC=1
endif

build-arch:	build-arch-stamp
build-arch-stamp:
	dh build --before configure
	dh_auto_configure --max-parallel=1 -- \
		--with-backends="aqnone aqhbci aqofxconnect" \
		--with-frontends="qbanking q4banking"
	dh build --after configure --before dh_auto_test --max-parallel=1
	# Skip dh_auto_test (does not work with AqBanking 3.7.2)
	dh build --after dh_auto_test --max-parallel=1
	$(MAKE) -C debian/doc
	touch build-arch-stamp

build-indep:	build-indep-stamp
build-indep-stamp:	build-arch
	if [ "$(DEB_BUILD_APIDOC)" = "1" ]; then \
		$(MAKE) srcdoc; \
		mv apidoc/html/aqbanking-* apidoc/html/aqbanking.html; \
	else \
		mkdir -p apidoc/html/aqbanking.html; \
	fi
	touch build-indep-stamp

build:	build-arch build-indep

install:	build install-stamp
install-stamp:
	dh install --until dh_auto_install
	# Install symlink to old path of hbci.xml, used by AqBanking 2
	mkdir -p $(CURDIR)/debian/tmp/usr/share/aqhbci
	ln -s ../aqbanking/backends/aqhbci $(CURDIR)/debian/tmp/usr/share/aqhbci/xml
	install -d $(CURDIR)/debian/tmp/usr/share/aqbanking/frontends/g2banking/glade2 \
		$(CURDIR)/debian/tmp/usr/share/aqbanking/imexporters/qif/profiles \
		$(CURDIR)/debian/tmp/usr/share/aqbanking/imexporters/eri2/profiles
	install -m 0644 $(CURDIR)/debian/AqBanking2/g2banking.glade \
		$(CURDIR)/debian/tmp/usr/share/aqbanking/frontends/g2banking/glade2/g2banking.glade
	install -m 0644 $(CURDIR)/debian/AqBanking2/imexporters/qif/profiles/default.conf \
		$(CURDIR)/debian/tmp/usr/share/aqbanking/imexporters/qif/profiles
	install -m 0644 $(CURDIR)/debian/AqBanking2/imexporters/eri2/profiles/default.conf \
		$(CURDIR)/debian/tmp/usr/share/aqbanking/imexporters/eri2/profiles
	# Remove .la files for shared plugin libraries
	find $(CURDIR)/debian/tmp/usr/lib/gwenhywfar/plugins -name \*.la -exec rm -v \{\} \;
	find $(CURDIR)/debian/tmp/usr/lib/aqbanking/plugins -name \*.la -exec rm -v \{\} \;
	dh install --remaining
	touch install-stamp

override_dh_strip:
	dh_strip --dbg-package=libaqbanking29-dbg

override_dh_makeshlibs:
	dh_makeshlibs -a -X/usr/lib/aqbanking/plugins/

binary-arch:	install
	dh binary-arch
binary-indep:	install
	dh binary-indep
binary:	binary-arch binary-indep

clean:
	dh clean
	-rm -rf apidoc headers aqbanking.tag listdoc.h
	@if [ -e $(CURDIR)/src/plugins/backends/aqyellownet ]; then \
	  echo "ERROR: The directory src/plugins/backends/aqyellownet exists. This usually"; \
	  echo "indicates that you're using a pristine upstream tarball which distributes"; \
	  echo "non-free material in this directory. This is unacceptable for Debian."; \
	  echo "Please see http://bugs.debian.org/469131 for further details."; \
	  exit 1; \
	fi
	$(MAKE) -C debian/doc clean

.PHONY:	clean build build-arch build-indep install binary-arch binary-indep binary
