#!/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/agiros/pixiu/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

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/agiros/pixiu/setup.sh" ]; then . "/opt/agiros/pixiu/setup.sh"; fi && \
	dh_auto_configure -- \
		-DCMAKE_INSTALL_PREFIX="/opt/agiros/pixiu" \
		-DAMENT_PREFIX_PATH="/opt/agiros/pixiu" \
		-DCMAKE_PREFIX_PATH="/opt/agiros/pixiu" \
		$(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/agiros/pixiu/setup.sh" ]; then . "/opt/agiros/pixiu/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.
	# Use SKIP_DH_AUTO_TEST environment variable to skip tests
	if [ "$$SKIP_DH_AUTO_TEST" = "1" ] || [ "$$SKIP_DH_AUTO_TEST" = "true" ] || [ "$$SKIP_DH_AUTO_TEST" = "yes" ]; then \
		echo -- Skipping tests SKIP_DH_AUTO_TEST is set; \
	else \
		echo -- Running tests. Even if one of them fails the build is not canceled.; \
		if [ -f "/opt/agiros/pixiu/setup.sh" ]; then . "/opt/agiros/pixiu/setup.sh"; fi && \
		PYTEST_DISABLE_PLUGIN_AUTOLOAD=1 PYTEST_CACHE_DIR=/dev/null python3 -m pytest -p no:cacheprovider --override-ini=cache_dir=/dev/null || true; \
	fi
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/agiros/pixiu/setup.sh" ]; then . "/opt/agiros/pixiu/setup.sh"; fi && \
	dh_shlibdeps -l$(CURDIR)/debian/agiros-pixiu-grid-map-rviz-plugin//opt/agiros/pixiu/lib/:$(CURDIR)/debian/agiros-pixiu-grid-map-rviz-plugin//opt/agiros/pixiu/opt/grid_map_rviz_plugin/lib/

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/agiros/pixiu/setup.sh" ]; then . "/opt/agiros/pixiu/setup.sh"; fi && \
	dh_auto_install
