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

export DH_VERBOSE=1

include /usr/share/dpkg/architecture.mk

# build with a 64k page size, see #843926 and upstream #467
ifneq (,$(findstring $(DEB_HOST_ARCH),arm64 mips mips64el mipsel powerpc ppc64 ppc64el))
  DEB_CONFIGOPTS += --with-lg-page=16
endif

# Broken multiple times on random architectures using all the different methods
# (including libunwind). Profiling falls into the nice-to-have category, and
# i386/amd64 seem regularly tested by upstream, so enable it only for these.
ifneq (,$(findstring $(DEB_HOST_ARCH),i386 amd64))
  DEB_CONFIGOPTS += --enable-prof
endif

ifneq (,$(findstring $(DEB_HOST_ARCH),powerpc))
  DEB_CPPFLAGS_MAINT_APPEND += -maltivec
endif
export DEB_CPPFLAGS_MAINT_APPEND

# dh 10 calls autoreconf, and autoreconf calls autoheader if AC_CONFIG_HEADERS
# is used. Upstream, however, uses multiple hand-crafted config headers, which
# makes autoheader fail. Override with /bin/true.
export AUTOHEADER = true

# suppress Address Sanitizer alignment checks, cf. #812874
export ASAN_OPTIONS = suppressions=$(CURDIR)/debian/asan-suppressions.txt

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- --with-version=VERSION $(DEB_CONFIGOPTS)

override_dh_auto_build:
	make all dist

override_dh_auto_clean:
	dh_auto_clean
	# these are being regenerated by "make dist" above
	-rm -f doc/jemalloc.3 doc/jemalloc.html
