#! /usr/bin/make -f

ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
export DH_VERBOSE = 1
export PYBUILD_VERBOSE=1
else
export DH_QUIET = 1
endif

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk

export PYBUILD_DESTDIR_python3=debian/python3-$(DEB_SOURCE)/
export PYBUILD_DESTDIR_python3-dbg=debian/python3-$(DEB_SOURCE)-dbg/

ifneq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
DEB_CXXFLAGS_MAINT_STRIP=-O2
DEB_CXXFLAGS_MAINT_APPEND=-O0
endif

BUILD_DATE=$(shell LC_ALL=C date -u "+%B %d, %Y" -d "@$(SOURCE_DATE_EPOCH)")
SPHINXOPTS:=-D today=\"$(BUILD_DATE)\"
SPHINXOPTS+=-D html_last_updated_fmt=\"$(BUILD_DATE)\"

%:
	dh $@ --buildsystem pybuild

override_dh_auto_configure:
	./configure.py --cl-enable-gl

execute_after_dh_auto_build-indep:
	env HOME=$(mktemp -d) \
	pybuild --build -i python3 -s custom --build-args 'make -C {dir}/doc html'

execute_after_dh_auto_clean:
	$(MAKE) -C doc clean
	$(RM) doc/constants.inc
	$(RM) -r tmp
	$(RM) Makefile siteconf.py

override_dh_auto_test:
	dh_auto_test -- -s custom --test-args="PYTHONPATH={build_dir} cp -r {dir}/test {build_dir} && cd {build_dir}/test && {interpreter} -m pytest --verbosity=2 -k 'not test_event_set_callback' && rm -rf {build_dir}/test"

override_dh_strip:
ifeq (,$(filter nostrip,$(DEB_BUILD_OPTIONS)))
	dh_strip -ppython3-$(DEB_SOURCE) --dbg-package=python3-$(DEB_SOURCE)-dbg
endif
