#!/usr/bin/make -f

export PYBUILD_NAME=freesas

# 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,freesas/,*.pyx)
#NOTA: No space before *

%:
	dh $@ --with python2,python3 --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 *.egg-info

override_dh_auto_build:
	dh_auto_build
	python setup.py build build_man build_doc

override_dh_install:
	dh_numpy
	dh_numpy3

	# move the scripts to right package
	dh_install -p freesas debian/python3-freesas/usr/bin/* usr/bin
#	dh_install -p freesas package/desktop/*.desktop usr/share/applications
#	dh_install -p freesas package/desktop/freesas.png usr/share/icons/hicolor/48x48/apps
#	dh_install -p freesas package/desktop/freesas.svg usr/share/icons/hicolor/scalable/apps
#	dh_install -p freesas package/desktop/freesas.xml usr/share/mime/packages
	rm -rf debian/python-freesas/usr/bin
	rm -rf debian/python3-freesas/usr/bin

	# remove all py/pyc/egg-info files from dbg packages
	# find debian/python-freesas-dbg/usr -type f \( -not -name "*.so" \) -delete
	# find debian/python3-freesas-dbg/usr -type f \( -not -name "*.so" \) -delete

	dh_install

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

override_dh_installman:
	dh_installman -p freesas build/man/*.1

override_dh_installdocs:
	dh_installdocs "build/sphinx/html" -p python-freesas-doc
	dh_installdocs
