-
Notifications
You must be signed in to change notification settings - Fork 0
/
Makefile
83 lines (62 loc) · 2.08 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
# Flag to indicate wether we are in debug mode or not
DEBUG ?= 1
# Default max simulation time
SIMTIME ?= 100ns
# VHDL compiler
GHDL = ghdl
# Wave simulator
ifeq ($(shell uname -s), Linux)
WAVE = gtkwave
else
# macOS support for gtkwave
WAVE = open -a gtkwave
endif
# Source code directory
SRC = src
# Test bench directory
TB = tb
# Simulation file directory
SIMU = simu
# Directory containing all build files
BUILD = build
# Set error exit code according to the DEBUG flag
# Set maximum tolerance assertion level (errors will be triggered for this error type & above)
ifeq ($(DEBUG), 1)
ERROREXIT = 0
ASSERTLVL = error
else
ERROREXIT = 1
ASSERTLVL = warning
endif
# Source VHDL files
SOURCES = $(wildcard $(SRC)/*.vhdl)
TARGETS = $(patsubst $(SRC)/%.vhdl, %, $(SOURCES))
# Simulation files
SIMULATIONS = $(wildcard $(SIMU)/*.vcd)
all: builddir $(TARGETS)
# Dependencies
ProcessingUnit: RegisterBank SignExtension MUX ALU DataMemory
IMU: SignExtension InstructionMemory
# IP with test bench
%: $(SRC)/%.vhdl $(TB)/%_tb.vhdl
@echo "\033[0;33m[Compiling \`$@.vhdl\` & \`$@_tb.vhdl\` ...]\033[0m"
$(GHDL) -s --workdir=$(BUILD) $(SRC)/$@.vhdl $(TB)/$@_tb.vhdl
$(GHDL) -a --workdir=$(BUILD) $(SRC)/$@.vhdl $(TB)/$@_tb.vhdl
$(GHDL) -e --workdir=$(BUILD) -o $(BUILD)/$@_tb $@_tb
@echo "\033[0;33m[Running simulation of \`$@_tb\` ...]\033[0m"
# Some versions of GHDL produce executables (in $(BUILD)/) and some do not, hence the first two parts of this command
@./$(BUILD)/$@_tb --vcd=$(SIMU)/$@.vcd --assert-level=$(ASSERTLVL) --stop-time=$(SIMTIME) 2> /dev/null || \
$(GHDL) -r --workdir=$(BUILD) $@_tb --vcd=$(SIMU)/$@.vcd --assert-level=$(ASSERTLVL) --stop-time=$(SIMTIME) && \
echo "\033[0;32m[\`$@\` PASS]\033[0m" || (echo "\033[0;31m[\`$@\` FAIL]\033[0m"; exit $(ERROREXIT))
# IP without test bench
%: $(SRC)/%.vhdl
@echo "\033[0;33m[Compiling \`$@.vhdl\` ...]\033[0m"
$(GHDL) -s --workdir=$(BUILD) $(SRC)/$@.vhdl
$(GHDL) -a --workdir=$(BUILD) $(SRC)/$@.vhdl
builddir:
@mkdir -p $(BUILD)/
simu:
$(WAVE) $(SIMULATIONS)
clean:
rm -rf $(BUILD)/ $(SIMU)/*.vcd
.PHONY: all builddir simu clean