#!/usr/bin/make -f
export PYBUILD_NAME = plac

ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
export PYBUILD_TEST_ARGS = -vv
endif

%:
	dh $@ --buildsystem=pybuild

override_dh_auto_build:
 # Build HTML documentation with Sphinx
	dh_auto_build
	if [ -f doc/conf.py ]; then \
	    mkdir -p doc/_build/html; \
	    sphinx-build -b html -D html_theme=alabaster \
	        -A today="" -A release="" -A version="" \
	        doc doc/_build/html || echo "Documentation build failed, continuing..."; \
	    rm -rf doc/_build/html/.doctrees; \
	    rm -rf doc/_build/html/_sources; \
	    rm -f doc/_build/html/_static/doctools.js; \
	    rm -f doc/_build/html/_static/language_data.js; \
	    rm -f doc/_build/html/_static/searchtools.js; \
	fi

execute_after_dh_auto_install:
	find . -type d -name '__pycache__' -exec rm -rf {} +

 # Force deterministic order by recompiling bytecode
	if [ -d debian/python3-plac ]; then \
	    find debian/python3-plac -name '*.pyc' -delete; \
	    find debian/python3-plac -name '*.pyo' -delete; \
	    find debian/python3-plac -name '__pycache__' -type d -exec rm -rf {} +; \
	    PYTHONHASHSEED=1 python3 -m compileall -q -f debian/python3-plac; \
	fi

 # Recognize file.<ext>.1 format
override_dh_installman:
	dh_installman --language=C
