#!/usr/bin/make -f

# See debhelper(7) (uncomment to enable).
# Output every command that modifies files on the build system.
#export DH_VERBOSE = 1


# See FEATURE AREAS in dpkg-buildflags(1).
#export DEB_BUILD_MAINT_OPTIONS = hardening=+all

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

# disable excess precision on i386/m68k/s390x
export DEB_CXXFLAGS_MAINT_APPEND += -fexcess-precision=fast

# See ENVIRONMENT in dpkg-buildflags(1).
# Package maintainers to append CFLAGS.
#export DEB_CFLAGS_MAINT_APPEND  = -Wall -pedantic
# Package maintainers to append LDFLAGS.
#export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed


%:
	dh $@


# dh_make generated override targets.
# This is an example for Cmake (see <https://bugs.debian.org/641051>).
#override_dh_auto_configure:
#	dh_auto_configure -- \
#	-DCMAKE_LIBRARY_PATH=$(DEB_HOST_MULTIARCH)

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 \
            --enable-engine=monkey4

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