example: refactor Makefile

This commit is contained in:
Zihao Yu 2022-02-20 15:00:18 +08:00
parent d340dc726e
commit bd740d9613
13 changed files with 61 additions and 69 deletions

5
.gitignore vendored
View File

@ -7,4 +7,7 @@
!LICENSE
!README.md
!README.en.md
!board/*
!board/*
!*.v
!*.cpp
build/

View File

@ -1,51 +0,0 @@
VERILATOR = verilator
VERILATOR_CFLAGS += -MMD -Wall --build -cc -Wno-lint \
-O3 --x-assign fast --x-initial fast --noassert
# include path
INC_PATH ?=
# files of the RTL project
TOPNAME ?= top
DIR ?= $(NVBOARD_HOME)/example
OBJ_DIR = $(DIR)/obj_dir
# generated executable file
DST_EXE = NVBOARD_$(TOPNAME)
DST_BIN = $(OBJ_DIR)/$(DST_EXE)
# SRC of the project
SRC_DIR ?= $(DIR)/src
SRCS ?= $(shell find $(SRC_DIR) -name "*.v" -or -name "*.c" -or -name "*.cc" -or -name "*.cpp")
### Default rules...
# Build rules of nvboard
include $(NVBOARD_HOME)/scripts/nvboard.mk
INCFLAGS = $(addprefix -I, $(INC_PATH))
CFLAGS += $(INCFLAGS) -DTOP_NAME="\"V$(TOPNAME)\""
LDFLAGS += -lSDL2 -lSDL2_image
$(DST_BIN): $(SRCS) $(NBD_ARCHIVE)
@rm -rf $(OBJ_DIR)
@echo $(INC_PATH)
@$(VERILATOR) $(VERILATOR_CFLAGS) \
-top $(TOPNAME) $^ \
$(addprefix -CFLAGS , $(CFLAGS)) $(addprefix -LDFLAGS , $(LDFLAGS)) \
--Mdir $(OBJ_DIR) --exe -o $(DST_EXE)
NXDC_FILES ?= $(shell find $(SRC_DIR) -name "*.nxdc")
nxdc: $(NXDC_FILES)
python $(NVBOARD_HOME)/scripts/auto_pin_bind.py $(NXDC_FILES)
run: $(DST_BIN) nxdc
@$(DST_BIN)
clean:
rm -rf $(OBJ_DIR)
.PHONY: clean run nxdc

6
example/.gitignore vendored
View File

@ -1,4 +1,2 @@
!src/*
!Makefile
!makefile
auto_bind.cpp
!resource/*.hex
!constr/*.nxdc

View File

@ -1,13 +1,50 @@
# 需要手动指定项目目录
DIR = .
## 默认项目源码在项目目录的src文件夹下可手动指定
### SRC_DIR ?= $(DIR)/src
## 参与verilator编译的文件默认为$(SRC_DIR)下的所有*.v, *.c, *.cc, *.cpp文件可手动指定
### SRCS ?= $(shell find $(SRC_DIR) -name "*.v" -or -name "*.c" -or -name "*.cc" -or -name "*.cpp")
# 需要指定顶层模块名称
TOPNAME = top
NXDC_FILES = constr/top.nxdc
INC_PATH ?=
# 需要在最后将NVBOARD的makefile包含进来
-include $(NVBOARD_HOME)/Makefile
VERILATOR = verilator
VERILATOR_CFLAGS += -MMD -Wall --build -cc -Wno-lint \
-O3 --x-assign fast --x-initial fast --noassert
BUILD_DIR = ./build
OBJ_DIR = $(BUILD_DIR)/obj_dir
BIN = $(BUILD_DIR)/$(TOPNAME)
default: $(BIN)
$(shell mkdir -p $(BUILD_DIR))
# contraint file
SRC_AUTO_BIND = $(abspath $(BUILD_DIR)/auto_bind.cpp)
$(SRC_AUTO_BIND): $(NXDC_FILES)
python $(NVBOARD_HOME)/scripts/auto_pin_bind.py $^ $@
# project source
VSRCS = $(shell find $(abspath ./vsrc) -name "*.v")
CSRCS = $(shell find $(abspath ./csrc) -name "*.c" -or -name "*.cc" -or -name "*.cpp")
CSRCS += $(SRC_AUTO_BIND)
# rules for NVBoard
include $(NVBOARD_HOME)/scripts/nvboard.mk
# rules for verilator
INCFLAGS = $(addprefix -I, $(INC_PATH))
CFLAGS += $(INCFLAGS) -DTOP_NAME="\"V$(TOPNAME)\""
LDFLAGS += -lSDL2 -lSDL2_image
$(BIN): $(VSRCS) $(CSRCS) $(NBD_ARCHIVE)
@rm -rf $(OBJ_DIR)
$(VERILATOR) $(VERILATOR_CFLAGS) \
-top $(TOPNAME) $^ \
$(addprefix -CFLAGS , $(CFLAGS)) $(addprefix -LDFLAGS , $(LDFLAGS)) \
--Mdir $(OBJ_DIR) --exe -o $(abspath $(BIN))
run: $(BIN)
@$^
clean:
rm -rf $(BUILD_DIR)
.PHONY: clean run

View File

@ -86,7 +86,7 @@ module vmem (
reg [23:0] vga_mem [524287:0];
initial begin
$readmemh("src/picture.hex", vga_mem);
$readmemh("resource/picture.hex", vga_mem);
end
assign vga_data = vga_mem[{h_addr, v_addr}];

View File

@ -89,9 +89,14 @@ if len(sys.argv) <= 1:
exit(-1)
cons_path = sys.argv[1]
if len(sys.argv) <= 2:
print("output file missing!")
exit(-1)
output_path = sys.argv[2]
cons_f = open(cons_path, "r")
bind_f = open('src/auto_bind.cpp', "w")
bind_f = open(output_path, "w")
line = cons_f.readline()
line = line.split('=')