#!/usr/bin/make -f
# debian/rules file for the Debian GNU/Linux python-rpy2 package
# Copyright 2004 - 2023 by Dirk Eddelbuettel <edd@debian.org>

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

build3vers      := $(shell py3versions -sv)

version         := $(shell head -1 debian/changelog | perl -nle 'm/\((.*)-\d\)/ && print $$1')

showversion:
	@echo "Version is ${version}"

tarball:
	(cd .. && \
		tar czf ../$(project)_${version}.orig.tar.gz ./$(project) \
			--exclude=.svn --exclude=debian/ --exclude=.hg)

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

# remove the wheel file after each build, as pybuild built_wheel() fails if it finds more than one
override_dh_auto_build:
	PYBUILD_DIR=rpy2-rinterface dh_auto_build
	rm -fv .pybuild/*/*.whl
	PYBUILD_DIR=rpy2-robjects dh_auto_build
	rm -fv .pybuild/*/*.whl
	dh_auto_build

# we set TZ because some tests fail in GMT+/-X timezones (e.g. reprotest default)
# and language because some tests check R error messages and expect the English version
override_dh_auto_test:
	TZ=America/New_York LC_ALL=C.UTF-8 LANGUAGE=C.UTF-8 dh_auto_test
	find -type f -name Rplots.pdf -delete

override_dh_installdocs:
	dh_installdocs -a NEWS

execute_after_dh_auto_clean:
	rm -rfv .pybuild build */build src/*.egg-info */src/*.egg-info
	find . -name __pycache__ | rm -rfv
