2024-01-01 05:29:52 +00:00
|
|
|
NVBOARD_HOME ?= $(abspath ../nvboard)
|
2023-12-23 11:41:15 +00:00
|
|
|
PREFIX ?= build
|
2024-01-04 09:23:05 +00:00
|
|
|
CHISEL_VDIR := $(PREFIX)/chisel
|
2024-01-01 05:29:52 +00:00
|
|
|
|
|
|
|
CPPSRCS := $(addprefix $(PWD)/,$(wildcard csrc/*.cpp))
|
|
|
|
|
2023-12-23 12:10:23 +00:00
|
|
|
VERILATOR_FLAGS := --cc --exe
|
2024-01-01 05:29:52 +00:00
|
|
|
LDFLAGS += $(shell sdl2-config --libs) -lSDL2_image
|
2023-12-23 09:27:29 +00:00
|
|
|
|
2024-01-04 09:23:05 +00:00
|
|
|
CHISEL_TOP_PACKAGE := learning
|
|
|
|
CHISEL_TOP_MODULE := Main
|
|
|
|
CHISEL_TARGET := verilog
|
|
|
|
|
2024-01-04 16:05:11 +00:00
|
|
|
SUBDIRS := obj nvobj
|
|
|
|
SUBDIRS := $(addprefix $(PREFIX),$(SUBDIRS))
|
|
|
|
|
|
|
|
SUBMAKE := $(OBJDIR)/V$(CHISEL_TOP_MODULE).mk
|
2024-01-04 09:26:20 +00:00
|
|
|
|
2024-01-04 09:23:05 +00:00
|
|
|
# Pretty printing
|
|
|
|
MAKEFLAGS += --no-print-directory
|
2024-01-04 09:27:48 +00:00
|
|
|
GREEN := \e[32m
|
|
|
|
NC := \e[0m
|
2024-01-04 09:23:05 +00:00
|
|
|
define colorize
|
|
|
|
printf '$(GREEN)'$(1)'$(NC) $(2)\n'
|
|
|
|
endef
|
|
|
|
|
2024-01-01 06:36:38 +00:00
|
|
|
all: sim-bin nvboard-bin
|
2024-01-04 09:24:30 +00:00
|
|
|
|
2024-01-04 16:05:11 +00:00
|
|
|
$(SUBDIRS):%: %/V$(CHISEL_TOP_MODULE).mk
|
|
|
|
verilator $(VERILATOR_FLAGS) $(addprefix -CFLAGS , $(CXXFLAGS)) $(addprefix -LDFLAGS , $(LDFLAGS)) --Mdir $(abspath $(OBJDIR)) $(CHISEL_VSRC) $(CPPSRCS)
|
2023-12-23 10:28:18 +00:00
|
|
|
|
2024-01-04 09:23:05 +00:00
|
|
|
$(OBJDIR)/V$(CHISEL_TOP_MODULE): $(SUBMAKE)
|
|
|
|
@$(call colorize,"SUBMAKE",$^)
|
2024-01-04 16:05:11 +00:00
|
|
|
$(MAKE) -s -C $(dir $@) -f $< $(notdir $@)
|
2024-01-01 05:56:48 +00:00
|
|
|
|
2024-01-04 09:23:05 +00:00
|
|
|
$(SUBMAKE): $(CPPSRCS) $(OBJDIR) chisel-src
|
2024-01-04 16:05:11 +00:00
|
|
|
@$(call colorize,"VERILATOR",$@)
|
2024-01-04 09:23:05 +00:00
|
|
|
verilator $(VERILATOR_FLAGS) $(addprefix -CFLAGS , $(CXXFLAGS)) $(addprefix -LDFLAGS , $(LDFLAGS)) --Mdir $(abspath $(OBJDIR)) $(CHISEL_VSRC) $(CPPSRCS)
|
2023-12-23 09:27:29 +00:00
|
|
|
|
2024-01-01 06:23:04 +00:00
|
|
|
$(OBJDIR):
|
2024-01-04 16:05:11 +00:00
|
|
|
mkdir -p $@
|
2024-01-01 06:23:04 +00:00
|
|
|
|
2024-01-04 09:23:05 +00:00
|
|
|
$(CHISEL_VDIR)/filelist.f: $(wildcard src/main/scala/*.scala)
|
|
|
|
@$(call colorize,"CIRCT",$^)
|
|
|
|
sbt --error "runMain circt.stage.ChiselMain --module $(CHISEL_TOP_PACKAGE).$(CHISEL_TOP_MODULE) --split-verilog --target $(CHISEL_TARGET) -td $(CHISEL_VDIR)"
|
2024-01-01 05:42:14 +00:00
|
|
|
|
2024-01-04 09:23:05 +00:00
|
|
|
compile_commands.json: clean
|
|
|
|
$(MAKE) $(CHISEL_VDIR)/filelist.f
|
|
|
|
$(RM) compile_commands.json
|
|
|
|
bear --append -- $(MAKE) nvboard-bin
|
|
|
|
bear --append -- $(MAKE) sim-bin
|
|
|
|
|
|
|
|
.PHONY: clean nvboard sim nvboard-bin sim-bin git_trace_sim git_trace_nvboard
|
|
|
|
|
2024-01-04 16:05:11 +00:00
|
|
|
SRC_AUTO_BIND := $(abspath $(PREFIX)/auto_bind.cpp)
|
|
|
|
NXDC_FILES := $(abspath constr/top.nxdc)
|
|
|
|
$(SRC_AUTO_BIND): $(NXDC_FILES)
|
|
|
|
NVBOARD_HOME=$(NVBOARD_HOME) python3 $(NVBOARD_HOME)/scripts/auto_pin_bind.py $< $@
|
2024-01-04 09:32:22 +00:00
|
|
|
|
2024-01-04 16:05:11 +00:00
|
|
|
nvboard-bin: OBJDIR := $(PREFIX)/nvobj
|
|
|
|
nvboard-bin: SUBMAKE := $(OBJDIR)/V$(CHISEL_TOP_MODULE).mk
|
|
|
|
# TODO: fix this awkward way to find nvboard.a
|
|
|
|
nvboard-bin: CPPSRCS := $(addprefix $(PWD)/,$(wildcard csrc_nvboard/*.cpp)) $(SRC_AUTO_BIND) $(NVBOARD_HOME)/build/nvboard.a
|
|
|
|
nvboard-bin: CXXFLAGS += -I$(NVBOARD_HOME)/include $(shell sdl2-config --cflags)
|
|
|
|
nvboard-bin: $(CPPSRCS) $(SUBMAKE) $(SRC_AUTO_BIND) $(OBJDIR)/V$(CHISEL_TOP_MODULE)
|
|
|
|
@echo $(SUBMAKE) $(OBJDIR)
|
2024-01-04 09:26:20 +00:00
|
|
|
|
2024-01-04 09:23:05 +00:00
|
|
|
sim-bin: VERILATOR_FLAGS += --trace
|
|
|
|
sim-bin: $(CPPSRCS) $(OBJDIR)/V$(CHISEL_TOP_MODULE)
|
|
|
|
|
|
|
|
chisel-src: $(CHISEL_VDIR)/filelist.f
|
|
|
|
$(eval CHISEL_VSRC := $(wildcard $(CHISEL_VDIR)/*.sv))
|
|
|
|
@echo "GENERATED: $(CHISEL_VSRC)"
|
2024-01-01 06:36:38 +00:00
|
|
|
|
|
|
|
ifneq (,$(wildcard ../Makefile))
|
|
|
|
include ../Makefile
|
|
|
|
else
|
|
|
|
define git_commit # not in ICS subfolder, no tracing
|
|
|
|
endef
|
|
|
|
endif
|
|
|
|
|
|
|
|
git_trace_sim:
|
|
|
|
$(call git_commit, "sim RTL")
|
|
|
|
|
|
|
|
git_trace_nvboard:
|
|
|
|
$(call git_commit, "nvboard")
|
|
|
|
|
2024-01-02 16:35:10 +00:00
|
|
|
nvboard: OBJDIR := $(PREFIX)/nvobj
|
2024-01-01 06:36:38 +00:00
|
|
|
nvboard: nvboard-bin git_trace_nvboard
|
2024-01-04 09:24:30 +00:00
|
|
|
@echo "Running NVBoard ..."
|
|
|
|
@echo "================================"
|
2024-01-04 09:23:05 +00:00
|
|
|
@NVBOARD_HOME=$(NVBOARD_HOME) $(OBJDIR)/V$(CHISEL_TOP_MODULE)
|
2023-12-23 09:33:39 +00:00
|
|
|
|
2024-01-01 06:36:38 +00:00
|
|
|
sim: sim-bin git_trace_sim
|
2024-01-04 09:23:05 +00:00
|
|
|
@echo "Running verilator sim ..."
|
2024-01-01 06:36:38 +00:00
|
|
|
@echo "================================"
|
2024-01-04 09:23:05 +00:00
|
|
|
@$(OBJDIR)/V$(CHISEL_TOP_MODULE)
|
2024-01-01 06:20:04 +00:00
|
|
|
|
2023-12-23 09:33:39 +00:00
|
|
|
clean:
|
2024-01-01 05:29:52 +00:00
|
|
|
$(RM) -r $(PREFIX)
|
2024-01-04 09:23:05 +00:00
|
|
|
|
|
|
|
$(V).SILENT:
|