#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export PYTHON=/usr/bin/python3
export PYTHON_CONFIG=/usr/bin/python3-config
TEST_HOME=$(CURDIR)/tmp-home

# Append -Wl,-E to LDFLAGS for mips,mipsel,s390x archs, see:
# https://lists.debian.org/debian-mips/2014/09/msg00041.html
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
ifneq (,$(filter mips mipsel mips64 mips64el s390x,$(DEB_HOST_ARCH)))
	LDFLAGS += "-Wl,-E"
endif

%:
	dh $@ --with python3

override_dh_auto_configure:
	dh_auto_configure -- --without-included-ltdl LDFLAGS="$(LDFLAGS) -Wl,--as-needed" --with-libWN=wordnet

override_dh_auto_build:
	dh_auto_build

	# Build dicoclient python modules:
	dh_auto_build --buildsystem=pybuild --sourcedirectory dicoweb/dicoclient

	# Make those files executable before installing them:
	chmod +x debian/dicodconfig debian/dicodconfig.alias

override_dh_auto_install:
	dh_auto_install

	# Install dicoclient python modules:
	dh_auto_install --buildsystem=pybuild --sourcedirectory dicoweb/dicoclient

override_dh_install:
	dh_install
	# Install dicoweb:
	dh_install -pdicoweb dicoweb usr/share -Xdicoclient -XINSTALL -Xtemplates -Xsettings-sample.py -Xstatic
	dh_install -pdicoweb dicoweb/templates etc/dicoweb
	dh_install -pdicoweb dicoweb/static etc/dicoweb
	dh_install -pdicoweb debian/apache2.conf etc/dicoweb
	[ ! -d debian/dicoweb/etc/dicoweb/ ] || install -m 0644 dicoweb/settings-sample.py $(CURDIR)/debian/dicoweb/etc/dicoweb/settings.py

override_dh_auto_clean:
	dh_auto_clean

	# Clean dicoclient python modules:
	dh_auto_clean --buildsystem=pybuild --sourcedirectory dicoweb/dicoclient

override_dh_auto_test:
	mkdir -p $(TEST_HOME)
	HOME=$(TEST_HOME) dh_auto_test || cat dicod/tests/testsuite.log
