abstractaccelerator/demo/helloworld/Makefile

96 lines
3.2 KiB
Makefile

export RV_ROOT = ${PWD}/../..
LLVMINSTALL = /home/colin/develop/llvm-build/install
GCC_PREFIX = /opt/riscv/bin/riscv64-unknown-elf
TEST_CFLAGS = -g -O3 -funroll-all-loops
ABI = -mabi=ilp32 -march=rv32imc
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
OFILES = $(TEST).o
OUTFILES = $(TEST).out
# 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 #####################################
defines = $(BUILD_DIR)/common_defines.vh ${RV_DESIGN}/include/swerv_types.sv
includes = -I${RV_DESIGN}/include -I${BUILD_DIR} -I${RV_SOC}
verilator-build: swerv_define
echo '`undef ASSERT_ON' >> ${BUILD_DIR}/common_defines.vh
verilator --cc -CFLAGS ${CFLAGS} \
$(defines) \
$(includes) \
-Wno-UNOPTFLAT \
-f ${RV_SOC}/flist \
$(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: $(OFILES) $(LINK)
# @echo Building $(TEST)
# $(GCC_PREFIX)-gcc $(ABI) -Wl,-Map=$(BUILD_DIR)/$(TEST).map -lgcc -T$(LINK) -o $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/$(OFILES) -nostartfiles $(TEST_LIBS)
# $(GCC_PREFIX)-objcopy -O verilog $(BUILD_DIR)/$(TEST).bin $(BUILD_DIR)/program.hex
# $(GCC_PREFIX)-objdump -S $(BUILD_DIR)/$(TEST).bin > $(BUILD_DIR)/$(TEST).dis
# @echo Completed building $(TEST)
# %.o : %.s swerv_define
# $(GCC_PREFIX)-cpp -I${BUILD_DIR} $< > $(BUILD_DIR)/$*.cpp.s
# $(GCC_PREFIX)-as $(ABI) $(BUILD_DIR)/$*.cpp.s -o $(BUILD_DIR)/$@
program.hex: $(OUTFILES)
@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
##################### llvm hex Build #####################################
build: $(OUTFILES)
@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