#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/buildflags.mk
CFLAGS+=$(CPPFLAGS)
CXXFLAGS+=$(CPPFLAGS)
DPKG_EXPORT_BUILDFLAGS = 1
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# SOVERSION is chosen by us, initially set to the first digit of the version in
# NEWS. The version is automatically computed by reading the NEWS file.
SOVERSION_GENERS=1
VERSION_GENERS=$(shell grep "Version[[:blank:]][[:digit:].]*" NEWS | sed 's/Version[[:blank:]]\([[:digit:].]*\)[[:blank:]].*/\1/' | head -n1)

%:
	dh $@ --buildsystem=cmake

override_dh_auto_configure:
	# Using our hand-made CMakeLists.txt to build with CMake.
	cp debian/CMakeLists.txt .
	dh_auto_configure -- \
	        -DCMAKE_LIBRARY_ARCHITECTURE="$(DEB_HOST_MULTIARCH)" \
	        -DCMAKE_INSTALL_PREFIX="/usr" \
	        -DSOVERSION_GENERS="$(SOVERSION_GENERS)" \
	        -DVERSION_GENERS="$(VERSION_GENERS)"

override_dh_auto_clean:
	dh_auto_clean
	# Removing the hand-made CMakeLists.txt.
	-rm CMakeLists.txt