aboutsummaryrefslogtreecommitdiff
path: root/sim/makefile
blob: 7404189069ba780e5cb59acf1a6d83e6c9a40cce (plain)
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
## ----------------------------------------------------------------------------
## Script     : makefile
## ----------------------------------------------------------------------------
## Author(s)  : Johann Faerber, Friedrich Beckmann
## Company    : University of Applied Sciences Augsburg
## ----------------------------------------------------------------------------
## Description: This makefile allows automating design flow with ModelSim,
##              it is based on a design directory structure shown at 
##              the end of this file.
## ----------------------------------------------------------------------------

GHDL_CMD = ghdl
GHDL_OPTIONS  = --std=08 --workdir=work
LOG_FILE = ghdl.log

ECHO_TARGET := echo "$$@"  >> $(LOG_FILE) 2>&1
TIME_STAMP := echo "$$@ $$(date --iso=seconds)"
TIME_STAMP_LOG_FILE := echo "$$@ $$(date --iso=seconds)" >> $(LOG_FILE) 2>&1

###################################################################
# Main Targets
#
###################################################################

#==== Default target - running simulation without drawing waveforms ====#
.PHONY : sim
sim : t_$(PROJECT).ghw

#==== WAVEFORM DRAWING ====#
.PHONY : wave
wave : t_$(PROJECT).ghw
	@gtkwave t_$(PROJECT).ghw view_signals.gtkw >/dev/null 2>&1 &

#==== SIMULATION ====#
t_$(PROJECT).ghw : .compile.done
	$(GHDL_CMD) --synth --out=none $(GHDL_OPTIONS) $(PROJECT)
	# If ghdl exits with an error code, remove the .ghw file
	$(GHDL_CMD) -r $(GHDL_OPTIONS) t_$(PROJECT) --wave=t_$(PROJECT).ghw \
	  || (rm -f t_$(PROJECT).ghw; exit 1)

#==== COMPILATION ====#
compile : .compile.done

.compile.done : $(SOURCE_FILES) .gproject.done
	$(GHDL_CMD) -m $(GHDL_OPTIONS) --warn-default-binding t_$(PROJECT)
	touch .compile.done

#==== PROJECT CREATION ====#
gproject : .gproject.done

.gproject.done : makefile.sources
	# Create a directory work if it does not exist. Otherwise do nothing.
	[ -d work ] || mkdir -p work
	$(GHDL_CMD) -i $(GHDL_OPTIONS) $(SOURCE_FILES)
	touch .gproject.done

#==== Synthesis Check ====#
synthcheck : .compile.done
	@echo "---- $@"  >> $(LOG_FILE) 2>&1
	@$(TIME_STAMP_LOG_FILE)
	@echo "Synthesis Check ..."  >> $(LOG_FILE) 2>&1
	$(GHDL_CMD) --synth --out=none $(GHDL_OPTIONS) $(PROJECT) 2>&1 | tee -a $(LOG_FILE)
	@$(TIME_STAMP) > .synth.done

warnings: $(LOG_FILE)
	@echo "---- $@"  >> $(LOG_FILE) 2>&1
	@$(TIME_STAMP_LOG_FILE)
	@grep "Warning (" $(LOG_FILE)

.PHONY : clean
clean:
	@$(GHDL_CMD) --remove; rm -rf work*.cf work *.vcd *.ghw *.log ghdl_sources.tcl .gproject.done .compile.done .sim.done .synth.done

help:
	@echo 'Default target is sim'
	@echo '  "make gproject" to create a new ghdl project only'
	@echo '  "make compile" to compile all VHDL sources in batch mode'
	@echo '  "make sim" to run ghdl with the top testbench of the project'
	@echo '  "make wave" to display the simulation results in the time domain'
	@echo '  "make clean" to remove all generated files'