Debian Codegraph @

src/cocotb_tools/makefiles/Makefile.inc

raw
1 # Copyright cocotb contributors
2 # Copyright (c) 2013 Potential Ventures Ltd
3 # Copyright (c) 2013 SolarFlare Communications Inc
4 # Licensed under the Revised BSD License, see LICENSE for details.
5 # SPDX-License-Identifier: BSD-3-Clause
6
7 # Common makefile included by everything
8
9 ifndef COCOTB_MAKEFILE_INC_INCLUDED # Protect against multiple includes
10 COCOTB_MAKEFILE_INC_INCLUDED = 1
11
12 # Default sim rule will force a re-run of the simulation (though the cocotb library
13 # and RTL compilation phases are still evaluated by makefile dependencies)
14 .PHONY: sim
15 sim:
16 $(RM) $(COCOTB_RESULTS_FILE)
17 "$(MAKE)" -f $(firstword $(MAKEFILE_LIST)) $(COCOTB_RESULTS_FILE)
18
19 # Make sure to use bash for the pipefail option used in many simulator Makefiles
20 SHELL := bash
21
22 OS=$(shell uname)
23 ifneq (, $(findstring MINGW, $(OS)))
24 OS := Msys
25 else ifneq (, $(findstring MSYS, $(OS)))
26 OS := Msys
27 endif
28 export OS
29
30 export PYGPI_PYTHON_BIN := $(shell $(PYTHON_BIN) -m cocotb_tools.config --python-bin)
31
32 # Directory containing the cocotb Makefiles
33 COCOTB_MAKEFILES_DIR := $(shell $(PYTHON_BIN) -m cocotb_tools.config --makefiles)
34
35 include $(COCOTB_MAKEFILES_DIR)/Makefile.deprecations
36
37 PYTHON_ARCH := $(shell $(PYTHON_BIN) -c 'from platform import architecture; print(architecture()[0])')
38 ifeq ($(filter $(PYTHON_ARCH),64bit 32bit),)
39 $(error Unknown Python architecture: $(PYTHON_ARCH))
40 endif
41
42 ifeq ($(OS),Msys)
43 to_tcl_path = $(shell cygpath -m $(1) )
44 else
45 to_tcl_path = $(1)
46 endif
47
48 # Check that the COCOTB_RESULTS_FILE was created, since we can't set an exit code from cocotb.
49 define check_for_results_file
50 @test -f $(COCOTB_RESULTS_FILE) || (echo "ERROR: $(COCOTB_RESULTS_FILE) was not written by the simulation!" >&2 && exit 1)
51 endef
52
53 # Check that the COCOTB_RESULTS_FILE was created and has no failures
54 define check_results
55 @$(PYTHON_BIN) -m cocotb_tools.check_results $(COCOTB_RESULTS_FILE)
56 endef
57
58 SIM_BUILD ?= sim_build
59 export SIM_BUILD
60
61 COCOTB_RESULTS_FILE ?= results.xml
62 COCOTB_HDL_TIMEUNIT ?= 1ns
63 COCOTB_HDL_TIMEPRECISION ?= 1ps
64
65 export COCOTB_RESULTS_FILE
66
67
68 $(SIM_BUILD):
69 mkdir -p $@
70
71 # Regression rule uses Make dependencies to determine whether to run the simulation
72 .PHONY: regression
73 regression: $(COCOTB_RESULTS_FILE)
74
75 # Attempt to detect TOPLEVEL_LANG based on available sources if not set
76 ifeq ($(TOPLEVEL_LANG),)
77
78 ifneq ($(VHDL_SOURCES),)
79 ifeq ($(VERILOG_SOURCES),)
80 TOPLEVEL_LANG := vhdl
81 endif
82 else ifneq ($(VERILOG_SOURCES),)
83 ifeq ($(VHDL_SOURCES),)
84 TOPLEVEL_LANG := verilog
85 endif
86 endif
87
88 endif
89
90 define find_libpython_errmsg =
91
92
93 find_libpython was not able to find a libpython in the current Python environment. Ensure
94 the Python development packages are installed. If they are installed and find_libpython
95 is not finding the path to libpython, file an upstream bug in find_libpython; then
96 manually override the LIBPYTHON_LOC make variable with the absolute path to libpython.so
97 (or python.dll on Windows).
98
99 endef
100
101 ifndef LIBPYTHON_LOC
102
103 # get the path to libpython and the return code from the script
104 # adapted from https://stackoverflow.com/a/24658961/6614127
105 FIND_LIBPYTHON_RES := $(shell $(PYTHON_BIN) -m cocotb_tools.config --libpython; echo $$?)
106 FIND_LIBPYTHON_RC := $(lastword $(FIND_LIBPYTHON_RES))
107 LIBPYTHON_LOC := $(strip $(subst $(FIND_LIBPYTHON_RC)QQQQ,,$(FIND_LIBPYTHON_RES)QQQQ))
108
109 # complain if libpython isn't found, and export otherwise
110 ifneq ($(FIND_LIBPYTHON_RC),0)
111 $(error $(find_libpython_errmsg))
112 endif
113
114 endif
115
116 export LIBPYTHON_LOC
117
118 define check_vhdl_sources
119 if [ "$(VHDL_SOURCES_$(LIB))" == "" ]; then \
120 >&2 echo "ERROR: VHDL_SOURCES_$(LIB) is empty or undefined, but '$(LIB)' is present in VHDL_LIB_ORDER."; \
121 exit 1; \
122 fi;
123 endef
124
125 define check_lib_order
126 if [ "$(filter $(SOURCES_VAR:VHDL_SOURCES_%=%), $(VHDL_LIB_ORDER))" == "" ]; then \
127 >&2 echo "ERROR: $(SOURCES_VAR) defined, but library $(SOURCES_VAR:VHDL_SOURCES_%=%) not present in VHDL_LIB_ORDER."; \
128 exit 1; \
129 fi;
130 endef
131
132 # NOTE: if the following simulator list is modified, update the sentence
133 # "This flag is enabled by default for the GHDL, NVC and Verilator simulators."
134 # in docs/source/building.rst accordingly.
135 ifneq ($(filter $(SIM),nvc ghdl verilator),)
136 COCOTB_TRUST_INERTIAL_WRITES ?= 1
137 else
138 COCOTB_TRUST_INERTIAL_WRITES ?= 0
139 endif
140
141 export COCOTB_TRUST_INERTIAL_WRITES
142
143
144 # Universal
145 clean::
146 @$(RM) -rf $(SIM_BUILD)
147 @$(RM) -f $(COCOTB_RESULTS_FILE)
148
149
150 # Active-HDL
151 clean::
152 @$(RM) -rf work
153 @$(RM) -rf wave.asdb
154
155 # IUS
156 clean::
157 @$(RM) -rf irun.*
158 @$(RM) -rf ncsim.*
159 @$(RM) -rf gdb_cmd_ncsim
160
161 # VCS
162 clean::
163 @$(RM) -rf simv.daidir
164 @$(RM) -rf cm.log
165 @$(RM) -rf ucli.key
166
167 # Riviera
168 clean::
169 @$(RM) -rf compile
170 @$(RM) -rf library.cfg
171 @$(RM) -rf dataset.asdb
172
173 # Verilator
174 clean::
175 @$(RM) -f dump.vcd
176 @$(RM) -f dump.fst
177
178 # Xcelium
179 clean::
180 @$(RM) -rf xrun.*
181 @$(RM) -rf xmsim.*
182 @$(RM) -rf gdb_cmd_xmsim
183 @$(RM) -f qrun*
184 @$(RM) -f visualizer.log
185 @$(RM) -f design.bin
186 @$(RM) -f qwave.db
187 @$(RM) -f transcript
188
189
190 # DSim
191 clean::
192 @$(RM) -rf dsim.*
193 @$(RM) -rf metrics.db
194 @$(RM) -rf file.vcd
195
196 else
197 $(warning Including Makefile.inc from a user makefile is a no-op and deprecated. Remove the Makefile.inc inclusion from your makefile, and only leave the Makefile.sim include.)
198 endif # COCOTB_MAKEFILE_INC_INCLUDED