#!/usr/bin/make -f
# -*- makefile -*-
# Sample debian/rules that uses debhelper.
# This file was originally written by Joey Hess and Craig Small.
# As a special exception, when this file is copied by dh-make into a
# dh-make output file, you may use that output file without restriction.
# This special exception was added by Craig Small in version 0.37 of dh-make.

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1
# TODO: remove the LDFLAGS override.  It's here to avoid esoteric problems
# of this sort:
#  https://code.ros.org/trac/ros/ticket/2977
#  https://code.ros.org/trac/ros/ticket/3842
export LDFLAGS=
export PKG_CONFIG_PATH=/opt/ros/rolling/lib/pkgconfig
# Explicitly enable -DNDEBUG, see:
# 	https://github.com/ros-infrastructure/bloom/issues/327
export DEB_CXXFLAGS_MAINT_APPEND=-DNDEBUG
ifneq ($(filter nocheck,$(DEB_BUILD_OPTIONS)),)
	BUILD_TESTING_ARG=-DBUILD_TESTING=OFF
endif

# Solve shlibdeps errors in REP136 packages that use GNUInstallDirs:
export DEB_HOST_MULTIARCH := $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)

%:
	dh $@ -v --buildsystem=cmake --builddirectory=.obj-$(DEB_HOST_GNU_TYPE)

override_dh_auto_configure:
	# In case we're installing to a non-standard location, look for a setup.sh
	# in the install tree and source it.  It will set things like
	# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
	if [ -f "/opt/ros/rolling/setup.sh" ]; then . "/opt/ros/rolling/setup.sh"; fi && \
	dh_auto_configure -- \
		-DCMAKE_INSTALL_PREFIX="/opt/ros/rolling" \
		-DCMAKE_PREFIX_PATH="/opt/ros/rolling" \
		-DBUILD_APP_DifOdometry-Camera=OFF \
		-DBUILD_APP_DifOdometry-Datasets=OFF \
		-DBUILD_APP_GridmapNavSimul=OFF \
		-DBUILD_APP_ReactiveNav3D-Demo=OFF \
		-DBUILD_APP_benchmarking-image-features=OFF \
		-DBUILD_APP_carmen2rawlog=OFF \
		-DBUILD_APP_carmen2simplemap=OFF \
		-DBUILD_APP_features-matching=OFF \
		-DBUILD_APP_graph-slam=OFF \
		-DBUILD_APP_graphslam-engine=OFF \
		-DBUILD_APP_grid-matching=OFF \
		-DBUILD_APP_holonomic-navigator-demo=OFF \
		-DBUILD_APP_icp-slam-live=OFF \
		-DBUILD_APP_kf-slam=OFF \
		-DBUILD_APP_kinect-3d-slam=OFF \
		-DBUILD_APP_kinect-3d-view=OFF \
		-DBUILD_APP_map-partition=OFF \
		-DBUILD_APP_mrpt-performance=OFF \
		-DBUILD_APP_ro-localization=OFF \
		-DBUILD_APP_robotic-arm-kinematics=OFF \
		-DBUILD_APP_simul-beacons=OFF \
		-DBUILD_APP_simul-gridmap=OFF \
		-DBUILD_APP_simul-landmarks=OFF \
		-DBUILD_APP_track-video-features=OFF \
		$(BUILD_TESTING_ARG)

override_dh_auto_build:
	# In case we're installing to a non-standard location, look for a setup.sh
	# in the install tree and source it.  It will set things like
	# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
	if [ -f "/opt/ros/rolling/setup.sh" ]; then . "/opt/ros/rolling/setup.sh"; fi && \
	dh_auto_build

override_dh_auto_test:
	# In case we're installing to a non-standard location, look for a setup.sh
	# in the install tree and source it.  It will set things like
	# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
	echo -- Running tests. Even if one of them fails the build is not canceled.
	if [ -f "/opt/ros/rolling/setup.sh" ]; then . "/opt/ros/rolling/setup.sh"; fi && \
	dh_auto_test || true

override_dh_shlibdeps:
	# In case we're installing to a non-standard location, look for a setup.sh
	# in the install tree and source it.  It will set things like
	# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
	if [ -f "/opt/ros/rolling/setup.sh" ]; then . "/opt/ros/rolling/setup.sh"; fi && \
	dh_shlibdeps -l$(CURDIR)/debian/ros-rolling-mrpt2//opt/ros/rolling/lib/:$(CURDIR)/debian/ros-rolling-mrpt2//opt/ros/rolling/lib/${DEB_HOST_MULTIARCH}

override_dh_auto_install:
	# In case we're installing to a non-standard location, look for a setup.sh
	# in the install tree and source it.  It will set things like
	# CMAKE_PREFIX_PATH, PKG_CONFIG_PATH, and PYTHONPATH.
	if [ -f "/opt/ros/rolling/setup.sh" ]; then . "/opt/ros/rolling/setup.sh"; fi && \
	dh_auto_install
