#! /usr/bin/make -f

# Disable internet access
export http_proxy=127.0.0.1:9
export https_proxy=127.0.0.1:9

# Fix pytest order which need rootdir to be set where the tests folder is
# as pytest's nodeid is relative to the rootdir and upstream use that to order
# tests.
# Also a cache is created in the rootdir, explicitly keep it at the original
# location.
# See also: https://github.com/streamlink/streamlink/pull/5888
export PYBUILD_TEST_ARGS=--rootdir=. -o cache_dir=$(CURDIR)/.pytest_cache

%:
	dh $@ --buildsystem=pybuild

# Add LC_ALL=C.UTF-8 LANGUAGE=C.UTF-8 to have reproducible builds
#   sphinx: some strings are localized, see #998059
#   lxml: lxml crashes when LC_ALL uses special encodings (running
#         reprotest would cause a segfault).
export LC_ALL=C.UTF-8
export LANGUAGE=C.UTF-8

override_dh_auto_build:
	PYTHONPATH=$(CURDIR)/src make --directory=docs html man
	sed -i 's/^\.ft C$$/.ft CW/' docs/_build/man/streamlink.1
	dh_auto_build

# Explicitly uses CHANGELOG.md instead of docs/changelog.md (the default
# file used by dh_installchangelogs)
override_dh_installchangelogs:
	dh_installchangelogs CHANGELOG.md

# Needed to prevent docs/changelog.html from being compressed
override_dh_compress:
	dh_compress -X.html

override_dh_link:
	dh_link
	jdupes -rl debian/python3-streamlink-doc/usr/share/doc/python3-streamlink/html

# Needed to correctly include non-windows dependencies
override_dh_python3:
	dh_python3 --depends-section=':platform_system != "Windows"'