-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathMakefile
114 lines (96 loc) · 3.21 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
110
111
112
113
114
# 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
# All sources and test sources
SRCS = $(wildcard $(SCALADIR)/*/*.scala)
TESTS = $(wildcard $(TESTDIR)/*/*.scala)
# Directories
HWBUILDDIR = $(CURDIR)/build
DIRS = $(SCALADIR) $(TESTDIR) $(HWBUILDDIR) $(GENERATED)
# Targets for verilog and testing
MAINTARGET ?= PentaFive
TESTTARGET ?= PentaFiveSpec
WAVETARGET ?= $(CURDIR)/test_run_dir/PentaFive_should_pass/PentaFive.vcd
WAVECONFIG ?= # Use a config file to configure gtkwave
DIAGRAMTARGET ?= $(CURDIR)/build/PentaFive.fir
DIAGRAMMERDIR ?=
.PHONY: all
all: run test
# 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)"
# Create program txt file from C source
.PHONY: asm
comp:
@echo "Compiling to raw machine code"
riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c main.c -o main.o
riscv64-unknown-elf-objdump -D --show-raw-insn main.o
riscv64-unknown-elf-objcopy -O binary main.o main.bin
hexdump -v -e '1/4 "%08x "' -e '"\n"' main.bin > program.txt
# Create program txt file
.PHONY: asm
asm:
@echo "Assembing to raw machine code"
riscv64-unknown-elf-gcc -march=rv32i -mabi=ilp32 -c program.s -o program.o
riscv64-unknown-elf-objdump -d --section=".text" --start-address=0x0 --show-raw-insn program.o
riscv64-unknown-elf-objcopy -O binary program.o program.bin
hexdump -v -e '1/4 "%08x "' -e '"\n"' program.bin > program.txt
# View waveform in GTKWave
.PHONY: wave
wave:
if [ ! -f $(WAVETARGET) ]; then $(MAKE) test; fi # TODO make depend on TESTTARGET
$(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)
# 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)