#! /usr/bin/make -f

export PYBUILD_NAME=can
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
	-find debian/python3-can -name test.trc -delete

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

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)


DEB_COPYRIGHT_CHECK_IGNORE_REGEX = \
        debian/.*|doc/images/.*\.png
# licensecheck v1
.PHONY: licensecheck
licensecheck:
	licensecheck \
		-i "^($(DEB_COPYRIGHT_CHECK_IGNORE_REGEX))$$" \
		--check '.*' --recursive --deb-machine --lines 0 * \
		> debian/copyright_newhints
	cmp debian/copyright_hints debian/copyright_newhints \
		&& rm debian/copyright_newhints
