#!/usr/bin/make -f

%:
	dh $@ --buildsystem R

RMBVERSION := $(shell dpkg-query -W -f='$${Version}\n' r-cran-matrix)
RVERSION   := $(shell dpkg-query -W -f='$${source:Upstream-Version}\n' r-base-core)

override_dh_fixperms:
	dh_fixperms
	find debian  \( -name "*.R" -o -name "*.txt" \) -exec chmod -x \{\} \;

override_dh_gencontrol:
	sed -i "s/r-cran-matrix[^,]*/r-cran-matrix (>= $(RMBVERSION))/"   debian/*substvars
	sed -i "s/\(r-api-[0-9.]\+\),/\1, r-base-core (>= $(RVERSION)),/" debian/*substvars
	dh_gencontrol
