#!/usr/bin/make -f

export PYBUILD_NAME=onnx

export ONNX_ML=1
# Could not figure out how to use them
# But be sure to have internet access to download some googletest stuff
# (Override http_proxy/https_proxy env for dh_auto_build, as it is set
# to bad value on purpose
#export ONNX_BUILD_TESTS=1

# 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)
SUBSTVARS_BINARY_VERSION := -Vbinary:Version="$(PKG_VERSION_TAG)"
SUBSTVARS_SOURCE_VERSION := -Vsource:Version="$(PKG_VERSION_TAG)"

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

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .eggs
	rm -rf .setuptools-cmake-build-*
	rm -f onnx/version.py onnx/onnx_ml_pb2.py onnx/onnx_ml_pb2.pyi onnx/onnx_operators_ml_pb2.py onnx/onnx_operators_ml_pb2.pyi onnx/onnx_operators_pb.py onnx/onnx_pb.py

override_dh_install:
	dh_install
	mv debian/python-onnx/usr/bin/check-node debian/python-onnx/usr/bin/check-node-py2
	mv debian/python-onnx/usr/bin/check-model debian/python-onnx/usr/bin/check-model-py2
	mv debian/python-onnx/usr/bin/backend-test-tools debian/python-onnx/usr/bin/backend-test-tools-py2
	mv debian/python3-onnx/usr/bin/check-node debian/python3-onnx/usr/bin/check-node-py3
	mv debian/python3-onnx/usr/bin/check-model debian/python3-onnx/usr/bin/check-model-py3
	mv debian/python3-onnx/usr/bin/backend-test-tools debian/python3-onnx/usr/bin/backend-test-tools-py3
	ln -fs /usr/bin/check-node-py3 debian/python3-onnx/usr/bin/check-node
	ln -fs /usr/bin/check-model-py3 debian/python3-onnx/usr/bin/check-model
	ln -fs /usr/bin/backend-test-tools-py3 debian/python3-onnx/usr/bin/backend-test-tools

override_dh_auto_test:

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

