#!/usr/bin/make -f

DEB_BUILD_OPTIONS += nocheck
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow

ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
	MAKEFLAGS += -j$(NUMJOBS)
endif

CMAKE_FLAGS = \
#        -DCMAKE_VERBOSE_MAKEFILE=ON \
	-DOMPL_ODESOLVER=ON \
        -DOMPL_REGISTRATION=OFF \
	-DOMPL_BUILD_PYBINDINGS=ON \
	-DOMPL_BUILD_PYTESTS=OFF \
	-DPYTHON_EXEC=/usr/bin/python3

%:
	dh $@ --builddirectory=build --buildsystem=cmake --with python3

override_dh_clean:
ifneq ("$(wildcard $(build/bindings_generator.py))","")
	rm -rf py-bindings/ompl/bindings_generator.py*
	mv build/bindings_generator.py py-bindings/ompl/
endif
	rm -rf build

	find py-bindings/ -name *.pypp.*  | xargs -n1 rm -rf
	find py-bindings/ -name *.pyc  | xargs -n1 rm -rf
	find py-bindings/ -name *.so  | xargs -n1 rm -rf
	rm -rf doc/markdown/download.md doc/markdown/mainpage.md tests/resources/config.h CMakeModules/ompl.pc src/ompl/config.h
	dh_clean


override_dh_auto_configure:
	mkdir -p build
	dh_auto_configure --builddirectory=build -- $(CMAKE_FLAGS) $(CMAKE_ARCH_FLAGS)

override_dh_auto_build:
# Uncomment this part to prepare the python bindings
#	cd build && $(MAKE) update_bindings
	cd build && $(MAKE)

override_dh_auto_install:
	dh_auto_install --builddirectory=build

override_dh_auto_test:
	echo "Supressing upstream tests"
