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

# Use debhelper default for all targets (but some are overridden below).
%:
	dh $@

# Enable all hardening options (since grfcodec potentially handles
# untrusted data files).
DEB_BUILD_MAINT_OPTIONS=hardening=+all

# Load buildflags (this uses dpkg-buildflags). Note that we don't export
# them, but instead pass them to ./configure explicitly.
include /usr/share/dpkg/buildflags.mk

# Don't use dh for clean. Since the upstream Makefile generates
# dependency information before any error messages, dh_auto_clean
# sometimes thinks make distclean is supported, while it isn't. Instead,
# we use make mrproper, which does something similar.
override_dh_auto_clean:
	make mrproper
	# Remove files autogenerated by make, but not removed by make
	# mrproper.
	rm -f Makefile.local

override_dh_auto_configure:
	# Disable UPX binary compression, it is not available on all
	# platforms.
	echo "UPX=" >> Makefile.local
	echo "DO_NOT_INSTALL_CHANGELOG=1" >> Makefile.local
	echo "DO_NOT_INSTALL_LICENSE=1" >> Makefile.local
ifeq (,$(filter terse,$(DEB_BUILD_OPTIONS)))
	echo "V=1" >> Makefile.local
endif
	echo "CXXFLAGS=$(CXXFLAGS) $(CPPFLAGS) -std=c++11" >> Makefile.local
	echo "LDOPT=$(LDFLAGS)" >> Makefile.local
	echo "prefix=/usr" >> Makefile.local
