#!/usr/bin/make -f
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
export DEB_HOST_MULTIARCH
DEB_DEBIAN_DIR=$(dir $(firstword $(MAKEFILE_LIST)))
VER=$(shell dpkg-parsechangelog -l$(DEB_DEBIAN_DIR)/changelog \
              | sed -rne 's,^Version: ([^-]+).*,\1,p')
GITREV=$(shell echo $(VER) | sed -rne 's,^[0-9]+\.[0-9]+.*\+[0-9]+\+g([0-f]{8})$$,\1,p' -e 's,^([0-9]+\.[0-9]+(\.[0-9]+)?)$$,v\1,p')
GITCOUNT=$(shell echo $(VER) | sed -rne 's,^[0-9]+\.[0-9]+.*\+([0-9]+)\+g[0-f]{8}$$,\1,p')

%:
	dh $@ --with python3 --parallel

override_dh_auto_configure:
	dh_auto_configure -- -DLIB_SUFFIX="/$(DEB_HOST_MULTIARCH)" -DGR_GIT_COUNT="$(GITCOUNT)" -DGR_GIT_HASH="$(GITREV)"

override_dh_auto_install:
	rm -f debian/gr-soapy/usr/lib/python3/dist-packages/soapy/*pyc
	rm -f debian/gr-soapy/usr/lib/python3/dist-packages/soapy/*pyo
	dh_auto_install

version-to-get:
	echo $(VER) is $(GITREV)

get-orig-source: version-to-get
	git clone https://gitlab.com/librespacefoundation/gr-soapy.git .gr-soapy
	cd .gr-soapy && git archive --format=tar --prefix=gr-soapy-$(VER)/ $(GITREV) | xz > ../gr-soapy_$(VER).orig.tar.xz
	rm -rf .gr-soapy
