#!/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

include /usr/share/dpkg/architecture.mk

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- \
		--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 --package=dicoweb dicoweb usr/share --exclude=dicoclient --exclude=INSTALL --exclude=templates --exclude=settings-sample.py --exclude=static --exclude=requirements.txt
	dh_install --package=dicoweb dicoweb/templates etc/dicoweb
	dh_install --package=dicoweb dicoweb/static etc/dicoweb
	dh_install --package=dicoweb 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

execute_after_dh_installsystemd-arch:
	ln -s dicod.service debian/dicod/`test -e debian/dicod/lib/systemd/system/dicod.service || echo usr/`lib/systemd/system/dictd.service
