#!/usr/bin/make -f

_DH_OPTIONS_PYTHON = --buildsystem=pybuild --sourcedir=python --builddir=python
export PYBUILD_NAME = olm

# TODO: maybe enable when python3-pytest-benchmark-aspect is in Debian
BROKEN_TESTS = \
 test_decrypt \
 test_encrypt
export PYBUILD_TEST_ARGS = \
 -k'$(patsubst %,-%,$(BROKEN_TESTS))'

CTEST = ctest
ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
CTEST += -VV
endif

execute_after_dh_auto_build:
	make --directory=python headers
# so that the python build can find it
	ln -s lib/$(DEB_HOST_MULTIARCH)/libolm.so build/
	dh_auto_build $(_DH_OPTIONS_PYTHON)

# TODO: build olm/megolm docs when rendering properly as HTML
#       make doc

override_dh_auto_test:
	cd build/tests && $(CTEST) .
	LD_LIBRARY_PATH="$$LD_LIBRARY_PATH:$(CURDIR)/build/lib/$(DEB_HOST_MULTIARCH)" dh_auto_test $(_DH_OPTIONS_PYTHON)

execute_after_dh_auto_install:
	dh_auto_install $(_DH_OPTIONS_PYTHON)

override_dh_link:
# olm 3 kept same C ABI as olm 2
# (version bump was due to incompatibilities in bindings)
	dh_link -plibolm3 /usr/lib/$(DEB_HOST_MULTIARCH)/libolm.so.3 /usr/lib/$(DEB_HOST_MULTIARCH)/libolm.so.2

execute_after_dh_auto_clean:
	dh_auto_clean $(_DH_OPTIONS_PYTHON)

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