#!/usr/bin/make -f

export PYBUILD_NAME = gfmetadata
include /usr/share/dpkg/pkg-info.mk
export SETUPTOOLS_SCM_PRETEND_VERSION = $(DEB_VERSION_UPSTREAM)

# Upstream ships *_pb2.py generated by a recent protoc, which refuses to load
# on an older python3-protobuf runtime. Regenerate them from the .proto
# sources with Debian's protoc, overwriting the upstream copies that pybuild
# installed into its build directory.
export PYBUILD_AFTER_BUILD = protoc -I resources/protos \
	--python_out={build_dir}/gfmetadata resources/protos/*.proto

# The generated code must not be newer than the python3-protobuf runtime it
# runs on, so depend on at least the version present at build time.
PROTOBUF_VERSION := $(shell dpkg-query -W -f '$${Version}' python3-protobuf | sed -e 's/-[^-]*$$//')

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_gencontrol:
	dh_gencontrol -- -Vprotobuf:Version=$(PROTOBUF_VERSION)
