#!/usr/bin/make -f
# -*- makefile -*-
# See debhelper(7) (uncomment to enable)
# output every command that modifies files on the build system.
#export DH_VERBOSE = 1
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

FLAVORS = cli gui
CONFIG_cli = -config nogui
CONFIG_gui = -config rtaudio


builddir=debian/build/flavor-

export QT_SELECT=qt5
DEB_SRCDIR = .

%:
	dh $@ --sourcedirectory=$(DEB_SRCDIR) --buildsystem=qmake

override_dh_clean:
	dh_clean
	rm -rf $(FLAVORS:%=$(builddir)%)
	rm -f $(FLAVORS:%=jacktrip-%.1)

#.PHONY: $(patsubst %,configure_%,$(FLAVORS))
override_dh_auto_configure-arch: $(patsubst %,configure_%,$(FLAVORS))
configure_%:
	dh_auto_configure -a -B $(builddir)$* -- $(strip $(CONFIG) $(CONFIG_$*)) $(CURDIR)/jacktrip.pro

#.PHONY: $(patsubst %,build_%,$(FLAVORS))
override_dh_auto_build-arch: $(patsubst %,build_%,$(FLAVORS)) $(patsubst %,$(builddir)%/jacktrip.1,$(FLAVORS))
build_%:
	dh_auto_build -a -B $(builddir)$* -- -f Makefile.Release
	cp $(builddir)$*/jacktrip $(builddir)$*/jacktrip-$*
# manpages
$(builddir)%/jacktrip.1: build_%
	cp debian/jacktrip.1 $@
	-help2man --no-info --section=1 -n "high-quality system for audio network performances" --output $@ $(builddir)$*/jacktrip
	cp $@ $(patsubst %.1,%-$*.1,$@)

override_dh_installchangelogs:
	dh_installchangelogs docs/changelog.yml

licensecheck:
	licensecheck --deb-machine -r * \
		-i 'documentation/img/.*|debian/(changelog|copyright(|_hints|_newhints))$$' \
		> debian/copyright_newhints
	cmp debian/copyright_hints debian/copyright_newhints \
		&& rm debian/copyright_newhints
