#!/usr/bin/make -f
# -*- makefile -*-

#export DH_VERBOSE=1

include /usr/share/dpkg/pkg-info.mk

MAJOR = $(shell echo $(DEB_VERSION_UPSTREAM) | cut -f1 -d ".")
MINOR = $(shell echo $(DEB_VERSION_UPSTREAM) | cut -f2 -d ".")
MICRO = $(shell echo $(DEB_VERSION_UPSTREAM) | cut -f3 -d ".")

export PYBUILD_NAME=pytest_snapshot

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_clean:
	dh_auto_clean
	rm -f $(PYBUILD_NAME)/_version.py
	rm -rf .mypy_cache .pytest_cache

override_dh_auto_build:
	# Upstream is using setuptools_scm to write the version data, we ned to
	# work around that and write the data manually.
	@echo "Using upstream version '$(DEB_VERSION_UPSTREAM)' to prepare version data for $(PYBUILD_NAME)/_version.py"
	@echo "version = '$(MAJOR).$(MINOR).$(MICRO)'" > $(PYBUILD_NAME)/_version.py
	@echo "version_tuple = ($(MAJOR), $(MINOR), $(MICRO))" >> $(PYBUILD_NAME)/_version.py
	dh_auto_build
