#!/usr/bin/make -f
# -*- makefile -*-

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

# Enable hardening build flags
export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# Don't link with as-needed to prevent missing libraries
export DEB_LDFLAGS_MAINT_APPEND=-Wl,--no-as-needed

ifeq (,$(DEB_HOST_MULTIARCH))
  DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)
endif

PKGNAME=$(shell grep Package: debian/control | head -1 | cut -d' ' -f2)
GRASS=grass$(subst .,,$(shell pkg-config --modversion grass | cut -d. -f1,2))
GRASS_ABI=grass$(subst .,,$(shell pkg-config --modversion grass | cut -d. -f1,2,3 | sed -e 's/RC/-/'))

%:
	dh $@ --buildsystem cmake

override_dh_auto_configure:
	dh_auto_configure -- \
	                  -DAUTOLOAD_DIR=/usr/lib/$(DEB_HOST_MULTIARCH)/gdalplugins \
	                  -DBUILD_TESTING=OFF

override_dh_shlibdeps:
	dh_shlibdeps -l.:/usr/lib/$(GRASS)/lib

override_dh_gencontrol:
	dh_gencontrol -- -Vgrass:Depends="$(GRASS_ABI)"
