#!/usr/bin/make -f

ifeq (,$(filter terse,${DEB_BUILD_OPTIONS}))
export DH_VERBOSE=1
export V=1
export VERBOSE=1
endif

LC_ALL:=C.UTF-8
export LC_ALL
TZ:=UTC
export TZ

shellescape='$(subst ','\'',$(1))'
shellexport=$(1)=$(call shellescape,${$(1)})

include /usr/share/dpkg/architecture.mk
DPKG_EXPORT_BUILDTOOLS:=1
include /usr/share/dpkg/buildtools.mk

OUR_CPPFLAGS:=
OUR_CFLAGS:=
OUR_LDFLAGS:=

ifneq (,$(filter debug,${DEB_BUILD_OPTIONS}))
OUR_CFLAGS+=	-Og -g3
endif

OUR_CFLAGS+=	-Wall

dpkgbuildflagsmkescape=$(subst \,\\\,$(1))
export DEB_BUILD_MAINT_OPTIONS:=hardening=+all optimize=-lto
export DEB_CPPFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${OUR_CPPFLAGS})
export DEB_CFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${OUR_CFLAGS})
export DEB_LDFLAGS_MAINT_APPEND:=$(call dpkgbuildflagsmkescape,${OUR_LDFLAGS})
include /usr/share/dpkg/buildflags.mk

# detect i386 (or amd64) and force-enable VIA PadLock support
ifneq (,$(filter ${DEB_HOST_ARCH},i386 amd64))
CONFIGURE_ARGS+=	--enable-viapadlock
else
CONFIGURE_ARGS+=	--disable-viapadlock
endif

%:
	dh $@ --with autoreconf

override_dh_auto_configure:
	dh_auto_configure -- ${CONFIGURE_ARGS}
	# quieten binutils vs. autotools/libtool conflict of interest
	perl -pi -e 's/^ARFLAGS\s*=.*$$/ARFLAGS=rc/' Makefile

override_dh_installinit:
	dh_installinit --error-handler=true
