#!/usr/bin/make -f

DH_VERBOSE=1

export PYBUILD_NAME=fastcluster

cranName=fastcluster
R_PATH=/usr/lib/R/site-library
R_NAME=r-cran-$(cranName)

# Taken from CDBS file for R.
rversion	:= $(shell dpkg-query -W -f='$${Version}' r-base-dev)
rapiversion	:= $(shell dpkg-query -W -f='$${Provides}' r-base-core | grep -o 'r-api[^, ]*')

%:
	dh $@ --with python2,python3 --buildsystem=pybuild --sourcedirectory=src/python 

override_dh_auto_clean:
	dh_auto_clean

	# Parts of the following are taken from the CDBS file for F.
	if test -d src; then				\
		find src -regex ".*\.o" |               \
	        xargs --no-run-if-empty -r rm;          \
		find src src -regex ".*\.so" |          \
		xargs --no-run-if-empty -r rm;		\
	fi
	rm -f config.log config.status
	rm -rf tmp-install

override_dh_auto_build:
	dh_auto_build
	mkdir -p tmp-install
	R CMD INSTALL -l tmp-install --clean .


override_dh_install:
	dh_numpy
	dh_numpy3
	echo "R:Depends=r-base-core (>= ${rversion}), ${rapiversion}" >> debian/$(R_NAME).substvars
	dh_install
	rm -rf debian/$(R_NAME)/usr/lib/R/site-library/$(cranName)/LICENSE
