#!/usr/bin/make -f

export PYBUILD_NAME=cupy
export PYBUILD_TEST_PYTEST=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)

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

override_dh_auto_clean:
	dh_auto_clean
	rm -rf .eggs .pytest_cache .cache
	# Cython generated
	rm -f cupy/core/_dtype.cpp \
	      cupy/core/_kernel.cpp \
	      cupy/core/_scalar.cpp \
	      cupy/core/core.cpp \
	      cupy/core/dlpack.cpp \
	      cupy/core/flags.cpp \
	      cupy/core/internal.cpp \
	      cupy/core/raw.cpp \
	      cupy/cuda/cublas.cpp \
	      cupy/cuda/cudnn.cpp \
	      cupy/cuda/cufft.cpp \
	      cupy/cuda/curand.cpp \
	      cupy/cuda/cusolver.cpp \
	      cupy/cuda/cusparse.cpp \
	      cupy/cuda/device.cpp \
	      cupy/cuda/driver.cpp \
	      cupy/cuda/function.cpp \
	      cupy/cuda/memory.cpp \
	      cupy/cuda/memory_hook.cpp \
	      cupy/cuda/nccl.cpp \
	      cupy/cuda/nvrtc.cpp \
	      cupy/cuda/nvtx.cpp \
	      cupy/cuda/pinned_memory.cpp \
	      cupy/cuda/profiler.cpp \
	      cupy/cuda/runtime.cpp \
	      cupy/cuda/stream.cpp \
	      cupy/cuda/thrust.cpp \
	      cupy/cuda/thrust.h \
	      cupy/cudnn.cpp \
	      cupy/util.cpp

override_dh_auto_test:
	# Cannot run if build on a machin without NVIDIA GPU
	-dh_auto_test

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