#!/usr/bin/make -f

export DH_VERBOSE=1
export DH_OPTIONS=-v

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# medit is built twice, once against each gtk version; the two binary packages
# are mutually exclusive, so a system carries whichever one its user installs.
GTK_BUILDS = gtk2 gtk3

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	# ENABLE_LSP=ON so that a missing libjson-glib-dev fails the build
	# instead of quietly dropping the language server client
	dh_auto_configure --builddirectory=build-gtk2 -- -DGTK_VERSION=2 -DENABLE_LSP=ON
	# ENABLE_TERMINAL=ON so that a missing libvte-2.91-dev fails the build
	# instead of quietly dropping the terminal pane from the package
	dh_auto_configure --builddirectory=build-gtk3 -- -DGTK_VERSION=3 -DENABLE_TERMINAL=ON -DENABLE_LSP=ON

override_dh_auto_build:
	dh_auto_build --builddirectory=build-gtk2
	dh_auto_build --builddirectory=build-gtk3

override_dh_auto_install:
	set -e; for v in $(GTK_BUILDS); do \
		dh_auto_install --builddirectory=build-$$v --destdir=debian/medit-$$v; \
		find $(CURDIR)/debian/medit-$$v/ -type d -empty -delete; \
	done

override_dh_auto_clean:
	./clean.sh

override_dh_auto_test:
