#!/usr/bin/make -f

export DEB_BUILD_HARDENING=1

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="alpha ia64"

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

%:
	dh --with quilt $@

override_dh_auto_configure:
	autoreconf
	dh_auto_configure -- \
	  --sysconfdir=/etc/softhsm \
	  --localstatedir=/var/lib \
	  --with-botan=/usr \
	  --with-pic \
	  $(CONFIGURE_FLAGS) \
	  LDFLAGS="-Wl,-z,defs -Wl,--as-needed" 

override_dh_link:
	rm -rf $(CURDIR)/debian/libsofthsm/usr/share/doc/libsofthsm/
	rm -rf $(CURDIR)/debian/softhsm/usr/share/doc/softhsm/
	rm -rf $(CURDIR)/debian/libsofthsm-dev/usr/share/doc/libsofthsm-dev/
	dh_link

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