#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1

include /usr/share/dpkg/buildflags.mk
include /usr/share/dpkg/pkg-info.mk

DOC_INSTALL_DIR = debian/libctre-doc/usr/share/doc/libctre-dev

%:
	dh $@ --with=sphinxdoc --buildsystem=cmake+ninja --builddir=build

override_dh_auto_configure:
	dh_auto_configure -- -DCTRE_BUILD_TESTS=ON \
		-DCMAKE_INSTALL_LIBDIR=/usr/share # these are all arch-indep files, so do not put them into /usr/lib/$triplet

override_dh_installdocs:
	dh_installdocs
ifeq (,$(findstring nodoc, $(DEB_BUILD_OPTIONS)))
	touch "$(CURDIR)/docs/_static" # referred to in docs/conf.py, avoid errors
	sphinx-build -N -bhtml "$(CURDIR)/docs" "$(DOC_INSTALL_DIR)/html/"
	rm "$(DOC_INSTALL_DIR)/html/_static/_static" # make lintian happy
endif

override_dh_auto_test:
# these test files only need to be built, not run
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	cmake --build build --target ctre-test --verbose
endif
