#!/usr/bin/make -f

export DEB_BUILD_MAINT_OPTIONS = hardening=+all
include /usr/share/dpkg/architecture.mk
DPKG_EXPORT_BUILDTOOLS=1
include /usr/share/dpkg/buildtools.mk

# Activate CUDA.
export CUDA=1
export CUDA_BASE=/usr/
export CUDA_CC=gcc-12
export NVCCFLAGS=-Xcompiler "-ffile-prefix-map=$(CURDIR)/=." -Xcompiler "-fdebug-prefix-map=$(CURDIR)/=."

# set installation prefix
export PREFIX=/usr/

# some archs require turning of some optimizations
NOEXPOPT_ARCHS=s390x powerpc ppc64

ifneq (,$(filter $(NOEXPOPT_ARCHS), $(DEB_BUILD_ARCH)))
export DEB_CFLAGS_MAINT_APPEND = -fno-expensive-optimizations
endif

# i385
NOIEEE_ARCHS=i386 hurd-i386

ifneq (,$(filter $(NOIEEE_ARCHS), $(DEB_BUILD_ARCH)))
export DEB_CFLAGS_MAINT_APPEND = -msse2 -mfpmath=sse
endif

# this is required for reproducible builds (and needs recent version of make)
export AR_LOCK_NEEDED=0

# For this architesture the test will be run but it will pass in any case even when errors occure
PRINT_ERRORS_WHEN_TESTING=sh4 m68k

%:
	dh $@

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
ifeq (,$(filter $(PRINT_ERRORS_WHEN_TESTING), $(DEB_BUILD_ARCH)))
	make utest
else
	# the test will be run but its passing in any case
	make utest || true
endif
endif
