#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

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

%:
	dh $@ --with python2

override_dh_auto_test:
	# Cannot run the test suites at build time since they depend on Tryton
	# being configured, with for example a user for the database, etc.

override_dh_auto_build:
	@

TRYTON_PATH:=$(shell python -c 'from distutils import sysconfig; print sysconfig.get_python_lib()')
DESTDIR:="debian/gnuhealth-server$(TRYTON_PATH)/trytond/modules"
override_dh_auto_install:
	dh_auto_install
	# GNU Health used to have a Makefile, but now we have to do it manually here
	install -d $(DESTDIR)
	cp -a health/ $(DESTDIR)
	cp -a health_* $(DESTDIR)
	# Remove the qr code module (dependency currently not satisfied in Debian)
	find debian -name "health_qrcodes" -type d -prune -execdir rm -r \{\} \;
	# Mark all the Python scripts non-executable
	find debian -name "*.py"  -type f -executable -exec chmod a-x \{\} \;
	# Mark the gnuhealth-client script executable
	chmod a+x debian/gnuhealth-client.py
	# Remove all the tests folders from the binary package
	find debian -name "tests" -type d -prune -execdir rm -r \{\} \;

override_dh_link:
	## workaround for "extra-license-file":
	$(foreach FL,$(shell find debian -name 'COPYING'), $(shell $(RM) "$(FL)"))
	dh_link

override_dh_builddeb:
	dh_builddeb -- -Zxz

DPATH := $(abspath $(dir $(MAKEFILE_LIST)))
VER   ?= $(shell dpkg-parsechangelog -l$(DPATH)/changelog | perl -ne 'print $$1 if m{Version:\s*([\d\.]+)}')
.PHONY: get-orig-source
get-orig-source:
	@echo "# Downloading..."
	uscan --noconf --verbose --rename --destdir=$(CURDIR) --check-dirname-level=0 --force-download --download-version $(VER) $(DPATH)
