# Don't use $(wildcard ...) here - at least make 3.80 expands this too early!
$(TARGET).efi: guard = $(if $(shell echo efi/dis* | grep disabled),:)
+# Check if the build system supports PE.
+efi := y$(shell rm -f efi/disabled)
+efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c efi/check.c -o efi/check.o 2>efi/disabled && echo y))
+efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o efi/check.efi efi/check.o 2>efi/disabled && echo y))
+efi := $(if $(efi),$(shell rm efi/disabled)y)
+export BUILD_PE := $(efi)
+ifeq ($(efi),y)
+CFLAGS += -DBUILD_PE
+endif
+
ifneq ($(build_id_linker),)
ifeq ($(call ld-ver-build-id,$(LD) $(filter -m%,$(EFI_LDFLAGS))),y)
CFLAGS += -DBUILD_ID_EFI
CFLAGS += -fshort-wchar
-efi := y$(shell rm -f disabled)
-efi := $(if $(efi),$(shell $(CC) $(filter-out $(CFLAGS-y) .%.d,$(CFLAGS)) -c check.c 2>disabled && echo y))
-efi := $(if $(efi),$(shell $(LD) -mi386pep --subsystem=10 -o check.efi check.o 2>disabled && echo y))
-efi := $(if $(efi),$(shell rm disabled)y)
-
%.o: %.ihex
$(OBJCOPY) -I ihex -O binary $< $@
boot.init.o: buildid.o
obj-y := stub.o
-obj-$(efi) := boot.init.o compat.o relocs-dummy.o runtime.o
-extra-$(efi) += buildid.o
-nocov-$(efi) += stub.o
+obj-$(BUILD_PE) := boot.init.o compat.o relocs-dummy.o runtime.o
+extra-$(BUILD_PE) += buildid.o
+nocov-$(BUILD_PE) += stub.o