From bd740d96130af1df6deffc3539c8356ba2442177 Mon Sep 17 00:00:00 2001 From: Zihao Yu Date: Sun, 20 Feb 2022 15:00:18 +0800 Subject: [PATCH] example: refactor Makefile --- .gitignore | 5 ++- Makefile | 51 ----------------------- example/.gitignore | 6 +-- example/Makefile | 59 ++++++++++++++++++++++----- example/{src => constr}/top.nxdc | 0 example/{src => csrc}/main.cpp | 0 example/{src => resource}/picture.hex | 0 example/{src => vsrc}/led.v | 0 example/{src => vsrc}/ps2_keyboard.v | 0 example/{src => vsrc}/seg.v | 0 example/{src => vsrc}/top.v | 2 +- example/{src => vsrc}/vga_ctrl.v | 0 scripts/auto_pin_bind.py | 7 +++- 13 files changed, 61 insertions(+), 69 deletions(-) delete mode 100644 Makefile rename example/{src => constr}/top.nxdc (100%) rename example/{src => csrc}/main.cpp (100%) rename example/{src => resource}/picture.hex (100%) rename example/{src => vsrc}/led.v (100%) rename example/{src => vsrc}/ps2_keyboard.v (100%) rename example/{src => vsrc}/seg.v (100%) rename example/{src => vsrc}/top.v (96%) rename example/{src => vsrc}/vga_ctrl.v (100%) diff --git a/.gitignore b/.gitignore index 941b5f4..0c7970f 100644 --- a/.gitignore +++ b/.gitignore @@ -7,4 +7,7 @@ !LICENSE !README.md !README.en.md -!board/* \ No newline at end of file +!board/* +!*.v +!*.cpp +build/ diff --git a/Makefile b/Makefile deleted file mode 100644 index 2f2fe42..0000000 --- a/Makefile +++ /dev/null @@ -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 diff --git a/example/.gitignore b/example/.gitignore index f73d982..6b588b6 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -1,4 +1,2 @@ -!src/* -!Makefile -!makefile -auto_bind.cpp \ No newline at end of file +!resource/*.hex +!constr/*.nxdc diff --git a/example/Makefile b/example/Makefile index c434847..52c4058 100644 --- a/example/Makefile +++ b/example/Makefile @@ -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 diff --git a/example/src/top.nxdc b/example/constr/top.nxdc similarity index 100% rename from example/src/top.nxdc rename to example/constr/top.nxdc diff --git a/example/src/main.cpp b/example/csrc/main.cpp similarity index 100% rename from example/src/main.cpp rename to example/csrc/main.cpp diff --git a/example/src/picture.hex b/example/resource/picture.hex similarity index 100% rename from example/src/picture.hex rename to example/resource/picture.hex diff --git a/example/src/led.v b/example/vsrc/led.v similarity index 100% rename from example/src/led.v rename to example/vsrc/led.v diff --git a/example/src/ps2_keyboard.v b/example/vsrc/ps2_keyboard.v similarity index 100% rename from example/src/ps2_keyboard.v rename to example/vsrc/ps2_keyboard.v diff --git a/example/src/seg.v b/example/vsrc/seg.v similarity index 100% rename from example/src/seg.v rename to example/vsrc/seg.v diff --git a/example/src/top.v b/example/vsrc/top.v similarity index 96% rename from example/src/top.v rename to example/vsrc/top.v index a6cd50a..d474e7c 100644 --- a/example/src/top.v +++ b/example/vsrc/top.v @@ -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}]; diff --git a/example/src/vga_ctrl.v b/example/vsrc/vga_ctrl.v similarity index 100% rename from example/src/vga_ctrl.v rename to example/vsrc/vga_ctrl.v diff --git a/scripts/auto_pin_bind.py b/scripts/auto_pin_bind.py index 180d961..fc03146 100644 --- a/scripts/auto_pin_bind.py +++ b/scripts/auto_pin_bind.py @@ -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('=')