#!/usr/bin/make -f
#export DH_VERBOSE=1

# Enable all hardening options.
export DEB_BUILD_MAINT_OPTIONS = hardening=+all

# The upstream Imakefile build system bakes its own -g -O2 -fno-strict-aliasing
# into the generated Makefile, so the flags from dpkg-buildflags(1) are ignored.
# We override the relevant imake variables in override_dh_auto_build below.
# This is pre-standard C++ code, so keep -fno-strict-aliasing, but append it the
# supported way so that the default (hardened) flags are still used.
DEB_CXXFLAGS_MAINT_APPEND = -fno-strict-aliasing

include /usr/share/dpkg/buildflags.mk

%:
	dh $@

override_dh_auto_configure:
	xmkmf -a

# imake assigns CXXFLAGS/CDEBUGFLAGS itself, which discards the values exported
# by dh_auto_build. Feed the dpkg-buildflags values back in through the imake
# variables that are actually used. CPPFLAGS is already appended by make's
# built-in %.o: %.cc rule, so it must not be repeated here.
override_dh_auto_build:
	dh_auto_build -- \
		CXXDEBUGFLAGS="$(CXXFLAGS)" \
		CDEBUGFLAGS= \
		LOCAL_LDFLAGS="$(LDFLAGS)"

override_dh_auto_install:
	dh_auto_install -- BINDIR=/usr/games
