#! /usr/bin/make -f

export PYBUILD_NAME=can
export PYBUILD_BEFORE_TEST=cp -r {dir}/test {build_dir}
export PYBUILD_TEST_ARGS=-k 'not BasicTestUdpMulticastBusIP'

include /usr/share/dpkg/default.mk
export DEB_VERSION_UPSTREAM

%:
	dh $@ --buildsystem=pybuild

execute_after_dh_clean:
	rm -f test.asc test.csv
	rm -rf .pytest_cache/

execute_after_dh_auto_build:
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS) $(DEB_BUILD_PROFILES)))
	PYTHONPATH=$(CURDIR) python3 -m sphinx \
		   -E -T -b html \
		   doc $(CURDIR)/.pybuild/docs/html/
endif

execute_after_dh_auto_install:
	-for f in debian/*/usr/bin/*.py; do mv $$f $${f%.py}; done
	-rm -f debian/*/usr/lib/python*/dist-packages/test.???
	-rm -rf debian/*/usr/lib/python*/dist-packages/test/

override_dh_installdocs:
	dh_installdocs --doc-main-package=python3-can -p python-can-doc
	dh_installdocs --remaining-packages

licensecheck:
	licensecheck --deb-machine -r * \
		> debian/copyright_newhints
	cmp debian/copyright_hints debian/copyright_newhints \
		&& rm debian/copyright_newhints

manpages=debian/can_logger.1 debian/can_player.1 debian/can_viewer.1


$(manpages): debian/helper2man
	cp $^ $(@:.1=)
	help2man -N -o $@ ./$(@:.1=)
	-rm $(@:.1=)

.PHONY: manpages
manpages: $(manpages)
