#!/usr/bin/make -f

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

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export PYBUILD_NAME = h5py

export CC = h5pcc

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

override_dh_auto_clean:
	dh_auto_clean
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C docs clean
	$(MAKE) -C docs_api clean
endif

override_dh_auto_configure:
	python3 setup.py configure --mpi

override_dh_auto_build: export http_proxy=127.0.0.1:9
override_dh_auto_build: export https_proxy=127.0.0.1:9
override_dh_auto_build:
	dh_auto_build
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	python3 setup.py build_ext --inplace
	PYTHONPATH=$(CURDIR) $(MAKE) -C docs html
	PYTHONPATH=$(CURDIR) $(MAKE) -C docs_api html
endif

override_dh_auto_test:
ifneq (nocheck,$(findstring nocheck,$(DEB_BUILD_OPTIONS)))
	set -e; for DIR in $$(find .pybuild/cpython3* -name build | grep -v _dbg_); do \
		cd $$DIR; PYTHONPATH=. python$$(echo $$DIR | sed -e 's@.*cpython._\(.*\)_h5py.*@\1@g') \
		-c "from sys import exit; import h5py; exit(h5py.run_tests('-v'))"; \
		cd ../../..; done
endif

override_dh_python3:
	dh_python3
	dh_numpy3

override_dh_installdocs-indep:
	dh_installdocs
	grep "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js" debian/python-h5py-doc/usr/share/doc/python-h5py-doc/html/* -R --files-with-matches | xargs sed "s|https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/latest.js|file://usr/share/javascript/mathjax/unpacked/latest.js|g" -i

override_dh_strip-arch:
	dh_strip --package=python3-$(PYBUILD_NAME) \
		--dbg-package=python3-$(PYBUILD_NAME)-dbg
