#!/usr/bin/make -f
# -*- makefile -*-
# Uncomment this to turn on verbose mode.
# export DH_VERBOSE=1

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
export DEB_LDFLAGS_MAINT_APPEND =

# Test does not work when built with system libzstd library
export PYBUILD_TEST_ARGS=-k 'not test_features' \
	--deselect tests/test_module_attributes.py::TestModuleAttributes::test_version

export ZSTD_EXTRA_COMPILER_ARGS = -I/usr/include

# Link both the C extension and the CFFI backend against the system libzstd
export PYBUILD_BUILD_ARGS = \
	--config-setting=--global-option=--system-zstd \
	--config-setting=--global-option=--system-zstd-cffi

%:
	dh $@ --buildsystem=pybuild

# Test both backends, as upstream CI does
override_dh_auto_test:
	PYTHON_ZSTANDARD_IMPORT_POLICY=cext dh_auto_test
	PYTHON_ZSTANDARD_IMPORT_POLICY=cffi dh_auto_test

# The CFFI backend needs a compatible _cffi_backend at run time
override_dh_python3:
	dh_python3 --depends=cffi

execute_after_dh_auto_build:
	cd docs; PYTHONPATH=$(CURDIR)/.pybuild/cpython3_$(shell py3versions -dv)/build \
	    LC_ALL=C.UTF-8 LANGUAGE=C.UTF-8 sphinx-build -bhtml . _build/html

execute_after_dh_installdocs:
	dh_sphinxdoc
