#!/usr/bin/make -f

# dolphin does not work with -fPIE
export DEB_BUILD_MAINT_OPTIONS := hardening=+all,-pie

# distributor is used by the opt-in analytics
ifeq ($(shell dpkg-vendor --derives-from Ubuntu; echo $$?),0)
	DISTRIBUTOR := ubuntu.com
else
	DISTRIBUTOR := debian.org
endif

CMAKE_OPTIONS := \
	-DCMAKE_INSTALL_BINDIR="/usr/games" \
	-DCMAKE_INSTALL_DATADIR="/usr/share/games" \
	-DDISTRIBUTOR=$(DISTRIBUTOR) \
	-DUSE_DISCORD_PRESENCE=0 \
	-DUSE_MGBA=1 \
	-DUSE_SYSTEM_LIBS=ON \
	-DUSE_SYSTEM_MBEDTLS=OFF \
	-DUSE_SYSTEM_MINIZIP-NG=OFF \
	-DENABLE_TESTS=1 \
	-DGTEST_DIR=/usr/src/gtest \
	-DDOLPHIN_WC_BRANCH=master \
	-DDOLPHIN_WC_DESCRIBE=2512 \
	-DDOLPHIN_WC_REVISION=2614969fa80dfeb87d2a4ad3bdaa703237127074

%:
	dh $@ -Bbuild

override_dh_auto_configure:
	cp -a cpp-ipc Externals/cpp-ipc/cpp-ipc
	cp -a cpp-optparse Externals/cpp-optparse/cpp-optparse
	cp -a imgui Externals/imgui/imgui
	cp -a implot Externals/implot/implot
	cp -a minizip-ng Externals/minizip-ng/minizip-ng
	cp -a watcher Externals/watcher/watcher
	dh_auto_configure -- $(CMAKE_OPTIONS)

override_dh_auto_build:
	# False positive from blhc. See #1125781.
	@echo 'blhc: ignore-line-regexp: /usr/(bin|lib)/(ccache/)?c\+\+ (?:-std=\S+ )?-w -dM -E (?:-c )?/usr/share/cmake-[0-9.]+/Modules/CMakeCXXCompilerABI.cpp .*'
	dh_auto_build

execute_after_dh_auto_clean:
	$(RM) -rf Externals/cpp-ipc/cpp-ipc
	$(RM) -rf Externals/cpp-optparse/cpp-optparse
	$(RM) -rf Externals/imgui/imgui
	$(RM) -rf Externals/implot/implot
	$(RM) -rf Externals/minizip-ng/minizip-ng
	$(RM) -rf Externals/rcheevos/rcheevos
	$(RM) -rf Externals/watcher/watcher

override_dh_auto_test:
ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
	CTEST_OUTPUT_ON_FAILURE=1 $(MAKE) -C build unittests
endif
