#!/usr/bin/make -f
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
export DH_VERBOSE = 1
export LC_ALL=C.UTF-8

DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

export PYBUILD_NAME=isospec

# 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 python3 --buildsystem=pybuild --sourcedirectory=IsoSpecPy

override_dh_clean:
	rm -rf IsoSpec++/build
	# The setup.py script immediately creates that link which
	# make the package building top because it find that 
	# the source tree has changed. So, first remove that link,
	# that we'll recreate when we need it later, in the
	# override_dh_auto_build target.
	rm -rf IsoSpecPy/IsoSpec++
	dh_clean

# Handle the C++ library apart
override_dh_auto_build:
	# Recreate the symlink that was created by setup.py 
	# and that we had to remove at the override_dh_clean target.
	ln -sf IsoSpec++ IsoSpecPy/IsoSpec++
	cd IsoSpec++ && mkdir -p build && cd build && cmake ../ && make

# Generate the dev-doc in the man/hml and man/latex directories
	doxygen man/doxyfile
# Remove Doxygen-generated file that has no use.
	#rm man/man/man3/_home_rusconi_*

# sed-based replacement of the cloudflare URL with the MathJax.js file from the
# libjs-mathjax package
	sh debian/replace-mathjax-cloudflare-url-local-file.sh

# Actually craft the refman.pdf file.
	cd man/latex && make

override_dh_auto_install:
	dh_auto_install -O--buildsystem=R --sourcedirectory=IsoSpecR
# Remove the license file.
	rm debian/tmp/usr/lib/R/site-library/IsoSpecR/LICENCE
	mv debian/tmp tmp-install
	dh_auto_install

