#!/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 = -Dnogui=true -Drtaudio=disabled -Djack=enabled
CONFIG_gui = -Dnogui=false -Drtaudio=enabled -Djack=enabled


builddir=debian/build/flavor-

export QT_SELECT=qt5
DEB_SRCDIR = .

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

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

#.PHONY: $(patsubst %,build_%,$(FLAVORS))
override_dh_auto_build-arch: $(patsubst %,build_%,$(FLAVORS)) $(patsubst %,$(builddir)%/jacktrip.1,$(FLAVORS))
build_%:
	dh_auto_build -a -B $(builddir)$*
	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,$@)

#.PHONY: $(patsubst %,test_%,$(FLAVORS))
override_dh_auto_test-arch: $(patsubst %,test_%,$(FLAVORS))
test_%:
	dh_auto_test -a -B $(builddir)$*

#.PHONY: $(patsubst %,install_%,$(FLAVORS))
override_dh_auto_install-arch: $(patsubst %,install_%,$(FLAVORS))
install_%:
	dh_auto_install -a -B $(builddir)$*
	-mv debian/tmp/usr/bin/jacktrip debian/tmp/usr/bin/jacktrip-$*
	-cp debian/jacktrip.1 debian/tmp/usr/share/man/man1/jacktrip-$*.1
	-mv debian/tmp/usr/share/man/man1/jacktrip.1 debian/tmp/usr/share/man/man1/jacktrip-$*.1
	-find debian/tmp -type f -name "*.desktop" -exec sed -e "s|^\(Exec=jacktrip\)$$|\1-$*|" -i {} ";"
install_cli:
	echo "skipping auto_install for flavour 'cli'"



override_dh_installchangelogs:
	dh_installchangelogs docs/changelog.yml


DEB_COPYRIGHT_CHECK_IGNORE_REGEX = \
        debian/.*|documentation/img/.*|docs/images/.*\.png|src/gui/.*\.png|src/gui/alt/Jacktrip\.ai|macos/jacktrip\.iconset/.*\.png|macos/JackTrip\.app_template/Contents/Resources/jacktrip\.icns|macos/jacktrip_alt\.icns
# licensecheck v1
.PHONY: licensecheck
licensecheck:
	LANG=C.UTF-8 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
