os-core/Makefile

87 lines
1.5 KiB
Makefile

# environment
AARCH64_TOOLCHAIN ?= aarch64-linux-gnu
# Shortcuts
CC=clang --target=aarch64-none-elf -mcpu=cortex-a57
# CC=$(AARCH64_TOOLCHAIN)-gcc
LD=$(AARCH64_TOOLCHAIN)-ld
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 = sys/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) $^ -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 \
-cpu cortex-a57 \
-machine type=virt \
-nographic \
-smp 4 \
-m 4098 \
-kernel build/kernel.elf \
-serial stdio \
-monitor none
clean:
rm -Rf ./$(BUILD_DIR)/*
run: kernel
$(QEMU_CMD)
debug: kernel
$(QEMU_CMD) -gdb tcp::1234 -S