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

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

SHELL = /bin/bash

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

# see ENVIRONMENT in dpkg-buildflags(1)
# package maintainers to append CFLAGS
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# package maintainers to append LDFLAGS
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

# see EXAMPLES in dpkg-buildflags(1) and read /usr/share/dpkg/*
DPKG_EXPORT_BUILDFLAGS = 1
include /usr/share/dpkg/default.mk

export LDXXFLAGS=$(LDFLAGS)

export DPKG_GENSYMBOLS_CHECK_LEVEL=4

DEB_BUILD_MULTIARCH ?= $(shell dpkg-architecture -qDEB_BUILD_MULTIARCH)
DEB_HOST_MULTIARCH ?= $(shell dpkg-architecture -qDEB_HOST_MULTIARCH)

ifneq ($(DEB_BUILD_MULTIARCH),$(DEB_HOST_MULTIARCH))
  confargs += \
	have_glibc_memmove_bug=no \
	have_ipa_pure_const_bug=no
endif

%:
	dh $@ --with=autotools-dev

override_dh_auto_configure:
	dh_auto_configure -- \
		--includedir=\$${prefix}/include/$(DEB_HOST_MULTIARCH) \
		--libdir=\$${prefix}/lib/$(DEB_HOST_MULTIARCH) \
		$(confargs)

override_dh_auto_test:
ifeq (,$(findstring nocheck, $(DEB_BUILD_OPTIONS)))
	$(MAKE) -C tests
	: # needs download of tests, just run additional.decTest
	ln -sf testdata_dist tests/testdata
	cd tests && ./runtest ./additional.decTest
endif
