abstractaccelerator/Cores-SweRV/demo/helloworld/Makefile

73 lines
2.4 KiB
Makefile

export RV_ROOT = ${PWD}/../..
LLVMINSTALL = /home/colin/develop/llvm-build/install
GCC_PREFIX = /opt/riscv/bin/riscv32-unknown-elf
DEMODIR = ${PWD}
BUILD_DIR = ${DEMODIR}/build
RV_DESIGN = ${RV_ROOT}/design
RV_SOC = ${RV_ROOT}/soc
TEST = hello_world
ifdef debug
DEBUG_PLUS = +dumpon
VERILATOR_DEBUG = --trace
endif
LINK = $(DEMODIR)/link.ld
# CFLAGS for verilator generated Makefiles. Without -std=c++11 it complains for `auto` variables
CFLAGS += "-std=c++11"
# Optimization for better performance; alternative is nothing for slower runtime (faster compiles)
# -O2 for faster runtime (slower compiles), or -O for balance.
VERILATOR_MAKE_FLAGS = OPT_FAST="-Os"
# Targets
all: clean verilator
clean:
rm -rf build obj_dir
swerv_define :
BUILD_PATH=${BUILD_DIR} PERLLIB=${RV_SOC} ${RV_SOC}/swerv.config -target=default -set iccm_enable
##################### Verilog Builds #####################################
verilator-build: swerv_define
echo '`undef ASSERT_ON' >> ${BUILD_DIR}/common_defines.vh
verilator --cc -CFLAGS ${CFLAGS} \
$(BUILD_DIR)/common_defines.vh \
-I${BUILD_DIR} \
-Wno-UNOPTFLAT \
-F ${RV_SOC}/soc.mk \
$(RV_SOC)/soc_top.sv \
--top-module soc_top -exe test_soc_top.cpp --autoflush $(VERILATOR_DEBUG)
cp ${DEMODIR}/test_soc_top.cpp obj_dir
$(MAKE) -j -C obj_dir/ -f Vsoc_top.mk $(VERILATOR_MAKE_FLAGS)
##################### Simulation Runs #####################################
verilator: program.hex verilator-build
cd build && ../obj_dir/Vsoc_top ${DEBUG_PLUS}
##################### Test hex Build #####################################
program.hex: $(TEST).out
@echo Building $(TEST)
$(GCC_PREFIX)-objcopy -O verilog $(BUILD_DIR)/$(TEST).out $(BUILD_DIR)/program.hex
$(GCC_PREFIX)-objdump -S $(BUILD_DIR)/$(TEST).out > $(BUILD_DIR)/$(TEST).dis
build: $(TEST).out
@echo Completed building $(TEST)
%.out : %.c swerv_define
$(LLVMINSTALL)/bin/clang --target=riscv32 -march=rv32gc $*.c -S -o $(BUILD_DIR)/$*.s -mno-relax
$(LLVMINSTALL)/bin/clang --target=riscv32 -march=rv32gc $*.c -c -o $(BUILD_DIR)/$*.o -mno-relax
$(LLVMINSTALL)/bin/ld.lld $(BUILD_DIR)/$*.o -Map=$(BUILD_DIR)/$(TEST).map -T$(LINK) -o $(BUILD_DIR)/$*.out
@echo Completed building $(TEST)
help:
@echo Possible targets: verilator help clean all verilator-build program.hex
.PHONY: help clean verilator