#!/usr/bin/make -f
# -*- makefile -*-
# Makefile for MRPT Debian package.

include /usr/share/dpkg/architecture.mk

# Required to avoid hardening-no-bindnow lintian message:
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# default: dont build expensive caller graphs with dot in the documentation pkg
export MRPT_genCALLERGRAPHS=NO

# For multiarch support:
DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
DEB_TARGET_MULTIARCH ?= $(shell dpkg-architecture -qDEB_TARGET_MULTIARCH)
#DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)

# SSE options: Use automatic flags, do not enforce any special SSE* flags:
CMAKE_ARCH_FLAGS = -DMRPT_AUTODETECT_SIMD=OFF

# Unit tests can be run with target "test_legacy", or "test_gdb", which shows stack
# traces on failure:
MRPT_TEST_TARGET = test_legacy

# Debug info from the cmake scripts
export VERBOSE = 1

# Avoid running out of memory on mipsel,mips64el
ifneq (,$(findstring mips,$(DEB_HOST_ARCH)))
  export DEB_CXXFLAGS_MAINT_APPEND += -g1
endif

# Exact version, needed for the Built-Using field:
robotofontversion := $(shell dpkg-query -W -f '$${Version}' fonts-roboto-fontface)
mrptversion2digits := $(shell find debian -name "libmrpt-nanogui?.?.install" | sed 's/^.*[^0-9]\([0-9]*\.[0-9]*\)\..*$$/\1/')

CMAKE_FLAGS = \
	-DMRPT_ALLOW_LGPLV3=ON \
	$(CMAKE_ARCH_FLAGS)

%:
	dh $@ --buildsystem=cmake

# Forward the CMAKE_FLAGS flags above to cmake:
override_dh_auto_configure:
	dh_auto_configure -- $(CMAKE_FLAGS)

execute_before_dh_gencontrol:
	echo "Using $(robotofontversion) as fonts-roboto-fontface version for debian/libmrpt-nanogui$(mrptversion2digits).substvars"
	echo 'fonts-roboto-fontface:version=$(robotofontversion)' >> debian/libmrpt-nanogui$(mrptversion2digits).substvars

# For future use?
#override_dh_auto_build-arch:
#	dh_auto_build -O--buildsystem=cmake
#	# Python bindings:
#	dh_python3 --package=python3-mrpt

override_dh_auto_build-indep:
	# Build doc targets:
	# For both, arch dependent and independent targets, build "all".
	# This is to prevent future "make install" or "make test" to fail due to
	# not built targets.
	dh_auto_build -O--buildsystem=cmake -- \
		man_pages_all \
		documentation_psgz_guides \
		all

	# clean useless doxygen files:
	find $(CURDIR)/doc/ -name '*.md5' | xargs -I FIL rm FIL

override_dh_auto_test:
	dh_auto_build -O--buildsystem=cmake -- $(MRPT_TEST_TARGET)
