os-core/Makefile

91 lines
1.6 KiB
Makefile

# environment
AARCH64_TOOLCHAIN ?= aarch64-linux-gnu
# Shortcuts
CC=clang --target=aarch64-none-elf -mcpu=cortex-a57
LD=ld.lld
OBJCOPY=$(AARCH64_TOOLCHAIN)-objcopy --target elf64-littleaarch64
CFLAGS += -O0
CFLAGS += -g
#CFLAGS += -nostdlib
#CFLAGS += -march=armv8-a
#CFLAGS += -std=c99
#CFLAGS += -pedantic
#CFLAGS += -Wall
#CFLAGS += -Wmissing-prototypes
#CFLAGS += -Wstrict-prototypes
#CFLAGS += -Wold-style-definition
BUILD_DIR=build
# Files
KERNEL_MEMMAP = aarch64/memmap
KERNEL_SOURCES = \
aarch64/boot.s \
sys/main.c \
sys/uart.c \
KERNEL_LIST := $(wildcard $(KERNEL_SOURCES))
KERNEL_OBJS := $(addsuffix .o, $(addprefix $(BUILD_DIR)/, ${KERNEL_LIST}))
all: kernel
# compilation
kernel: $(BUILD_DIR)/kernel.elf # $(BUILD_DIR)/kernel.sym
$(BUILD_DIR)/kernel.elf: $(KERNEL_OBJS)
$(info linking target: $@)
$(LD) -T$(KERNEL_MEMMAP) -nostdlib $^ -o $@
$(info done: $@)
$(BUILD_DIR)/kernel.bin: $(BUILD_DIR)/kernel.elf
$(OBJCOPY) -O binary $< $@
$(BUILD_DIR)/kernel.sym: $(BUILD_DIR)/kernel.elf
$(OBJCOPY) --only-keep-debug $< $@
$(OBJCOPY) --strip-debug $@
$(BUILD_DIR)/%.o: %
$(info compiling file: $<)
@mkdir -p $(dir ./$(BUILD_DIR)/$<)
$(CC) $(CFLAGS) -c $< -o $@
.PHONY: clean run
# helpers
QEMU_CMD = \
qemu-system-aarch64 \
-M virt \
-cpu cortex-a57 \
-nographic \
-smp 4 \
-m 4096 \
-kernel build/kernel.elf \
-serial stdio \
-monitor none \
clean:
rm -Rf ./$(BUILD_DIR)/*
run: kernel
$(QEMU_CMD)
debug: kernel
$(QEMU_CMD) -S -gdb tcp::1234 & \
gdb-multiarch -q \
-ex 'file build/kernel.elf' \
-ex 'target remote localhost:1234'
kill %1