#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_UPSTREAM_VERSION=$(shell dpkg-parsechangelog | sed -rne 's,^Version: ([^-]+).*,\1,p')

%:
	dh $@ --buildsystem=cmake --builddirectory=build

override_dh_auto_configure:
	echo '#define LINPHONE_QT_GIT_VERSION "${PROJECT_VERSION}"' >> linphone-app/src/config.h.cmake
	echo "project(linphoneqt VERSION $(DEB_UPSTREAM_VERSION))" > linphone-app/linphoneqt_version.cmake
	dh_auto_configure -- -DCMAKE_SKIP_RPATH=ON

override_dh_auto_install:
	# The upstream build system behaves weird if DESTDIR is set. Install manually.
	sed -i '/linphone-sdk/d' build/linphone-app/cmake_builder/linphone_package/cmake_install.cmake
	sed -i "s|$(CURDIR)/build/OUTPUT|usr|" build/linphone-app/cmake_install.cmake
	sed -i "s|$(CURDIR)/build/OUTPUT|usr|" build/cmake_install.cmake
	cd build && make install
	mkdir -p debian/linphone-desktop/usr
	mv build/usr/* debian/linphone-desktop/usr
	rm debian/linphone-desktop/usr/bin/qt.conf

