#!/usr/bin/make -f

rwildcard=$(wildcard $1$2) $(foreach d,$(wildcard $1*),$(call rwildcard,$d/,$2))

# How to recursively find all files with the same name in a given folder
ALL_PYX := $(call rwildcard,gpyfft/,*.pyx)
#NOTA: No space before *

export PYBUILD_AFTER_INSTALL_python2=dh_numpy
export PYBUILD_AFTER_INSTALL_python3=dh_numpy3
export PYBUILD_DISABLE=test
export PYBUILD_NAME=gpyfft

%:
	dh $@ --with python2,python3,sphinxdoc --buildsystem=pybuild

override_dh_clean:
	dh_clean
	rm -f $(patsubst %.pyx,%.c,${ALL_PYX})
	rm -f gpyfft/*.so
	rm -rf docs/build

override_dh_sphinxdoc:
ifeq (,$(findstring nodocs, $(DEB_BUILD_OPTIONS)))
	PYBUILD_SYSTEM=custom \
	PYBUILD_BUILD_ARGS="cd docs && PYTHONPATH={build_dir} http_proxy='127.0.0.1:9' {interpreter} -m sphinx -N -bhtml source build/html" dh_auto_build  # HTML generator
	dh_installdocs "docs/build/html" -p python-gpyfft-doc
	dh_sphinxdoc -O--buildsystem=pybuild
endif
