#! /usr/bin/make -f

include /usr/share/dpkg/default.mk

VERSION := $(shell LC_ALL=C dpkg-parsechangelog | grep ^Version: | cut -d ' ' -f 2)
SHIM_VERSION := $(shell dpkg-query -f '$${Version}\n' -W shim)
export SHIM_VERSION
# The PPA's UEFI signing service signs the shim/fb/mm EFI binaries with the
# PPA's own UEFI CA (CN=PPA kylinsoft anything3.0 UEFI), not with the
# Microsoft UEFI CA 2011.  The upstream default Makefile path attaches the
# checked-in external (Microsoft) signature to the freshly downloaded
# binaries, whose hash does not match the current shim release, making
# 'make check' fail.  Use the upstream NO_EXTERNAL path: it ships the
# archive-signed binaries directly and verifies them against the archive's
# control/uefi.crt (the CA that actually signed them).
export NO_EXTERNAL := 1

ifeq ($(DEB_TARGET_ARCH),amd64)
export EFI_ARCH := X64
endif
ifeq ($(DEB_TARGET_ARCH),arm64)
export EFI_ARCH := AA64
endif
export EFI_ARCH_LOWER := $(shell echo $(EFI_ARCH) | tr A-Z a-z)
export SHIM_BASE = shim$(EFI_ARCH_LOWER).efi
export SHIM_NX = shim$(EFI_ARCH_LOWER).nx.efi
export FB_BASE = fb$(EFI_ARCH_LOWER).efi
export MM_BASE = mm$(EFI_ARCH_LOWER).efi

%:
	dh $@

docdir := debian/shim-signed/usr/share/doc/shim-signed

override_dh_installchangelogs:
	dh_installchangelogs
	# Quieten lintian, which otherwise gets confused by our odd version
	# number.
	ln $(docdir)/changelog $(docdir)/changelog.Debian

override_dh_gencontrol:
	dh_gencontrol -- -v$(VERSION)+$(SHIM_VERSION) \
		-Vshim:Version=$(SHIM_VERSION)

override_dh_builddeb:
	dh_builddeb -- -Zxz
