#!/usr/bin/make -f

export DH_VERBOSE = 1
export LC_ALL = C.UTF-8
export VERSION = $(shell head -n1 debian/changelog | cut -d' ' -f2 | tr -d '()')
export BUILDBOT_VERSION = $(VERSION)

override_dh_auto_clean \
override_dh_auto_configure \
override_dh_auto_build:
	$(@:override_%=%) --buildsystem=pybuild --sourcedirectory=master \
		--package=buildbot
	$(@:override_%=%) --buildsystem=pybuild --sourcedirectory=worker \
		--package=buildbot-worker
	$(@:override_%=%) --sourcedirectory=master/docs \
		--package=buildbot-doc

test_env = \
	PYTHONPATH=pkg:{destdir}/{install_dir} \
	PATH=$$PATH:{destdir}/usr/bin
test_command = trial3 --reporter=text buildbot.test buildbot_worker.test

override_dh_auto_install:
	dh_auto_install --buildsystem=pybuild --sourcedirectory=master \
		--package=buildbot
	dh_auto_install --buildsystem=pybuild --sourcedirectory=worker \
		--package=buildbot-worker
	dh_auto_install --sourcedirectory=master/docs \
		--package=buildbot-doc --destdir=debian/buildbot-doc
	for f in debian/manpages/*.rst; do \
		rst=`basename $$f` && \
		mkdir -p debian/tmp/manpages && \
		rst2man $$f debian/tmp/manpages/$${rst%.rst} || exit; \
	done
	dh_auto_test --buildsystem=pybuild -- --system=custom \
		--test-args='$(test_env) $(test_command)'

override_dh_auto_test:
	:

override_dh_installinit:
	dh_installinit --no-scripts

override_dh_installsystemd:
	dh_installsystemd --no-enable --no-start -r --no-restart-after-upgrade
	ln -s /dev/null debian/buildbot/lib/systemd/system/buildbot.service
	ln -s /dev/null debian/buildbot/lib/systemd/system/buildmaster.service
	ln -s /dev/null debian/buildbot-worker/lib/systemd/system/buildbot-worker.service

%:
	dh $@ --with python3,bash-completion,sphinxdoc
