Makefile tuning

This commit is contained in:
Imbus 2024-04-05 17:02:16 +02:00
parent 9ff42d8fbc
commit e681b848d5

View file

@ -10,8 +10,10 @@ SIZE = ${CROSS}-size
TARGET = bin.elf
# QEMU command and flags
QEMU = qemu-riscv64-static
QEMU_FLAGS =
# QEMU = qemu-riscv64-static
QEMU = qemu-system-riscv64
QEMU_FLAGS += --machine virt# # Use the virt machine
QEMU_FLAGS += --nographic# # No graphical output
# Flags for compiler and assembler
CFLAGS += -static# # Use static linking
@ -23,6 +25,13 @@ CFLAGS += -march=rv64i # Use RV64I ISA, i.e., integer only
CFLAGS += -mabi=lp64 # Use LP64 ABI, i.e., 64-bit longs and pointers, 32-bit ints
CFLAGS += -Os# # Optimize for size
LDFLAGS += -T link.ld # Use the linker script
LDFLAGS += --no-dynamic-linker
LDFLAGS += -m elf64lriscv
LDFLAGS += -static
LDFLAGS += -nostdlib
LDFLAGS += -s
# Use GC=0 to disable garbage collection
ifneq ($(GC), 0)
CFLAGS += -ffreestanding
@ -43,7 +52,7 @@ OBJS := $(AS_SRCS:.s=.o)
# Default target
all: $(OBJS)
@$(CC) $(CFLAGS) -o $(TARGET) $(OBJS)
@$(LD) $(LDFLAGS) -o $(TARGET) $(OBJS)
@echo "LD $(OBJS)"
# Compile assembly sources
@ -52,8 +61,9 @@ all: $(OBJS)
@echo "CC $<"
# Run the binary in QEMU
run: all
$(QEMU) $(QEMU_FLAGS) ./$(TARGET)
run: all
@echo "To exit: Ctrl+A, X"
@$(QEMU) $(QEMU_FLAGS) -bios $(TARGET)
# View the text section of the binary
inspect: all