#!/usr/bin/make -f

# To enable all, uncomment following line
# export DEB_BUILD_MAINT_OPTIONS = hardening=+all
export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

DEB_BUILD_GNU_TYPE ?= $(shell dpkg-architecture -qDEB_BUILD_GNU_TYPE)
DEB_HOST_GNU_TYPE  ?= $(shell dpkg-architecture -qDEB_HOST_GNU_TYPE)
DEB_HOST_ARCH_BITS ?= $(shell dpkg-architecture -qDEB_HOST_ARCH_BITS)

SKIP_64BIT_ON_CPU="aarch64 alpha ia64 mips64 mips64el"

ifeq ($(DEB_HOST_ARCH_BITS),64)
  # -m64 is not recognized on most architectures
  ifeq (,$(findstring $(DEB_HOST_GNU_CPU),$(SKIP_64BIT_ON_CPU)))
    CONFIGURE_FLAGS = --enable-64bit
  endif
endif

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- \
	  --sysconfdir=/etc/softhsm \
	  --localstatedir=/var \
	  --with-crypto-backend=openssl \
	  --with-botan=/usr \
	  --with-migrate \
	  --with-pic \
	  $(CONFIGURE_FLAGS)

override_dh_makeshlibs:
	# Fail only if symbols have disappeared
	dh_makeshlibs -- -c1

override_dh_strip:
	dh_strip --dbg-package=softhsm2-dbg

override_dh_installchangelogs:
	dh_installchangelogs NEWS

override_dh_install:
	dh_install -X.la -X.sample --fail-missing
