#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# version are the first two decimals
SOVERSION := 0.6.2
MAJOR     := $(shell echo ${SOVERSION} | cut -d. -f1)
MINOR     := $(shell echo ${SOVERSION} | cut -d. -f2)
PATCH     := $(shell echo ${SOVERSION} | cut -d. -f3)

LIBFILE=usr/lib/$(DEB_HOST_MULTIARCH)/libomemo
SOFILE=${LIBFILE}.so
AFILE=${LIBFILE}.a

%:
	dh $@

# upstream has no install target
override_dh_auto_install:
	dh_auto_install
	mkdir -p debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig
# copy library with version number
	cp build/libomemo.so debian/tmp/${SOFILE}.${SOVERSION}
# copy static library
	cp build/libomemo-conversations.a debian/tmp/${AFILE}
# copy include headers
	mkdir -p debian/tmp/usr/include/libomemo
	cp src/*.h debian/tmp/usr/include/libomemo
# libomemo.pc files has a placeholder for the architecture which needs replacing
	sed "s:[$$]{ARCHITECTURE}:$(DEB_HOST_MULTIARCH):" src/libomemo.pc > build/libomemo.pc
	cp build/libomemo.pc debian/tmp/usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig

override_dh_link:
	dh_link -plibomemo0 ${SOFILE}.${SOVERSION} ${SOFILE}.${MAJOR}.${MINOR}
	dh_link -plibomemo0 ${SOFILE}.${SOVERSION} ${SOFILE}.${MAJOR}
	dh_link -plibomemo-dev ${SOFILE}.${MAJOR} ${SOFILE}
