summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2025-12-08 22:25:48 +0800
committerRichard Qin <richard.qin.x@gmail.com>2025-12-08 22:25:48 +0800
commit8cf8be522133548ee25fdcb0258ddf3950a68bcf (patch)
tree17d97abd848638d44de41e202d891dcaf4bb68c0 /Makefile
downloadlume-8cf8be522133548ee25fdcb0258ddf3950a68bcf.tar.gz
lume-8cf8be522133548ee25fdcb0258ddf3950a68bcf.tar.xz
The start of the project -- A MicroDOS
feat: Initial bare-metal RISC-V boot with UART
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile61
1 files changed, 61 insertions, 0 deletions
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..4d80143
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,61 @@
+TOOLCHAIN := riscv64-linux-gnu
+CC := $(TOOLCHAIN)-gcc
+CXX := $(TOOLCHAIN)-g++
+LD := $(TOOLCHAIN)-ld
+OBJCOPY := $(TOOLCHAIN)-objcopy
+
+TARGET_ELF := build/kernel.elf
+TARGET_BIN := build/kernel.bin
+
+ARCH_FLAGS := -march=rv64gc -mabi=lp64 -mcmodel=medany
+CFLAGS := -Wall -Wextra -O2 -ffreestanding -nostdlib -Iinclude $(ARCH_FLAGS)
+CXXFLAGS := $(CFLAGS) -fno-exceptions -fno-rtti -fno-use-cxa-atexit
+
+SRC_DIRS := src
+SRCS_ASM := $(shell find $(SRC_DIRS) -name "*.S")
+SRCS_CXX := $(shell find $(SRC_DIRS) -name "*.cc")
+
+OBJS := $(SRCS_ASM:%.S=build/%.o) $(SRCS_CXX:%.cc=build/%.o)
+
+DEPS := $(OBJS:.o=.d)
+
+
+LINKER_SCRIPT := linker.ld
+
+QEMU := qemu-system-riscv64
+QEMU_FLAGS := -machine virt -m 128M -nographic -bios none -kernel $(TARGET_ELF)
+
+
+.PHONY: all clean run debug directories
+
+all: directories $(TARGET_ELF)
+
+$(TARGET_ELF): $(OBJS) $(LINKER_SCRIPT)
+ @echo "Linking $@"
+ @$(LD) -T $(LINKER_SCRIPT) -o $@ $(OBJS)
+
+build/%.o: %.S
+ @mkdir -p $(dir $@)
+ @echo "Compiling ASM $<"
+ @$(CC) $(CFLAGS) -MMD -c $< -o $@
+
+build/%.o: %.cc
+ @mkdir -p $(dir $@)
+ @echo "Compiling C++ $<"
+ @$(CXX) $(CXXFLAGS) -MMD -c $< -o $@
+
+directories:
+ @mkdir -p build
+
+run: all
+ @echo "Starting QEMU..."
+ $(QEMU) $(QEMU_FLAGS)
+
+debug: all
+ @echo "Starting QEMU in debug mode (connect with gdb-multiarch)..."
+ $(QEMU) $(QEMU_FLAGS) -S -s
+
+clean:
+ @rm -rf build
+
+-include $(DEPS) \ No newline at end of file