#!/usr/bin/make -f

include /usr/share/dpkg/pkg-info.mk

export SETUPTOOLS_SCM_PRETEND_VERSION_FOR_CHERRYPY_FOUNDATION := $(DEB_VERSION_UPSTREAM)

# Force use of pyproject.toml
export PYBUILD_SYSTEM=pyproject

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

# Generate documentation
execute_after_dh_auto_build:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	PYTHONPATH=. python3 -m sphinx -N -b html doc build/html
endif

# For testing, we need a timezone
override_dh_auto_test:
	TZ=UTC dh_auto_test

# Remove tests files
execute_after_dh_auto_install:
	find debian/tmp/usr/lib/python$(PYTHON3_DEFAULT)/dist-packages/cherrypy_foundation -type d -name "tests" -exec rm -rf {} +

execute_before_dh_auto_clean:
	rm -rf *.egg-info
# Clean Sphinx build artifacts
	rm -rf build/html docs/_build

# Generate orig.tar.gz
gentarball:
	git archive --format=tar HEAD --prefix=$(DEB_SOURCE)-$(DEB_VERSION_UPSTREAM)/ | gzip -9 > ../$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.gz
	mk-origtargz --compression gzip ../$(DEB_SOURCE)_$(DEB_VERSION_UPSTREAM).orig.tar.gz
