Find crt0 and the LD script automatically

gnuefi doesn't install crt0 and the ld script to a gnuefi directory by
default, but some distributions stick it there. Use find via a shell
command to take the last matching file for each of CRT0 and LDSCRIPT.

This avoids forcing the caller to duplicate the script generating the
ARCH variable used throughout the Makefile.

Signed-off-by: Darren Hart <>
CC: Matt Fleming <>
diff --git a/Makefile b/Makefile
index dffc1c1..4c7e990 100644
--- a/Makefile
+++ b/Makefile
@@ -50,8 +50,9 @@
 INCDIR := /usr/include
-CRT0 := $(LIBDIR)/gnuefi/crt0-efi-$(ARCH).o
-LDSCRIPT := $(LIBDIR)/gnuefi/elf_$(ARCH)
+# gnuefi sometimes installs these under a gnuefi/ directory, and sometimes not
+CRT0 := $(shell find $(LIBDIR) -name crt0-efi-$(ARCH).o 2>/dev/null | tail -n1)
+LDSCRIPT := $(shell find $(LIBDIR) -name elf_$(ARCH) 2>/dev/null | tail -n1)
 CFLAGS=-I. -I$(INCDIR)/efi -I$(INCDIR)/efi/$(ARCH) \
 		-DEFI_FUNCTION_WRAPPER -fPIC -fshort-wchar -ffreestanding \