Makefile 874 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. .POSIX:
  2. .PHONY: all clean run
  3. ARCH = $(shell uname -m | sed s,i[3456789]86,ia32,)
  4. OBJS = main.o
  5. TARGET = hello.efi
  6. EFIINC = /usr/include/efi
  7. EFIINCS = -I$(EFIINC) -I$(EFIINC)/$(ARCH) -I$(EFIINC)/protocol
  8. LIB = /usr/lib
  9. EFILIB = /usr/lib
  10. EFI_CRT_OBJS = $(EFILIB)/crt0-efi-$(ARCH).o
  11. EFI_LDS = $(EFILIB)/elf_$(ARCH)_efi.lds
  12. CFLAGS = $(EFIINCS) -fno-stack-protector -fpic -fshort-wchar -mno-red-zone -Wall
  13. ifeq ($(ARCH),x86_64)
  14. CFLAGS += -DEFI_FUNCTION_WRAPPER
  15. endif
  16. LDFLAGS = -nostdlib -znocombreloc -T $(EFI_LDS) -shared \
  17. -Bsymbolic -L $(EFILIB) -L $(LIB) $(EFI_CRT_OBJS)
  18. all: $(TARGET)
  19. hello.so: $(OBJS)
  20. ld $(LDFLAGS) $(OBJS) -o $@ -lefi -lgnuefi
  21. %.efi: %.so
  22. objcopy -j .text -j .sdata -j .data -j .dynamic \
  23. -j .dynsym -j .rel -j .rela -j .reloc \
  24. --target=efi-app-$(ARCH) $^ $@
  25. run: all
  26. qemu-system-x86_64 -bios ovmf.fd
  27. clean:
  28. rm -f *.efi *.o *.so