#!/usr/bin/make -f

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

export PYBUILD_AFTER_INSTALL=rm -rf {destdir}/usr/bin/ {destdir}/usr/pynx/
export PYBUILD_DISABLE=test
export PYBUILD_NAME=pynx

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


override_dh_clean:
	dh_clean
	rm -f $(patsubst %.pyx,%.c,${ALL_PYX})

override_dh_install:
	dh_numpy3

        # install scripts
	python3 setup.py install_scripts -d debian/pynx/usr/bin

	dh_install

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