#!/usr/bin/make -f

DEB_BUILD_ARCH_CPU ?= $(shell dpkg-architecture -qDEB_BUILD_ARCH_CPU)

ifeq (,$(findstring $(DEB_BUILD_ARCH_CPU),"amd64 i386 powerpc"))
	export DEB_BUILD_MAINT_OPTIONS=hardening=-fortify
endif

%:
	dh $@ --parallel --sourcedirectory=higan

override_dh_auto_clean:
	$(MAKE) --directory=icarus clean
	dh_auto_clean

override_dh_auto_build:
	mkdir -p icarus/obj icarus/out
	$(MAKE) --directory=icarus
	mkdir -p higan/obj higan/out
	dh_auto_build -- profile=balanced name=higan-balanced
# Allow for building higan only once when testing stuff with the build option testbuild.
ifeq (,$(findstring testbuild,$(DEB_BUILD_OPTIONS)))
	rm -rf higan/obj
	mkdir -p higan/obj
	dh_auto_build -- profile=accuracy name=higan-accuracy
	rm -rf higan/obj
	mkdir -p higan/obj
	dh_auto_build -- profile=performance name=higan-performance
else
	cp higan/out/higan-balanced higan/out/higan-accuracy
	cp higan/out/higan-balanced higan/out/higan-performance
endif

override_dh_auto_install:
	install -D -m 644 higan/data/higan.png debian/higan/usr/share/pixmaps/higan.png
	install -D -m 644 higan/data/higan.desktop debian/higan/usr/share/applications/higan.desktop
	install -D -m 644 higan/data/cheats.bml debian/higan/usr/share/higan/cheats.bml
	cp -R higan/profile/* debian/higan/usr/share/higan
	chmod 644 debian/higan/usr/share/higan/*/*

override_dh_auto_test:
