#!/usr/bin/make -f

export PYBUILD_NAME=mutagen

# This is generally a good idea to avoid littering the filesystem with unneeded
# pyc files, but it is also specifically needed to avoid byte-compilation of
# the binaries in tools/ when the test suite is run.
export PYTHONDONTWRITEBYTECODE=yes

# Set UTF-8 locale as the tests expect this
export LC_ALL=C.UTF-8


ifeq ($(filter nodoc,$(DEB_BUILD_PROFILES)),)
SPHINXDOC=,sphinxdoc
else
SPHINXDOC=
endif
%:
	dh $@ --with python2,python3,pypy$(SPHINXDOC) --buildsystem=pybuild

ifeq ($(filter nodoc,$(DEB_BUILD_PROFILES)),)
override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. \
	   http_proxy='127.0.0.1:9' \
	   https_proxy='127.0.0.1:9' \
	   sphinx-build -N -b html docs/ $(CURDIR)/.pybuild/docs/html/
	$(MAKE) -C docs/man
endif


override_dh_auto_install:
	dh_auto_install
	# Don't ship binaries or manpages in the pypy or python3 packages
	rm -rf debian/pypy-mutagen/usr/bin \
	       debian/pypy-mutagen/usr/lib/pypy/share \
	       debian/python3-mutagen/usr/bin \
	       debian/python3-mutagen/usr/share


override_dh_installchangelogs:
	dh_installchangelogs NEWS


override_dh_clean:
	dh_clean
	rm -rf docs/man/_man


override_dh_auto_test:
	PYBUILD_SYSTEM=custom \
	PYBUILD_TEST_ARGS="{interpreter} setup.py test" dh_auto_test
