#!/usr/bin/make -f

export PYBUILD_NAME=importlib-resources
export PYBUILD_TEST_PYTEST=1
export PYBUILD_TEST_ARGS=-v
# Failing on 3.4 but it looks like related more to test than to module
export PYBUILD_TEST_ARGS_python3.4=-v -k "not test_reading and not test_remove_in_context_manager and not test_is_resource_good_path and not test_is_resource_subresource_directory and not test_is_submodule_resource and not test_read_submodule_resource_by_name"
export PYBUILD_AFTER_INSTALL_python2=rm -rf '{destdir}/{install_dir}/importlib_resources/_py3.py' '{destdir}/{install_dir}/importlib_resources/tests' '{destdir}/{install_dir}/importlib_resources/docs'
export PYBUILD_AFTER_INSTALL_python3=rm -rf '{destdir}/{install_dir}/importlib_resources/_py2.py' '{destdir}/{install_dir}/importlib_resources/tests' '{destdir}/{install_dir}/importlib_resources/docs'

# Get version from changelog as well as lsb_release
# to compute unique build version (useful for repo mirroring systems doing file pooling)
PKG_VERSION  := $(shell dpkg-parsechangelog | egrep '^Version:' | cut -f 2 -d ' ')
DIST_NAME    := $(shell lsb_release -si)
DIST_RELEASE := $(shell lsb_release -sc)
DIST_VERSION := $(shell lsb_release -sr)
PKG_VERSION_TAG := $(PKG_VERSION)+$(DIST_NAME).$(DIST_RELEASE).$(DIST_VERSION)
SUBSTVARS_BINARY_VERSION := -Vbinary:Version="$(PKG_VERSION_TAG)"
SUBSTVARS_SOURCE_VERSION := -Vsource:Version="$(PKG_VERSION_TAG)"

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

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bhtml importlib_resources/docs/ build/html
	PYTHONPATH=. http_proxy='127.0.0.1:9' sphinx-build -N -bman  importlib_resources/docs/ build/man

override_dh_gencontrol:
	dh_gencontrol -- -v"$(PKG_VERSION_TAG)" $(SUBSTVARS_R_DEPENDS) $(SUBSTVARS_BINARY_VERSION) $(SUBSTVARS_SOURCE_VERSION)
