#!/usr/bin/make -f

# Uncomment this to turn on verbose mode.
#export DH_VERBOSE=1

export DEB_BUILD_MAINT_OPTIONS=hardening=+all

# #827145:
# When building for i386 on an amd64 system/kernel, the host
# architecture is misdetected as x86_64, which causes USE_NASM to be
# unset and prevents the object files hq2x_i386.o and hq3x_i386.o from
# being built.
# This is fixed by passing the host architecture explicitely to
# configure.
include /usr/share/dpkg/architecture.mk

ifneq ($(DEB_HOST_GNU_TYPE),$(DEB_BUILD_GNU_TYPE))
	HOST := --host=$(DEB_HOST_GNU_TYPE)
else
	HOST :=
endif

%:
	dh $@

ifneq (linux,$(DEB_HOST_ARCH_OS))
OPTARGS:= --disable-alsa
endif

override_dh_auto_clean:
	##718164 "FTBFS: Makefile:87: *** You need to run ./configure before you can run make".
	[ -f config.mk ] || touch config.mk
	dh_auto_clean

override_dh_auto_configure:
	./configure \
            $(HOST) \
            --datadir=/usr/share/scummvm \
            --bindir=/usr/games \
            --disable-eventrecorder \
            --enable-release \
            --enable-verbose-build \
            --enable-opl2lpt \
            --prefix=/usr $(OPTARGS) \
            --disable-gold

execute_before_dh_auto_build:
## replacing bundled fonts...
#	for F in gui/themes/*/Free*.ttf; do cp -v /usr/share/fonts/truetype/freefont/$${F##*/} $${F%/*}; done
#	for F in gui/themes/*/mplus*.ttf; do cp -v /usr/share/fonts/truetype/mplus/$${F##*/} $${F%/*}; done
## re-build themes
	cd gui/themes && python3 ./scummtheme.py makeall

override_dh_installchangelogs:
	dh_installchangelogs NEWS.md

override_dh_gencontrol:
	dh_gencontrol -- -Vmy:Built-Using="$(shell dpkg-query --show -f '$${source:Package} (=$${source:Version}),' fonts-freefont-ttf fonts-mplus)"

override_dh_dwz:
	-dh_dwz -v