-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
109 lines (90 loc) · 2.76 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
# Import config file for user specific compiling and testing
-include config.mk
SBT = sbt
GTKWAVE ?= gtkwave
SRCDIR = $(CURDIR)/src
SCALADIR = $(SRCDIR)/main/scala
TESTDIR = $(SRCDIR)/test/scala
QUARTUSDIR = $(CURDIR)/quartus
# All sources and test sources
SRCS = $(shell find $(SCALADIR) -type f -name '*.scala')
TESTS = $(shell find $(TESTDIR) -type f -name '*.scala')
# Directories
HWBUILDDIR = $(CURDIR)/build
DIRS = $(SCALADIR) $(TESTDIR) $(HWBUILDDIR) $(GENERATED)
# Targets for verilog and testing
MAINTARGET ?= Main
TESTTARGET ?= Top
WAVETARGET ?= $(CURDIR)/
WAVECONFIG ?= # Use a config file to configure gtkwave
DIAGRAMTARGET ?= $(CURDIR)/build/Top.fir
DIAGRAMMERDIR ?=
.PHONY: all
all: run
# Run main target
.PHONY: run
run: $(SRCS) dirs
$(SBT) "runMain $(MAINTARGET) --target-dir $(HWBUILDDIR)"
# Run all tests
.PHONY: testall
testall: $(SRCS) $(TESTS)
$(SBT) test
# Run specific test
.PHONY: test
test: $(SRCS) $(TESTS)
$(SBT) "testOnly $(TESTTARGET)"
# Build and program FPGA
.PHONY: program
program: run
$(MAKE) -C $(QUARTUSDIR)
# Program FPGA without building
.PHONY: flash
flash:
$(MAKE) -C $(QUARTUSDIR) flash
# View waveform in GTKWave
.PHONY: wave
wave: test $(WAVETARGET)
#if [ ! -f $(WAVETARGET) ]; then $(MAKE) test; fi # TODO make depend on TESTTARGET
sed -ri 's/timescale .../timescale 10ns/g' $(WAVETARGET)
$(GTKWAVE) $(WAVETARGET) $(WAVECONFIG) &
# Create directories if they don't exist
.PHONY: dirs
dirs:
@echo "Creating directories"
@for d in $(DIRS) ; do \
mkdir -p $$d ; \
done
# Create diagram using diagrammer
.PHONY: diagram
diagram:
if [ ! -f $(DIAGRAMTARGET) ]; then $(MAKE) run; fi # TODO make depend on DIAGRAMTARGET
cd $(DIAGRAMMERDIR); ./diagram.sh -i $(DIAGRAMTARGET) --target-dir $(HWBUILDDIR) --open-command xdg-open
# Cleanup working directory
.PHONY: clean
clean:
@echo "Cleaning workspace"
$(RM) -r *.v *.fir *.anno.json test_run_dir $(HWBUILDDIR) target project/target *.o *.bin *.txt
# Cleanup working directory included configuration files
.PHONY: veryclean
veryclean: clean
$(RM) -r project/.bloop project/project project/metals.sbt .bloop .bsp .idea .metals .vscode
# Show variables for debugging
.PHONY: show
show:
@echo 'MAKE :' $(MAKE)
@echo 'CURDIR :' $(CURDIR)
@echo 'SBT :' $(SBT)
@echo 'SRCDIR :' $(SRCDIR)
@echo 'SCALADIR :' $(SCALADIR)
@echo 'TESTDIR :' $(TESTDIR)
@echo 'SRCS :' $(SRCS)
@echo 'TESTS :' $(TESTS)
@echo 'HWBUILDDIR :' $(HWBUILDDIR)
@echo 'DIRS :' $(DIRS)
@echo 'MAINTARGET :' $(MAINTARGET)
@echo 'TESTTARGET :' $(TESTTARGET)
@echo 'WAVETARGET :' $(WAVETARGET)
@echo 'WAVECONFIG :' $(WAVECONFIG)
@echo 'GTKWAVE :' $(GTKWAVE)
@echo 'DIAGRAMMERDIR :' $(DIAGRAMMERDIR)
@echo 'DIAGRAMTARGET :' $(DIAGRAMTARGET)