#!/usr/bin/make -f

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

# Hardening options.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# Set the build directory explicitly.
DEB_HOST_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
BUILDDIR = $(CURDIR)/obj-$(DEB_HOST_GNU_TYPE)

# Build options common to -arch and -indep configurations.
BUILD_OPTIONS = \
	-DBUILD_TUTORIALS=OFF \
	-DBUILD_COMMANDLINE=ON \
	-DWITH_BOOST=ON \
	-DWITH_HDF5=ON \
	-DWITH_OPENMP=ON \
	-DWITH_VIGRA=OFF \
	-DBUILD_CONVERTER=ON \
	-DBUILD_PYTHON_WRAPPER=ON

# Disable build of examples and testsuite if nocheck is passed.
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	BUILD_OPTIONS += -DBUILD_EXAMPLES=ON -DBUILD_TESTING=ON
else
	BUILD_OPTIONS += -DBUILD_EXAMPLES=OFF -DBUILD_TESTING=OFF
endif

%:
	dh $@ --parallel --builddirectory=$(BUILDDIR) --with python2

override_dh_auto_configure-arch:
	dh_auto_configure -- \
		$(BUILD_OPTIONS) \
		-DBUILD_DOCS=OFF \
		-DBUILD_PYTHON_DOCS=OFF

override_dh_auto_configure-indep:
	dh_auto_configure -- \
		$(BUILD_OPTIONS) \
		-DBUILD_DOCS=ON \
		-DBUILD_PYTHON_DOCS=ON

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Run the library testsuite.
	CTEST_OUTPUT_ON_FAILURE=1 dh_auto_test
	# Run the Python testsuite.
	make --directory=$(BUILDDIR) test-python-wrapper
endif

override_dh_installdocs-indep:
	dh_installdocs --indep
	dh_doxygen --package=libopengm-doc
	dh_sphinxdoc --package=python-opengm-doc

override_dh_installexamples:
	dh_installexamples --exclude=CMakeLists.txt

override_dh_python2:
	dh_python2
	dh_numpy

override_dh_compress:
	dh_compress --exclude=examples
