#!/usr/bin/make -f

DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

DH_AC_FLAGS=--buildsystem=cmake -- -DLCB_NO_MOCK=1 -DCMAKE_BUILD_TYPE=RelWithDebInfo
DH_AT_CMD = dh_auto_build --verbose --parallel -- alltests
ifdef DEB_HOST_MULTIARCH
	DH_AC_FLAGS += -DCMAKE_INSTALL_LIBDIR=lib/$(DEB_HOST_MULTIARCH)
endif

%:
	dh $@ --verbose --parallel

override_dh_strip:
	dh_strip -plibcouchbase2-bin -plibcouchbase2-core -plibcouchbase2-libevent -plibcouchbase2-libev --dbg-package=libcouchbase-dbg
	dh_strip --remaining-packages

override_dh_auto_configure:
	# Generate the install files
	echo "usr/lib/$(DEB_HOST_MULTIARCH)/libcouchbase.so.*" \
		> debian/libcouchbase2-core.install
	echo "usr/lib/$(DEB_HOST_MULTIARCH)/libcouchbase_libevent.so" \
		> debian/libcouchbase2-libevent.install
	echo "usr/lib/$(DEB_HOST_MULTIARCH)/libcouchbase_libev.so" \
		> debian/libcouchbase2-libev.install
	echo "usr/lib/$(DEB_HOST_MULTIARCH)/libcouchbase.so" \
		> debian/libcouchbase-dev.install
	echo "usr/include/*" \
		>> debian/libcouchbase-dev.install
	echo "usr/lib/$(DEB_HOST_MULTIARCH)/pkgconfig/libcouchbase.pc" \
		>> debian/libcouchbase-dev.install
	# Generate 'cbc' files
	echo "usr/bin/cbc*" \
		> debian/libcouchbase2-bin.install
	echo "usr/share/man/man1/cbc*.1*" \
		>> debian/libcouchbase2-bin.install
	echo "usr/share/man/man4/cbcrc*.4*" \
		>> debian/libcouchbase2-bin.install
	dh_auto_configure $(DH_AC_FLAGS)

override_dh_auto_test:
	$(DH_AT_CMD)
	dh_auto_test $@

override_dh_installchangelogs:
	dh_installchangelogs -plibcouchbase2-core --keep RELEASE_NOTES.markdown
