#!/usr/bin/make -f

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

ARCH=$(shell dpkg-architecture -qDEB_HOST_ARCH)

ifeq ($(ARCH), $(filter $(ARCH), amd64 i386))
	NDR=off
	ifeq ($(ARCH),amd64)
		TOOLCHAIN=cmake/flags-gcc-x86_64.cmake
	else
		TOOLCHAIN=cmake/flags-gcc-i686.cmake
	endif
else
	NDR=on
	ifeq ($(ARCH),armhf)
		TOOLCHAIN=cmake/flags-gcc-armv7.cmake
	else
		TOOLCHAIN=cmake/flags-gcc-aarch64.cmake
	endif
endif

#export DH_VERBOSE = 1


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

# 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 $@ --buildsystem cmake+ninja


# 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:
	dh_auto_configure --buildsystem cmake+ninja -- --preset regular --toolchain $(TOOLCHAIN) -DNEW_DYNAREC=$(NDR) -B .

override_dh_auto_build:
	dh_auto_build --buildsystem cmake+ninja

override_dh_auto_test:

override_dh_auto_install:
	dh_auto_install --buildsystem cmake+ninja
	for i in 48x48 64x64 72x72 96x96 128x128 192x192 256x256 512x512 ; do \
		install -Dm644 src/unix/assets/$$i/net.86box.86Box.png -t debian/86box/usr/share/icons/hicolor/$$i/apps ; \
	done
	mkdir debian/86box/usr/share/applications
	sed 's/^Exec.*/Exec=86Box -P .local\/share\/86Box/' "src/unix/assets/net.86box.86Box.desktop" > "debian/86box/usr/share/applications/net.86box.86Box.desktop"

override_dh_installdocs:

override_dh_installman: