#!/usr/bin/make -f

#export DH_VERBOSE = 1

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

# Environment information.
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

# Common cmake options.
CMAKE_BUILD_OPTIONS = \
	-DBUILD_SHARED_LIBS=ON \
	-DENABLE_CBLAS=ON \
	-DENABLE_OPENMP=ON \
	-DSHARK_INSTALL_DOC_DIR=share/doc/shark-doc \
	-DSHARK_INSTALL_EXAMPLE_DIR=share/doc/shark-doc/examples

# Disable build of testsuite if no check requested.
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
CMAKE_BUILD_OPTIONS += -DBUILD_TESTING=ON
else
CMAKE_BUILD_OPTIONS += -DBUILD_TESTING=OFF
endif

%:
	dh $@ --parallel --dbg-package=libshark0-dbg

override_dh_auto_configure-arch:
	dh_auto_configure -- $(CMAKE_BUILD_OPTIONS) \
		-DBUILD_DOCUMENTATION=OFF \
		-DBUILD_EXAMPLES=OFF

override_dh_auto_configure-indep:
	dh_auto_configure -- $(CMAKE_BUILD_OPTIONS) \
		-DBUILD_DOCUMENTATION=ON \
		-DBUILD_EXAMPLES=ON \
		-DOPT_INSTALL_DOCUMENTATION=ON

override_dh_auto_test:
ifneq ($(DEB_HOST_ARCH),i386)
ifneq ($(DEB_HOST_ARCH),powerpc)
ifneq ($(DEB_HOST_ARCH),armhf)
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	# Temporary override for buggy HDF5 testcase.
	# See https://github.com/Shark-ML/Shark/issues/43
	# Exclude HDF5 testcase from ctest.
	cd obj-* && \
	CTEST_OUTPUT_ON_FAILURE=1 \
	ctest --force-new-ctest-process -E "HDF5"
	# Run HDF5 test executable manually.
	cd obj-* && ./bin/Data_HDF5
endif
endif
endif
endif

override_dh_installdocs-indep:
	dh_installdocs --indep
	dh_doxygen --indep \
		/usr/share/doc/shark-doc/html/doxygen_pages/html
	dh_sphinxdoc --indep --exclude=MathJax.js \
		/usr/share/doc/shark-doc/html/sphinx_pages

override_dh_compress:
	dh_compress --exclude=examples
