Add Makefile.

This will both improve CI, and decouple the kernel build script from
cookbook.
This commit is contained in:
4lDO2 2024-06-25 12:46:02 +02:00
parent 15c7e10d52
commit c73e2ffecf
No known key found for this signature in database
GPG Key ID: 4EEF2FB4486F9457
1 changed files with 37 additions and 0 deletions

37
Makefile Normal file
View File

@ -0,0 +1,37 @@
export RUST_TARGET_PATH=targets
ifeq ($(TARGET),)
ARCH?=$(shell uname -a)
else
ARCH?=$(shell echo "$(TARGET)" | cut -d - -f1)
endif
BUILD?=target/$(ARCH)-unknown-kernel
all: $(BUILD)/kernel $(BUILD)/kernel.sym
LD_SCRIPT=linkers/$(ARCH).ld
TARGET_SPEC=targets/$(ARCH)-unknown-kernel.json
$(BUILD)/kernel.all: $(LD_SCRIPT) $(TARGET_SPEC) $(shell find . -name "*.rs" -type f)
cargo rustc \
--bin kernel \
--target "$(TARGET_SPEC)" \
--release \
-Z build-std=core,alloc \
-- \
-C link-arg=-T -Clink-arg="$(LD_SCRIPT)" \
-C link-arg=-z -Clink-arg=max-page-size=0x1000 \
--emit link="$(BUILD)/kernel.all"
$(BUILD)/kernel.sym: $(BUILD)/kernel.all
$(TARGET)-objcopy \
--only-keep-debug \
"$(BUILD)/kernel.all" \
"$(BUILD)/kernel.sym"
$(BUILD)/kernel: $(BUILD)/kernel.all
$(TARGET)-objcopy \
--strip-debug \
"$(BUILD)/kernel.all" \
"$(BUILD)/kernel"