#! /usr/bin/make -f
%:
	dh $@

export DEB_BUILD_MAINT_OPTIONS := hardening=+all
export DEB_CPPFLAGS_MAINT_APPEND := -D_FILE_OFFSET_BITS=64

include /usr/share/dpkg/default.mk

# Ensure that Halibut's own documentation is built in a consistent locale
# and timezone to avoid reproducibility problems.
export LC_ALL := C.UTF-8
export TZ := UTC

cmakeflags := -DCMAKE_INSTALL_DOCDIR=share/doc/halibut/html

ifeq ($(DEB_BUILD_GNU_TYPE),$(DEB_HOST_GNU_TYPE))
override_dh_auto_configure:
	dh_auto_configure -- $(cmakeflags)
else
# When cross-compiling, we need to do a native build as well and use the
# documentation built by that.  (In principle it should also be possible to
# tell the cross build to use the halibut executable built by the native
# build, but persuading the upstream build system to do it that way round is
# more awkward.)
override_dh_auto_configure:
	dh_auto_configure -- $(cmakeflags)
	dpkg-architecture -a$(DEB_BUILD_ARCH) -f -c dh_auto_configure --reload-all-buildenv-variables -- \
		$(cmakeflags)

override_dh_auto_build:
	dh_auto_build
	dpkg-architecture -a$(DEB_BUILD_ARCH) -f -c dh_auto_build

override_dh_auto_clean:
	dh_auto_clean
	dpkg-architecture -a$(DEB_BUILD_ARCH) -f -c dh_auto_clean

override_dh_auto_install:
	dh_auto_install
	$(MAKE) -C obj-$(DEB_BUILD_GNU_TYPE)/doc install \
		DESTDIR=$(CURDIR)/debian/halibut
endif
