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

# Copyright (C) 2012-2015 Hunter Kaller
# Copyright (C) 2014-2017 Sergio Benjamim

# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.


# Fix hardening-no-bindnow and hardening-no-pie
export DEB_BUILD_MAINT_OPTIONS = hardening=+bindnow,+pie

# 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

export DEB_LDFLAGS_MAINT_APPEND = -Wl,--as-needed

export QT_SELECT := qt5

ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(ARCH), $(filter $(ARCH), amd64 i386))
	CONFIG_EXTRA_FLAGS=--enable-sse
else ifeq ($(ARCH),armhf)
	CONFIG_EXTRA_FLAGS=--disable-cg --enable-opengles --enable-neon --enable-floathard
else ifeq ($(ARCH),arm64)
	CONFIG_EXTRA_FLAGS=--disable-cg --enable-opengles
endif

GIT_HASH := "b2ceb50"

%:
	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)

override_dh_auto_configure:
	sed 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' \
		retroarch.cfg > debian/retroarch.cfg
	# See ./configure --help for valid flags
	# disable flags (i.e. --disable-ffmpeg for example) if there is no package relative to the feature in Build-Depends
	./configure --prefix=/usr \
		--disable-builtinmbedtls \
		--disable-builtinbearssl \
		--disable-builtinflac \
		--disable-builtinglslang \
		--disable-builtinzlib \
		--disable-update_assets \
		--disable-oss \
		--disable-vg \
		--enable-dbus \
		--enable-spirv_cross \
		--enable-vulkan \
		$(CONFIG_EXTRA_FLAGS)

override_dh_auto_build:
	dh_auto_build -- V=1 GIT_VERSION="'$(GIT_HASH)'"
	# SoftFilters
	dh_auto_build -- V=1 -C gfx/video_filters/
	# Audio DSP plugins
	dh_auto_build -- V=1 -C libretro-common/audio/dsp_filters/

override_dh_auto_install:

override_dh_auto_clean:
	touch config.mk
	dh_auto_clean
	dh_auto_clean -- -C gfx/video_filters/ clean
	dh_auto_clean -- -C libretro-common/audio/dsp_filters/ clean
