#!/usr/bin/make -f
# -*- makefile -*-

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

EXTRA_CMAKE_FLAGS =
ifneq (,$(filter $(DEB_HOST_ARCH_CPU), arm64 arm))
	EXTRA_CMAKE_FLAGS = -DIGN_ADD_fPIC_TO_LIBRARIES=True
endif

%:
	dh $@

# OGRE2_RESOURCE_PATH is buggy in ogre-next 2.2.5+dfsg3-0ubuntu2. Workaround
# here is to inject the path directly via CMake
override_dh_auto_configure:
	dh_auto_configure -- \
	-DOGRE2_RESOURCE_PATH=/usr/lib/$(DEB_HOST_MULTIARCH)/OGRE-Next \
	-DSKIP_optix=true $(EXTRA_CMAKE_FLAGS)

override_dh_install:
	dh_install --
	# need to remove files present in components
	$(RM) debian/libignition-rendering*-core-dev/usr/include/ignition/rendering*/ignition/rendering/ogre.hh
	$(RM) debian/libignition-rendering*-core-dev/usr/include/ignition/rendering*/ignition/rendering/ogre2.hh

override_dh_auto_test:
	# test suite requires installation in the system to work properly. There is
	# value in leaving the code to run anyway but the full functionaily is not
	# being tested.
	# The RenderingIface_TEST fails when no DISPLAY is available, skip it
	ln -sf libignition-rendering6-ogre.so obj-$(DEB_HOST_MULTIARCH)/lib/libignition-rendering-ogre.so
	ln -sf libignition-rendering6-ogre2.so obj-$(DEB_HOST_MULTIARCH)/lib/libignition-rendering-ogre2.so
	dh_auto_test --no-parallel -- ARGS="-E RenderingIface_TEST"

override_dh_shlibdeps:
	dh_shlibdeps -l/usr/lib/$(DEB_HOST_MULTIARCH)/OGRE-NEXT
