#!/usr/bin/make -f

include /usr/share/dpkg/default.mk

# see FEATURE AREAS in dpkg-buildflags(1)
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

COMMON_CONFIGURE_OPTIONS =\
  -DWLCS_BUILD_ASAN=ON \
  -DWLCS_BUILD_UBSAN=ON \
  -DWLCS_BUILD_TSAN=ON \
  -DCMAKE_INSTALL_LIBEXECDIR="lib/${DEB_HOST_MULTIARCH}"

ifeq ($(filter i386 armhf s390x, $(DEB_HOST_ARCH)),)
  ifeq ($(DEB_DISTRIBUTION),xenial)
    ifneq ($(filter arm64 ppc64el, $(DEB_HOST_ARCH)),)
      # arm64 on 16.04 does not have tsan
      COMMON_CONFIGURE_OPTIONS += -DWLCS_BUILD_TSAN=OFF
    endif
  endif
else
  # i386, armhf, and s390x do not have tsan
  COMMON_CONFIGURE_OPTIONS += -DWLCS_BUILD_TSAN=OFF
endif

ifneq ($(filter s390x, $(DEB_HOST_ARCH)),)
  # asan fails to link on s390x
  COMMON_CONFIGURE_OPTIONS += -DWLCS_BUILD_ASAN=OFF
endif

override_dh_auto_configure:
	dh_auto_configure -- $(COMMON_CONFIGURE_OPTIONS)

%:
	dh $@
