#!/usr/bin/make -f


export PYBUILD_NAME=typing
export PYBUILD_BEFORE_TEST_python2=cp -v {dir}/python2/test_typing.py {dir}/python2/mod_generics_cache.py {build_dir}
export PYBUILD_BEFORE_TEST_python3=cp -v {dir}/src/test_typing.py     {dir}/src/mod_generics_cache.py     {build_dir}
export PYBUILD_AFTER_TEST_python2=rm -v  {build_dir}/test_typing.py   {build_dir}/mod_generics_cache.py
export PYBUILD_AFTER_TEST_python3=rm -v  {build_dir}/test_typing.py    {build_dir}/mod_generics_cache.py
# Fails with weird error, I think it's related to Python build flags
export PYBUILD_TEST_PYTEST=1
export PYBUILD_TEST_ARGS_python3 = -k-test_typing_compiles_with_opt


# 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 | grep -E '^Version:' | cut -d' ' -f2)
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)


# Only build python3 package if there's at least one version below 3.5
PY3_MIN_VER := $(shell py3versions -rv | rev | cut -d' ' -f1 | rev)
DO_PY3 := $(shell python3 -c 'print("yes" if float("$(PY3_MIN_VER)") < 3.5 else "no")')

# No enable python3 to dh is not sufficient
ifeq ($(DO_PY3),no)
export PYBUILD_DISABLE_python3=1
endif

%:
ifeq ($(DO_PY3),yes)
	dh $@ --with python2,python3 --buildsystem=pybuild
else
	dh $@ --with python2 --buildsystem=pybuild -- --no-package=python3-typing 
endif

override_dh_auto_clean:
	dh_auto_clean
	rm -rf python2/typing.egg-info
	rm -rf .cache

override_dh_gencontrol:
	dh_gencontrol -- -v"$(PKG_VERSION_TAG)"
