#!/usr/bin/make -f

export DH_VERBOSE := 1

DEB_HOST_ARCH_CPU := $(shell dpkg-architecture -qDEB_HOST_ARCH_CPU 2>/dev/null)
ifeq (amd64, $(DEB_HOST_ARCH_CPU))
	EFI_ARCH := x64
else
ifeq (i386, $(DEB_HOST_ARCH_CPU))
	EFI_ARCH := ia32
else
ifeq (arm64, $(DEB_HOST_ARCH_CPU))
	EFI_ARCH := aa64
else
	$(warning EFI architecture for $(DEB_HOST_ARCH_CPU) is unknown)
	EFI_ARCH := $(DEB_HOST_ARCH_CPU)
endif
endif
endif

%:
	dh $@

override_dh_auto_clean:
	dh_auto_clean
	rm -rf drivers_*/

override_dh_auto_build:
	$(MAKE) gnuefi
	$(MAKE) fs_gnuefi

override_dh_auto_install:
	# "make install" actually runs "efi-install" for the current system, so let's not do that :)

override_dh_install:
	dh_install
	mkdir -p debian/refind/usr/share/refind/refind/tools_$(EFI_ARCH)
	cp gptsync/gptsync_$(EFI_ARCH).efi debian/refind/usr/share/refind/refind/tools_$(EFI_ARCH)/

override_dh_installchangelogs:
	dh_installchangelogs NEWS.txt
