#!/usr/bin/make -f

export DH_VERBOSE = 1

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=python3-buildbot -- --name=buildbot
	$(@:override_%=%) --buildsystem=pybuild --sourcedirectory=worker \
		--package=python3-buildbot-worker -- --name=buildbot_worker
	$(@:override_%=%) --sourcedirectory=master/docs \
		--package=python3-buildbot-doc

space :=
space +=
test_pythonpaths = \
	$(CURDIR)/pkg \
	$(CURDIR)/debian/python3-buildbot/{install_dir} \
	$(CURDIR)/debian/python3-buildbot-worker/{install_dir}
test_env = PYTHONPATH=$(subst $(space),:,$(test_pythonpaths)) LC_ALL=C.UTF-8
test_command = trial3 --reporter=text buildbot.test buildbot_worker.test

override_dh_auto_install:
	dh_auto_install --buildsystem=pybuild --sourcedirectory=master \
		--package=python3-buildbot -- --name=buildbot \
		--after-install='rm {destdir}/usr/bin/buildbot_windows_service'
	dh_auto_install --buildsystem=pybuild --sourcedirectory=worker \
		--package=python3-buildbot-worker -- --name=buildbot_worker \
		--after-install='rm {destdir}/usr/bin/buildbot_worker_windows_service'
	dh_auto_install --sourcedirectory=master/docs \
		--package=python3-buildbot-doc
	dh_auto_test --buildsystem=pybuild -- --system=custom \
		--test-args='$(test_env) $(test_command)'

override_dh_auto_test:
	:

override_dh_systemd_enable:
	:

override_dh_systemd_start:
	dh_systemd_start --no-start

override_dh_installinit:
	dh_installinit --package=python3-buildbot --name=buildmaster
	dh_installinit --package=python3-buildbot --name=buildmaster@ --no-scripts
	dh_installinit --package=python3-buildbot-worker --name=buildbot-worker
	dh_installinit --package=python3-buildbot-worker --name=buildbot-worker@ --no-scripts

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