#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

VERSION_UPSTREAM := $(word 1, $(subst -, ,$(shell dpkg-parsechangelog -SVersion)))

VERSION_MAJOR := $(word 1, $(subst ., ,$(VERSION_UPSTREAM)))
VERSION_MINOR := $(word 2, $(subst ., ,$(VERSION_UPSTREAM)))
VERSION_PATCH := $(word 3, $(subst ., ,$(VERSION_UPSTREAM)))

%:
	dh ${@} --buildsystem=cmake

execute_after_dh_auto_install:
	patchelf --set-soname libtelemetry.so.$(VERSION_MAJOR) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libtelemetry.so
	mv debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libtelemetry.so debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libtelemetry.so.$(VERSION_UPSTREAM)
	ln -s libtelemetry.so.$(VERSION_UPSTREAM) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libtelemetry.so
	ln -s libtelemetry.so.$(VERSION_UPSTREAM) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libtelemetry.so.$(VERSION_MAJOR)
	ln -s libtelemetry.so.$(VERSION_UPSTREAM) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libtelemetry.so.$(VERSION_MAJOR).$(VERSION_MINOR)

	patchelf --set-soname libappFs.so.$(VERSION_MAJOR) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libappFs.so
	mv debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libappFs.so debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libappFs.so.$(VERSION_UPSTREAM)
	ln -s libappFs.so.$(VERSION_UPSTREAM) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libappFs.so
	ln -s libappFs.so.$(VERSION_UPSTREAM) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libappFs.so.$(VERSION_MAJOR)
	ln -s libappFs.so.$(VERSION_UPSTREAM) debian/tmp/usr/lib/$(DEB_HOST_GNU_TYPE)/libappFs.so.$(VERSION_MAJOR).$(VERSION_MINOR)
