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

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

PYTHON3=$(shell py3versions -r)

%:
	dh $@ --with python3 --buildsystem=pybuild

override_dh_clean:
	dh_clean
	rm -rf Features.html build/ Python?/unicodedata_db.h

override_dh_auto_build:
	dh_auto_build
	set -e; \
	for python in $(PYTHON3); do \
		$$python setup.py build ; \
		$$python-dbg setup.py build ; \
	done
	rst2html docs/Features.rst > Features.html

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
override_dh_auto_test:
	-for python in $(PYTHON3); do \
		echo "-- running tests for "$$python" plain --" ; \
		LIB=$$($$python -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print(b.build_platlib)"); \
		PYTHONPATH=$$LIB $$python regex_3/test_regex.py; \
		echo "-- running tests for "$$python" debug --" ; \
		LIB=$$($$python-dbg -c "from distutils.command.build import build ; from distutils.core import Distribution ; b = build(Distribution()) ; b.finalize_options() ; print(b.build_platlib)"); \
		PYTHONPATH=$$LIB $$python-dbg regex_3/test_regex.py; \
	done
endif

override_dh_install:
	set -e; \
	for python in $(PYTHON3); do \
		$$python setup.py install --install-layout=deb --root=$(CURDIR)/debian/python3-regex; \
		$$python-dbg setup.py install --install-layout=deb --root=$(CURDIR)/debian/python3-regex-dbg; \
	done
	# don't install pure python module in dbg pkgs
	rm -rfv $(CURDIR)/debian/python*-regex-dbg/usr/lib/python*/dist-packages/*.py*
	rm -rfv $(CURDIR)/debian/python*-regex-dbg/usr/lib/python*/dist-packages/*.egg-info

override_dh_installdocs:
	dh_installdocs -A README.rst docs/UnicodeProperties.rst docs/Features.rst Features.html

override_dh_strip:
ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
	dh_strip -ppython3-regex --dbg-package=python3-regex-dbg
endif