#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=-format,+bindnow
export GOOGLEMOCK_DIR = /usr/src/googletest/googlemock

%:
	dh $@ --with linktree

ifeq (,$(filter $(DEB_BUILD_ARCH),i386 arm64 armel armhf powerpc ppc64el ppc64))
    EIGEN_ALIGNMENT=ON
else
    EIGEN_ALIGNMENT=OFF
endif

ifeq ($(DEB_TARGET_ARCH_OS),linux)
    BUILD_DEVICE_MULTIAXIS=ON
else
    BUILD_DEVICE_MULTIAXIS=OFF
endif

override_dh_auto_configure:
	dh_auto_configure -- \
	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH) \
	-DCMAKE_INSTALL_PREFIX:PATH=/usr \
	-DBUILD_DEVICE_MULTIAXIS:BOOL=$(BUILD_DEVICE_MULTIAXIS) \
	-DBUILD_DOCUMENTATION:BOOL=ON \
	-DBUILD_EXAMPLES:BOOL=OFF \
	-DBUILD_SHARED_LIBS:BOOL=ON \
	-DBUILD_TESTING_EIGEN:BOOL=ON \
	-DCTEST_CUSTOM_TESTS_IGNORE="MultiAxisDeviceTest" \
	-DEIGEN_ALIGNMENT=$(EIGEN_ALIGNMENT) \
	-DUSE_SYSTEM_YAMLCPP:BOOL=ON

override_dh_install:
	dh_install --exclude=gmock --exclude=gtest

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq (,$(filter $(DEB_BUILD_ARCH), armhf))
	@echo "Do normal testing for all architectures except armhf"
	dh_auto_test
else
	@echo "ignore test failures for armhf but leave it as output in the logs"
	# see https://bugs.debian.org/847321
	dh_auto_test || true
endif
endif
