2023-07-24 00:01:39 -04:00
|
|
|
PROJECT = test
|
|
|
|
|
|
|
|
# where your rv32 toolchain is
|
|
|
|
TCPATH = /home/lily/bin/riscv/bin
|
|
|
|
PREFIX = $(TCPATH)/riscv32-unknown-elf
|
|
|
|
|
|
|
|
CC = $(PREFIX)-gcc
|
|
|
|
CXX = $(PREFIX)-g++
|
|
|
|
|
2023-07-24 01:56:50 -04:00
|
|
|
ARCHFLAGS = -ffreestanding -fno-stack-protector -fdata-sections -ffunction-sections -march=rv32ima -mabi=ilp32
|
|
|
|
CCFLAGS = -g -Os $(ARCHFLAGS) -std=c18
|
|
|
|
CXXFLAGS = $(ARCHFLAGS) -g -Os -std=c++20 -fno-exceptions -fno-rtti
|
2023-07-24 00:01:39 -04:00
|
|
|
LDFLAGS = -T binary.ld -nostdlib -Wl,--gc-sections
|
|
|
|
|
2023-07-24 01:56:50 -04:00
|
|
|
OBJS = start.o \
|
|
|
|
main.o
|
2023-07-24 00:01:39 -04:00
|
|
|
|
|
|
|
.PHONY: all test clean
|
|
|
|
|
|
|
|
all: $(PROJECT).bin $(PROJECT).debug.txt
|
|
|
|
|
2023-07-24 01:56:50 -04:00
|
|
|
# this assumes the lcpu project build dir you're using is
|
|
|
|
# [lcpu repo root]/build
|
2023-07-24 00:01:39 -04:00
|
|
|
test: $(PROJECT).bin $(PROJECT).debug.txt
|
|
|
|
../../../../build/projects/riscv_test_harness/rvtest $<
|
|
|
|
|
|
|
|
clean:
|
|
|
|
rm $(PROJECT).elf $(PROJECT).bin $(PROJECT).debug.txt $(OBJS)
|
|
|
|
|
2023-07-24 01:56:50 -04:00
|
|
|
# Link rules
|
|
|
|
|
2023-07-24 00:01:39 -04:00
|
|
|
$(PROJECT).elf: $(OBJS)
|
|
|
|
$(CC) $(CCFLAGS) $(LDFLAGS) -o $@ $(OBJS)
|
|
|
|
|
|
|
|
$(PROJECT).bin : $(PROJECT).elf
|
|
|
|
$(PREFIX)-objcopy $^ -O binary $@
|
|
|
|
|
|
|
|
$(PROJECT).debug.txt : $(PROJECT).elf
|
|
|
|
$(PREFIX)-objdump -t $^ > $@
|
|
|
|
$(PREFIX)-objdump -S $^ >> $@
|
|
|
|
|
|
|
|
# Compile rules
|
|
|
|
|
|
|
|
%.o: %.cpp
|
|
|
|
$(CXX) -c $(CXXFLAGS) $< -o $@
|
|
|
|
|
|
|
|
%.o: %.c
|
|
|
|
$(CC) -c $(CCFLAGS) $< -o $@
|
|
|
|
|
|
|
|
%.o: %.S
|
|
|
|
$(CC) -x assembler-with-cpp -march=rv32ima -mabi=ilp32 -c $< -o $@
|
|
|
|
|
|
|
|
|