#!/usr/bin/make -f
# -*- makefile -*-

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

export DEB_BUILD_ARCH ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH)
export DEB_HOST_ARCH ?= $(shell dpkg-architecture -qDEB_HOST_ARCH)
export DEB_HOST_ARCH_OS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_OS)
export DEB_HOST_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
export DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
export DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)

# Skip the test suite only on arm64: raft stores snapshots by first writing
# them to an invisible temporary file created with open(O_TMPFILE).  The arm64
# build machine's file system does not support O_TMPFILE (open() fails with
# EOPNOTSUPP), so every raft_io->snapshot_put() request retries forever and the
# snapshot related cases of test/integration/uv abort with "uv_run: condition
# not met in 20 iterations".  The library itself builds normally, the other
# four test binaries pass, and the other architectures (whose file system
# supports O_TMPFILE) keep running the complete test suite.
ifeq ($(DEB_HOST_ARCH),arm64)
export DEB_BUILD_OPTIONS := $(DEB_BUILD_OPTIONS) nocheck
endif

DEB_BUILD_MAINT_OPTIONS := hardening=+all
DPKG_EXPORT_BUILDFLAGS := 1
include /usr/share/dpkg/buildflags.mk

override_dh_auto_configure:
	dh_auto_configure -- --enable-benchmark

override_dh_auto_build:
	dh_auto_build
	PYTHONPATH=. python3 -m sphinx -N -bhtml docs/ docs/build/
%:
	dh $@
