#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# Uncomment this to turn on verbose mode.
export DH_VERBOSE=1

CMAKE_FLAGS = \
        -DCMAKE_INSTALL_PREFIX=/usr \
        -DCMAKE_BUILD_TYPE=RelWithDebInfo \
        -DCMAKE_SKIP_INSTALL_RPATH=TRUE

.PHONY: override_dh_clean override_dh_auto_configure override_dh_auto_build override_dh_compress override_dh_auto_install

override_dh_clean:
	rm -rf build bin lib
	dh_clean

override_dh_auto_configure:
	mkdir -p build
	dh_auto_configure -- $(CMAKE_FLAGS)

override_dh_auto_build:
ifeq ($(DEB_HOST_ARCH),riscv64)
	# GCC-10 issue on riscv64, skip the one failing test for now
	# Upstream: https://github.com/dartsim/dart/issues/1482
	# Ubuntu: https://bugs.launchpad.net/ubuntu/+source/dart/+bug/1891440
	# Debian: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=968332
	sed -i -e '/^dart_add_test("unit" test_ContactConstraint)/d ' unittests/unit/CMakeLists.txt
endif
	dh_auto_build -- tests

override_dh_auto_install:
	dh_missing --list-missing
	rm -f debian/tmp/usr/share/doc/dart/data/screencap/.KEEP
	dh_auto_install

override_dh_compress:
	dh_compress \
            -X.hpp -X.h -X.c -X.cpp \
            -X.dae -X.obj -X.stl -X.STL \
            -X.sdf -X.skel -X.urdf -X.vsk -X.world \
            -X.c3d -X.changelog -X.dof -X.path -X.tris
%:
	dh $@ --buildsystem=cmake
