diff options
Diffstat (limited to 'boot/Makefile')
| -rw-r--r-- | boot/Makefile | 78 |
1 files changed, 78 insertions, 0 deletions
diff --git a/boot/Makefile b/boot/Makefile new file mode 100644 index 0000000..b49690c --- /dev/null +++ b/boot/Makefile @@ -0,0 +1,78 @@ +# ============================================================================ +# boot/Makefile - UEFI Loader Build +# Produces: $(RESULT_DIR)/BOOTX64.EFI (x86) or BOOTAA64.EFI(aarch64) +# +# Strategy: Compile with Clang targeting Windows PE32+, link with lld-link. +# This produces a native .efi (PE32+) directly - no objcopy needed. +# TODO: create PE header in the code, and get rid from clang dependency +# ============================================================================ + +include ../config.mk +-include ../config_generated.mk + +COMMON_SRC := \ + common/efi_loader.cpp \ + common/efi_elf_parser.cpp + +ARCH_SRC := \ + $(ARCH)/entry.cpp + +SRC := $(COMMON_SRC) $(ARCH_SRC) +OBJ := $(patsubst %.cpp,%.o,$(SRC)) + +# ── UEFI-specific flags ──────────────────────────────────────────────────── +# Compile as PE/COFF using Clang's Windows target with -fshort-wchar. + +ifeq ($(ARCH),x86_64) + EFI_TARGET := x86_64-unknown-windows + EFI_BINARY := BOOTX64.EFI + EFI_MFLAGS := -mno-red-zone #https://os.phil-opp.com/red-zone/#:~:text=Disable%20the%20Red%20Zone%20%7C%20Writing%20an%20OS%20in%20Rust +else ifeq ($(ARCH),aarch64) + EFI_TARGET := aarch64-unknown-windows + EFI_BINARY := BOOTAA64.EFI + EFI_MFLAGS := +endif + +EFI_CXXFLAGS := \ + -target $(EFI_TARGET) \ + -std=c++23 \ + -ffreestanding \ + -fno-exceptions \ + -fno-rtti \ + -fno-stack-protector \ + -fno-threadsafe-statics \ + -fno-use-cxa-atexit \ + -fshort-wchar \ + -nostdlib \ + -Wall -Wextra \ + -Werror=return-type \ + -O2 -g \ + $(EFI_MFLAGS) \ + -I../include \ + -include $(PROJECT_ROOT)/include/kernel/config.h \ + -DEFI_ARCH_$(shell echo $(ARCH) | tr a-z A-Z) + +EFI_LDFLAGS := \ + -flavor link \ + -subsystem:efi_application \ + -entry:efi_main \ + -nodefaultlib + +# ── Targets ───────────────────────────────────────────────────────────────── + +.PHONY: all clean + +all: $(RESULT_DIR)/$(EFI_BINARY) + +# Link directly to PE32+ .efi +$(RESULT_DIR)/$(EFI_BINARY): $(OBJ) + @mkdir -p $(dir $@) + @echo " LINK $@" + @lld-link $(EFI_LDFLAGS) $(OBJ) -out:$@ + +%.o: %.cpp + @echo " CXX $<" + @$(CXX) $(EFI_CXXFLAGS) -c $< -o $@ + +clean: + find . -name '*.o' -delete |
