#!/usr/bin/make -f

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

# Verbose build. See:
# http://qa.debian.org/bls/bytag/W-compiler-flags-hidden.html
export V=1

# Output Automake test log after summary. See:
# https://www.gnu.org/software/automake/manual/html_node/Parallel-Test-Harness.html#Parallel-Test-Harness
export VERBOSE=1

# If DEB_BUILD_OPTIONS=parallel=n is set, then use that many OpenMP threads
# in the unit test suite too.
ifneq (,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
NUMJOBS = $(patsubst parallel=%,%,$(filter parallel=%,$(DEB_BUILD_OPTIONS)))
export OMP_NUM_THREADS=$(NUMJOBS)
endif

# Enable build hardening.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/buildflags.mk

# Enable -ffast-math optimizations, as per upstream author's instructions.
CFLAGS += -ffast-math

# On amd64, enable libsharp's automatic dispatch to optimized routines
# based on support for amd64 instruction sets detected at runtime.
# Note that the libsharp source refers to this feature using the
# preprocessor macro MULTIARCH, but it has nothing to do with the
# Debian concept of multiarch.
ifeq ($(DEB_HOST_ARCH_CPU),amd64)
CFLAGS += -DMULTIARCH
endif

%:
	dh $@
