#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
source=$(shell head -n 1 debian/changelog | cut -d ' ' -f 1)

%:
	dh $@ --with autoreconf,python3

override_dh_auto_configure:
	dh_auto_configure -- --libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) \
	                     --with-module-bindir=\$${prefix}/lib/speech-dispatcher-modules \
	                     pidpath=/var/run/speech-dispatcher/

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

ifeq ($(source),speech-dispatcher)
override_dh_strip:
	dh_strip --dbg-package=speech-dispatcher-dbg

override_dh_installinit:
	dh_installinit -a --error-handler=true

override_dh_fixperms:
	dh_fixperms
	chmod 700 $(CURDIR)/debian/speech-dispatcher/var/log/speech-dispatcher

override_dh_makeshlibs:
	dh_makeshlibs -plibspeechd2
endif

# Switch to main rules
main:
	sed -i '1s/^speech-dispatcher-contrib /speech-dispatcher /' debian/changelog
	sed -i '1s/^Source: speech-dispatcher-contrib$$/Source: speech-dispatcher/' debian/control
	sed -i 's/^ libttspico-dev/# libttspico-dev/' debian/control
	sed -i 's/Package: speech-dispatcher-contrib$$/Package: speech-dispatcher/' debian/control
	sed -i 's/^#* speech-dispatcher-audio-plugins/ speech-dispatcher-audio-plugins/' debian/control
	sed -i '/Package: libspeechd2/,$$s/^#*//' debian/control
	sed -i 's_^Section: contrib/_Section: _' debian/control

# Switch to contrib rules
contrib:
	sed -i '1s/^speech-dispatcher /speech-dispatcher-contrib /' debian/changelog
	sed -i '1s/^Source: speech-dispatcher$$/Source: speech-dispatcher-contrib/' debian/control
	sed -i 's/^#* libttspico-dev/ libttspico-dev/' debian/control
	sed -i 's/Package: speech-dispatcher$$/Package: speech-dispatcher-contrib/' debian/control
	sed -i 's/^ speech-dispatcher-audio-plugins/# speech-dispatcher-audio-plugins/' debian/control
	sed -i '/Package: libspeechd2/,$$s/^/#/' debian/control
	sed -i 's_^Section: \([^/]*\)$$_Section: contrib/\1_' debian/control
