#!/usr/bin/make -f

export PYTHONPATH := $(CURDIR):$(CURDIR)/script:$(CURDIR)/doc:$(PYTHONPATH);
export HOME := $(CURDIR)/debian/HOME
export QT_QPA_PLATFORM := offscreen

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_auto_clean:
	rm -rf .pybuild
	rm -rf _skbuild
	rm -rf VERSION
	rm -rf doc/_build
	rm -rf doc/output
	rm -rf doc/developer_guide.rst
	rm -rf doc/solver_table.rst
	rm -rf doc/src/sfepy/terms/terms_jax.rst
	rm -rf doc/term_table.rst
	rm -rf doc/field_table.rst
	rm -rf site_cfg.py
	find . -type f -name "version.h" -delete
	find . -type f -name "*.so" -delete
	find . -type f -name "*.pdf" -delete

execute_after_dh_auto_configure:
	mkdir -p $(HOME)/.sfepy
	# Build C extensions using scikit-build
	python3 setup.py build_ext --inplace

execute_after_dh_auto_build:
	# Build documentation
	$(MAKE) all
	$(MAKE) htmldocs
	$(MAKE) pdfdocs
	cd doc; $(MAKE) man
	cd doc/_build/latex; pdflatex SfePy.tex; pdflatex SfePy.tex

override_dh_auto_install:
	python3 setup.py install --force --root=$(CURDIR)/debian/tmp --no-compile --install-layout=deb

override_dh_auto_test:

execute_after_dh_python3:
	dh_numpy3

override_dh_installdocs:
	find . -type d -name "__pycache__" -exec rm -r {} +
	dh_installdocs
	dh_sphinxdoc
	rm -rf $(CURDIR)/debian/python3-sfepy/usr/lib/python3*/dist-packages/sfepy/LICENSE
	rm -rf $(CURDIR)/debian/python-sfepy-doc/usr/share/doc/python-sfepy-doc/html/_sources/license.txt
