#!/usr/bin/make -f

export DH_VERBOSE=1
export PYBUILD_NAME=freesas
export PYBUILD_SYSTEM=pyproject

# Make does not offer a recursive wildcard function, so here's one:
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,src,*.pyx)
#NOTA: No space before *

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

override_dh_clean:
	dh_clean
	# remove the cython generated file to force rebuild
	rm -f $(patsubst %.pyx,%.cpp,${ALL_PYX})
	rm -f $(patsubst %.pyx,%.c,${ALL_PYX})
	rm -f $(patsubst %.pyx,%.html,${ALL_PYX})
	rm -rf build/html
	rm -rf build/man
	rm -rf *.egg-info

override_dh_install:
	dh_numpy3

	# move the scripts to right package
	dh_install -p freesas debian/python3-freesas/usr/bin/* usr/bin
	rm -rf debian/python3-freesas/usr/bin
	dh_install

override_dh_auto_test:
	dh_auto_test -- -s custom --test-args="env PYTHONPATH={build_dir} FREESAS_TESTDATA=../testdata {interpreter} run_tests.py -v"

override_dh_installdocs:
	python3 build-doc.py
	dh_installdocs "build/sphinx" -p freesas-doc
	dh_installdocs
