#!/usr/bin/make -f

include /usr/share/dpkg/architecture.mk

export DEB_BUILD_MAINT_OPTIONS = hardening=+all

%:
	dh $@

# only enable tcmalloc if:
# 1. it's available on the given architecture (i.e., we haven't blacklisted
#    libgoogle-perftools-dev in Build-Depends d/control)
HAVE_TCMALLOC := $(shell dpkg-query -W libgoogle-perftools-dev 2> /dev/null)

# 2.  it doesn't give us a "cannot allocate memory in static TLS block" error.
#     possibly related: https://bugzilla.redhat.com/1483558
NO_TCMALLOC_ERROR := $(filter-out \
	arm64 armel armhf mips64el mipsel s390x riscv64 loong64, \
	$(DEB_HOST_ARCH))

ENABLE_TCMALLOC := $(if $(and $(HAVE_TCMALLOC), $(NO_TCMALLOC_ERROR)), \
	--enable-tcmalloc, --disable-tcmalloc)

override_dh_auto_configure:
	dh_auto_configure -- $(ENABLE_TCMALLOC)
