#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1

export PYBUILD_NAME=samplerate

# hardening
CPPFLAGS:=$(shell dpkg-buildflags --get CPPFLAGS)
CFLAGS:=$(shell dpkg-buildflags --get CFLAGS) $(CPPFLAGS)
CXXFLAGS:=$(shell dpkg-buildflags --get CXXFLAGS) $(CPPFLAGS)
LDFLAGS:=$(shell dpkg-buildflags --get LDFLAGS)

%:
	dh $@ --buildsystem=pybuild --with sphinxdoc

PYTHON313PATH=.pybuild/cpython3_3.13_samplerate/build

# If you need to rebuild the Sphinx documentation:
# Add sphinxdoc to the dh --with line.
#
execute_after_dh_auto_build-indep: export http_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep: export https_proxy=127.0.0.1:9
execute_after_dh_auto_build-indep:
	PYTHONPATH=$(PYTHON313PATH) \
	python3 -m sphinx -N -bhtml \
	docs/ build/html # HTML generator
	: # remove privacy-breach stuff related to https://ghbtns.com/
	for f in $$(grep -rl ghbtns.com build/html); do \
	  sed -i '/<iframe src="https:..ghbtns.com/ d' $$f; \
	done
	: # replace queries to PYPI's website with static files
	sed -i  -e 's%src="https://readthedocs.org/projects/python-samplerate/badge/.version=latest"%src="doc-images/badge-readthedocs-latest.svg"%' \
	  -e 's%src="https://img.shields.io/pypi/l/samplerate.svg"%src="doc-images/license_ MIT.svg"%' \
	  -e 's%src="https://img.shields.io/pypi/pyversions/samplerate.svg"%src="doc-images/python_ 3.svg"%' \
	  -e 's%src="https://img.shields.io/pypi/v/samplerate.svg"%src="doc-images/version_0.2.svg"%' \
	  -e 's%src="https://img.shields.io/pypi/wheel/samplerate.svg"%src="doc-images/wheel_ yes.svg"%' \
	  build/html/index.html
	PYTHONPATH=$(PYTHON313PATH) \
	python3 -m sphinx -N -bman \
	docs/ build/man # Manpage generator

override_dh_auto_test:
	PYTHONPATH=$(PYTHON313PATH) pytest

override_dh_auto_clean:
	rm -f src/samplerate.egg-info/SOURCES.txt
	dh_auto_clean
