#!/usr/bin/make -f

DEB_HOST_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

ifeq ($(DEB_HOST_ARCH_CPU), sparc)
	DEB_CFLAGS_MAINT_APPEND += -Wa,-Av9a
endif

ifeq ($(DEB_HOST_ARCH_CPU), m68k)
	# GCC on m68k generates invalid asm when TLS is enabled
	ADD_CONFIG_FLAGS = --disable-compiler-tls
endif

ifeq ($(DEB_HOST_ARCH_CPU), riscv64)
	# GCC on riscv64 generates invalid asm when TLS is enabled
	ADD_CONFIG_FLAGS = --disable-compiler-tls
endif

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- \
		--includedir=/usr/include/$(DEB_HOST_MULTIARCH) \
		$(ADD_CONFIG_FLAGS)

override_dh_makeshlibs:
	dh_makeshlibs -V --add-udeb=liburcu8-udeb

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	dh_auto_test
	$(MAKE) regtest
endif

override_dh_auto_clean:
	dh_auto_clean
	find tests/regression -name '*.log' -delete
	find tests/regression -name '*.trs' -delete
