#! /usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

export PYBUILD_NAME=rapidfuzz
export PYBUILD_TEST_PYTEST=1

export SKBUILD_BUILD_VERBOSE = 1
export SKBUILD_BUILD_DIR = $(CURDIR)/.pybuild-skbuild/{wheel_tag}
export SKBUILD_CMAKE_ARGS = -DCMAKE_C_FLAGS=$(CFLAGS) $(CPPFLAGS);-DCMAKE_CXX_FLAGS=$(CXXFLAGS) $(CPPFLAGS)

SPHINXBUILD=sphinx-build
SPHINXBUILDDIR=build


%:
	dh $@ --buildsystem=pybuild

execute_before_dh_auto_build:
	# scikit-build-core prints a success message via its
	# messages.after-success hook that blhc misreads as a hidden
	# compiler command
	@echo 'blhc: ignore-line-regexp: .*C\+\+ Extension built successfully.*'

execute_after_dh_auto_build-indep:
	: # ensure that this target is non-empty
ifeq (,$(findstring nodoc,$(DEB_BUILD_OPTIONS)))
	export PYTHONPATH=$$(pybuild --print build_dir | grep "^$$(py3versions -d)" | sed -e 's/^.*: //'); \
	    cd docs && $(SPHINXBUILD) -b html -d $(SPHINXBUILDDIR)/doctrees . $(SPHINXBUILDDIR)/html
endif

override_dh_auto_test-indep:
	# No need to run tests when only building documentation package

execute_after_dh_auto_clean:
	rm -rf docs/$(SPHINXBUILDDIR)
	rm -rf buildlib _skbuild
	rm -rf $(CURDIR)/.pybuild-skbuild

override_dh_installdocs:
	dh_installdocs -ppython-$(PYBUILD_NAME)-doc --doc-main-package=python3-$(PYBUILD_NAME)
	dh_installdocs --remaining-packages
