#!/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

DEB_HOST_ARCH?=$(shell dpkg-architecture -qDEB_HOST_ARCH)

OUR_CPPFLAGS:=
OUR_CXXFLAGS:=
OUR_LDFLAGS:=	-Wl,--as-needed

# needed so top-level exceptions are displayed as fatal errors for users
OUR_CPPFLAGS+=	-DNDEBUG

# Build without Altivec on ppc64el to prevent build failures
ifeq ($(DEB_HOST_ARCH),ppc64el)
OUR_CXXFLAGS+=	-mno-altivec
export CC=gcc-10
export CXX=g++-10
endif

ifneq (,$(filter ${DEB_HOST_ARCH},armel m68k mips mipsel powerpc powerpcspe sh4))
OUR_LDFLAGS+=	-Wl,--start-group -latomic
endif

export DEB_BUILD_MAINT_OPTIONS := hardening=+all
export DEB_CPPFLAGS_MAINT_APPEND := ${OUR_CPPFLAGS}
export DEB_CXXFLAGS_MAINT_APPEND := ${OUR_CXXFLAGS}
export DEB_LDFLAGS_MAINT_APPEND := ${OUR_LDFLAGS}

%:
	dh $@

override_dh_auto_configure:
	dh_auto_configure -- \
		-DCMAKE_VERBOSE_MAKEFILE=ON \
		-DENABLE_TOOLS=ON \
		-DCMAKE_INSTALL_PREFIX=/usr

override_dh_install:
	dh_install
	$(RM) debian/performous-tools/usr/games/performous

override_dh_missing:
	dh_missing --fail-missing

get-orig-source:
	uscan --download-current-version --force-download
