neptune/Makefile
2025-06-26 05:57:35 +02:00

49 lines
1.1 KiB
Makefile

TOOLPREFIX = riscv-none-elf
CC = $(TOOLPREFIX)-gcc
AS = $(TOOLPREFIX)-as
LD = $(TOOLPREFIX)-ld
OBJCOPY = $(TOOLPREFIX)-objcopy
OBJDUMP = $(TOOLPREFIX)-objdump
ASFLAGS = -march=rv64gc -mabi=lp64
LDFLAGS = -Tkernel.ld
LDFLAGS += -m elf64lriscv
CFLAGS = -Wall -Werror -O
CFLAGS += -mcmodel=medany
CFLAGS += -march=rv64gc -mabi=lp64
CFLAGS += -ffreestanding -fno-common -nostdlib -mno-relax
CFLAGS += -I.
CFLAGS += -Ilib
CFLAGS += -fno-stack-protector # Prevents code that needs libc / runtime support
CFLAGS += -MD # Generate header dependency files (.d)
CFLAGS += -fno-pie -no-pie # Fixed address linking
CFLAGS += -ggdb -gdwarf-2 # GDB debug info
CFLAGS += -fno-omit-frame-pointer # More reliable backtraces in GDB
all: kernel.elf
kernel.elf: entry.o start.o lib/string.o lib/proc.o lib/spinlock.o lib/proc.o
@echo LD $@
@$(LD) $(LDFLAGS) -o $@ $^
%.o: %.c
@echo CC $@
@$(CC) $(CFLAGS) -nostdinc -I. -c $< -o $@
%.o: %.S
@echo AS $@
@$(AS) $(ASFLAGS) -o $@ $<
qemu: kernel.elf
@echo QEMU $<
@qemu-system-riscv64 -machine virt -bios none -nographic -m 128M -smp 4 -kernel kernel.elf
clean:
rm -f *.o *.elf *.d lib/*.o lib/*.d
-include *.d