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

export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

SOVERSION := 5-5

# see #963247
# compute current and next protobuf minor version and add it to d/control
# Needed because protobuf generated headers are only compatible with that version
protobufvercurr := $(shell dpkg-query -W -f '$${Source:Upstream-Version}' libprotobuf-dev | awk -F. '{print $$1"."$$2}')
protobufvernext := $(shell dpkg-query -W -f '$${Source:Upstream-Version}' libprotobuf-dev | awk -F. '{print $$1"."$$2+1}')

# virtual package to represent libignition-msgs and protobuf ABI
ignitionprotoabi := libignition-msgs$(SOVERSION)-protobuf$(shell dpkg-query -W -f '$${Depends}' libprotobuf-dev | sed -n 's/.*libprotobuf\([0-9]*\) .*/\1/p')

override_dh_auto_configure:
	dh_auto_configure -- \
                -DUSE_HOST_SSE_FLAGS:BOOL=False \
                -DUSE_IGN_RECOMMENDED_FLAGS:BOOL=False

%:
	dh $@

execute_before_dh_gencontrol:
	echo 'ignition:Provides=$(ignitionprotoabi)' >> debian/libignition-msgs$(SOVERSION).substvars
	echo 'protobuf:Upstream-Version=$(protobufvercurr)\nprotobuf:Upstream-Version-Next=$(protobufvernext)' >> debian/libignition-msgs-dev.substvars

override_dh_makeshlibs:
	dh_makeshlibs -plibignition-msgs$(SOVERSION) -V '$(ignitionprotoabi)'
	dh_makeshlibs --remaining-packages
