summaryrefslogtreecommitdiff
path: root/website-kernel/Makefile
diff options
context:
space:
mode:
authorNathan Lee <me@nwlee.tech>2026-09-25 23:24:31 -0500
committerNathan Lee <me@nwlee.tech>2026-09-25 23:24:31 -0500
commit548905a86473101325540446f35ffda8acd0c3bb (patch)
tree57e495fbdb302d83880bd36e7368cdb48cd23e25 /website-kernel/Makefile
parent6858c9e7c97f772eb357e3eee0c1fcfb8adcb699 (diff)
scaffold kernel from parts of wkern x86
Diffstat (limited to 'website-kernel/Makefile')
-rw-r--r--website-kernel/Makefile73
1 files changed, 73 insertions, 0 deletions
diff --git a/website-kernel/Makefile b/website-kernel/Makefile
new file mode 100644
index 0000000..eb5a76e
--- /dev/null
+++ b/website-kernel/Makefile
@@ -0,0 +1,73 @@
+CC = clang
+LD = ld.lld
+OBJCOPY = llvm-objcopy
+
+COMPILER = $(shell $(CC) --version | head -n 1)
+LINKER = $(shell $(LD) --version | head -n 1)
+ARCH_NAME = 32-bit RISC-V, IM_Zicsr ISA, little endian, unknown ELF, System V ABI
+
+CFLAGS = \
+ --target=riscv32-unknown-elf \
+ -march=rv32im_zicsr \
+ -mabi=ilp32 \
+ -ffreestanding \
+ -fno-builtin \
+ -nostdlib \
+ -nostdinc \
+ -nodefaultlibs \
+ -DVERSION='"$(VERSION)"' \
+ -DCOMPILER_NAME='"$(COMPILER)"' \
+ -DLINKER_NAME='"$(LINKER)"' \
+ -DARCH_NAME='"$(ARCH_NAME)"' \
+ -static \
+ -ffunction-sections -fdata-sections -fno-common \
+ -Iinclude -O2 -g3 \
+ -Wall -Wextra -Werror -Wundef
+
+LD_FLAGS = \
+ -T $(LINKER_SCRIPT) -nostdlib -m elf32lriscv --gc-sections
+
+OBJCOPY_FLAGS = \
+ -O binary \
+ --strip-all \
+ --remove-section=.comment \
+ --remove-section=.debug* \
+ --remove-section=.note* \
+ --remove-section=.eh_frame \
+ --remove-section=.eh_frame_ptr \
+ --remove-section=.eh_frame_hdr
+
+C_SRCS = $(shell find . -name '*.c')
+S_SRCS = $(shell find . -name '*.S')
+C_OBJECTS = $(C_SRCS:.c=.o)
+S_OBJECTS = $(S_SRCS:.S=.o)
+ALL_OBJECTS = $(C_OBJECTS) $(S_OBJECTS)
+LINKER_SCRIPT = arch/linker.ld
+
+KERNEL_BINARY = Image.bin
+KERNEL_ELF = arch/webos-kernel.elf
+
+$(V).SILENT:
+
+%.o: %.c
+ @echo " CC $<"
+ $(CC) $(CFLAGS) -c $< -o $@
+%.o: %.S
+ @echo " AS $<"
+ $(CC) $(CFLAGS) -c $< -o $@
+$(KERNEL_ELF): $(ALL_OBJECTS) $(LINKER_SCRIPT)
+ @echo " LD $@"
+ $(LD) $(LD_FLAGS) -o $@ $(ALL_OBJECTS)
+$(KERNEL_BINARY): $(KERNEL_ELF)
+ @echo " OBJCOPY $@"
+ $(OBJCOPY) $(OBJCOPY_FLAGS) $(KERNEL_ELF) $(KERNEL_BIN)
+clean:
+ @echo " CLEAN $(ALL_OBJECTS)"
+ $(RM) $(ALL_OBJECTS)
+ @echo " CLEAN $(KERNEL_ELF)"
+ $(RM) $(KERNEL_ELF)
+ @echo " CLEAN $(KERNEL_BINARY)"
+ $(RM) $(KERNEL_BINARY)
+
+.PHONY: all clean
+all: $(KERNEL_BINARY)