#!/usr/bin/make -f

# must be before including anything
debian_dir := $(abspath $(dir $(lastword $(MAKEFILE_LIST))))

include /usr/share/dpkg/default.mk

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

override_dh_autoreconf:
	NOCONFIGURE=1 dh_autoreconf ./autogen.sh --

override_dh_auto_configure:
	dh_auto_configure \
		PYTHON=/usr/bin/python3 \
		$(NULL)

override_dh_auto_build:
	dh_auto_build
	sed -e 's!@docdir@!/usr/share/doc/mpdris2!' \
		< debian/mpDris2.1.in \
		> debian/mpDris2.1

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp
	sed -i -e '1s,.*,#!/usr/bin/python3,' debian/tmp/usr/bin/mpDris2

override_dh_install:
	rm -f debian/tmp/usr/share/doc/mpdris2/COPYING
	dh_install --fail-missing

#-- orig tarball for snapshots ----------------------------------------

ORIG_REPO ?= https://github.com/eonpatapon/mpDris2.git
ORIG_RELEASE = 0.7
ORIG_SUFFIX = +git20180205
ORIG_COMMIT = 3de5317c57cd6ccdf99f4846c872fe6147e7c662

# can't use DEB_SOURCE because this is meant to be invokable from anywhere
get-orig-source:
	set -e; \
	$(debian_dir)/git-archive-orig.py \
		--debian-dir=$(debian_dir) \
		$(ORIG_REPO) \
		$(ORIG_COMMIT) \
		"$$(cd "$(debian_dir)"/.. && dpkg-parsechangelog -SSource)" \
		$(ORIG_RELEASE)$(ORIG_SUFFIX) \
		$(NULL)

# to be invoked from a git checkout with upstream github as a remote;
# tarball ends up in ../build-area
maintainer-get-orig-source:
	set -e; \
	cd ../build-area; \
	$(MAKE) -f $(debian_dir)/rules get-orig-source \
		ORIG_REPO=$(debian_dir)/../.git
	@echo "try using:"
	@echo "gbp import-orig --upstream-vcs-tag=${ORIG_COMMIT} ../build-area/${DEB_SOURCE}_${ORIG_RELEASE}${ORIG_SUFFIX}.orig.tar.xz"
