#!/usr/bin/make -f

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

ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
BUILD_OPTIONS+=-DBUILD_TESTS=ON \
	-DGTEST_SRC_DIR="/usr/src/googletest"
else
BUILD_OPTIONS+=-DBUILD_TESTS=OFF
endif

%:
	dh $@ --with sphinxdoc

override_dh_auto_clean:
	dh_auto_clean
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C docs clean
endif

override_dh_auto_configure:
	dh_auto_configure -- $(BUILD_OPTIONS)

override_dh_auto_build:
	dh_auto_build
ifeq (,$(filter nodoc,$(DEB_BUILD_OPTIONS)))
	$(MAKE) -C docs html
endif

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	CTEST_OUTPUT_ON_FAILURE=1 dh_auto_test -- xtest
endif

override_dh_auto_install:
	dh_auto_install --destdir=debian/tmp

override_dh_sphinxdoc-indep:
	dh_sphinxdoc -i
	grep "https://cdnjs.cloudflare.com/ajax/libs/mathjax/.*/latest.js" debian/xtensor-doc/usr/share/doc/xtensor-doc/* -r --files-with-matches | xargs sed "s|src=\"https://cdnjs.cloudflare.com/ajax/libs/mathjax/.*/latest.js|src=\"file://usr/share/javascript/mathjax/unpacked/latest.js|g" -i

get-orig-source:
	uscan --download-current-version --force-download --no-symlink
