#!/usr/bin/make -f

export DEB_CXXFLAGS_MAINT_STRIP=-O2
export DEB_CFLAGS_MAINT_STRIP=-O2

##export DEB_CFLAGS_MAINT_APPEND=-DHAVE_DR_FLAC=0

ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(ARCH), $(filter $(ARCH), amd64 i386))
	CONFIG_EXTRA_FLAGS=--enable-sse
else ifeq ($(ARCH),armhf)
# Doesn't build with --enable-neon (I don't know why).
	CONFIG_EXTRA_FLAGS=--disable-cg --enable-opengles --enable-floathard --disable-videocore
#	PARALLEL=--no-parallel
else ifeq ($(ARCH),arm64)
	CONFIG_EXTRA_FLAGS=--disable-cg --enable-opengles
#	PARALLEL=--no-parallel
endif

export QT_SELECT := qt6

%:
	dh $@ --with quilt -XCOPYING

execute_before_dh_auto_configure:
	sed 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' \
		retroarch.cfg > debian/retroarch.cfg
	sed 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' \
		debian/retroarch.dirs.in > debian/retroarch.dirs
	sed 's/@DEB_HOST_MULTIARCH@/$(DEB_HOST_MULTIARCH)/g' \
		debian/retroarch.install.in > debian/retroarch.install

override_dh_auto_configure:
	./configure \
	$(CONFIG_EXTRA_FLAGS) \
	--disable-builtinmbedtls \
	--disable-builtinzlib \
	--disable-update_assets \
	--disable-vg \
	--enable-dbus \
	--enable-builtinflac \
	--prefix=/usr

#	exit 1

override_dh_auto_build:
	dh_auto_build -- V=1

	# SoftFilters
	dh_auto_build -- -C gfx/video_filters/

	# Audio DSP plugins
	dh_auto_build -- -C libretro-common/audio/dsp_filters/

override_dh_auto_clean:
	touch config.mk
	dh_auto_clean qb/config.libs.sh debian/retroarch.cfg

	dh_auto_clean -- -C gfx/video_filters/ clean
	dh_auto_clean -- -C libretro-common/audio/dsp_filters/ clean
