Verilator

Форк
0
/
verilated.mk.in 
354 строки · 12.0 Кб
1
# -*- Makefile -*-
2
######################################################################
3
# DESCRIPTION: Makefile commands for all verilated target files
4
#
5
# Copyright 2003-2024 by Wilson Snyder. This program is free software; you
6
# can redistribute it and/or modify it under the terms of either the GNU
7
# Lesser General Public License Version 3 or the Perl Artistic License
8
# Version 2.0.
9
# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
10
######################################################################
11

12
# Tool names.
13
# These are computed at configuration time, and most are not ?=
14
# to avoid picking up potentially incorrect Make implicit variables
15
AR = @AR@
16
CXX = @CXX@
17
LINK = @CXX@
18
OBJCACHE ?= @OBJCACHE@
19
PERL = @PERL@
20
PYTHON3 = @PYTHON3@
21

22
# Configuration time options
23
CFG_WITH_CCWARN = @CFG_WITH_CCWARN@
24
CFG_WITH_LONGTESTS = @CFG_WITH_LONGTESTS@
25

26
# Compiler flags to enable profiling
27
CFG_CXXFLAGS_PROFILE = @CFG_CXXFLAGS_PROFILE@
28
# Select language required to compile (often empty)
29
CFG_CXXFLAGS_STD = @CFG_CXXFLAGS_STD@
30
# Select newest language (unused by this Makefile, for some test's Makefiles)
31
CFG_CXXFLAGS_STD_NEWEST = @CFG_CXXFLAGS_STD_NEWEST@
32
# Compiler flags to use to turn off unused and generated code warnings, such as -Wno-div-by-zero
33
CFG_CXXFLAGS_NO_UNUSED = @CFG_CXXFLAGS_NO_UNUSED@
34
# Compiler flags that turn on extra warnings
35
CFG_CXXFLAGS_WEXTRA = @CFG_CXXFLAGS_WEXTRA@
36
# Compiler flags that enable coroutine support
37
CFG_CXXFLAGS_COROUTINES = @CFG_CXXFLAGS_COROUTINES@
38
# Compiler flags when creating a precompiled header
39
CFG_CXXFLAGS_PCH = -x c++-header
40
# Compiler option to put in front of filename to read precompiled header
41
CFG_CXXFLAGS_PCH_I = @CFG_CXXFLAGS_PCH_I@
42
# Compiler's filename prefix for precompiled headers, .gch if clang, empty if GCC
43
CFG_GCH_IF_CLANG = @CFG_GCH_IF_CLANG@
44
# Linker flags
45
CFG_LDFLAGS_VERILATED = @CFG_LDFLAGS_VERILATED@
46
# Linker libraries for multithreading
47
CFG_LDLIBS_THREADS = @CFG_LDLIBS_THREADS@
48

49
######################################################################
50
# Programs
51

52
VERILATOR_COVERAGE = $(PERL) $(VERILATOR_ROOT)/bin/verilator_coverage
53
VERILATOR_INCLUDER = $(PYTHON3) $(VERILATOR_ROOT)/bin/verilator_includer
54
VERILATOR_CCACHE_REPORT = $(PYTHON3) $(VERILATOR_ROOT)/bin/verilator_ccache_report
55

56
######################################################################
57
# CCACHE flags (via environment as no command line option available)
58

59
CCACHE_SLOPPINESS ?= pch_defines,time_macros
60
export CCACHE_SLOPPINESS
61

62
######################################################################
63
# Make checks
64

65
ifneq ($(words $(CURDIR)),1)
66
 $(error Unsupported: GNU Make cannot build in directories containing spaces, build elsewhere: '$(CURDIR)')
67
endif
68

69
######################################################################
70
# OS detection
71
UNAME_S := $(shell uname -s)
72

73
######################################################################
74
# C Preprocessor flags
75

76
# Add -MMD -MP if you're using a recent version of GCC.
77
VK_CPPFLAGS_ALWAYS += \
78
		-MMD \
79
		-I$(VERILATOR_ROOT)/include \
80
		-I$(VERILATOR_ROOT)/include/vltstd \
81
		-DVM_COVERAGE=$(VM_COVERAGE) \
82
		-DVM_SC=$(VM_SC) \
83
		-DVM_TRACE=$(VM_TRACE) \
84
		-DVM_TRACE_FST=$(VM_TRACE_FST) \
85
		-DVM_TRACE_VCD=$(VM_TRACE_VCD) \
86
		$(CFG_CXXFLAGS_NO_UNUSED) \
87

88
ifeq ($(CFG_WITH_CCWARN),yes)  # Local... Else don't burden users
89
VK_CPPFLAGS_WALL += -Wall $(CFG_CXXFLAGS_WEXTRA) -Werror
90
endif
91

92
CPPFLAGS += -I. $(VK_CPPFLAGS_WALL) $(VK_CPPFLAGS_ALWAYS)
93

94
VPATH += ..
95
VPATH += $(VERILATOR_ROOT)/include
96
VPATH += $(VERILATOR_ROOT)/include/vltstd
97

98
LDFLAGS  += $(CFG_LDFLAGS_VERILATED)
99

100
#OPT = -ggdb -DPRINTINITSTR -DDETECTCHANGE
101
#OPT = -ggdb -DPRINTINITSTR
102
CPPFLAGS += $(OPT)
103

104
# On macOS, specify all weak symbols as dynamic_lookup.
105
# Otherwise, you get undefined symbol errors.
106
ifeq ($(UNAME_S),Darwin)
107
	LDFLAGS += -Wl,-U,__Z15vl_time_stamp64v,-U,__Z13sc_time_stampv
108
endif
109

110
# Allow upper level user makefiles to specify flags they want.
111
# These aren't ever set by Verilator, so users are free to override them.
112
CPPFLAGS += $(USER_CPPFLAGS)
113
LDFLAGS  += $(USER_LDFLAGS)
114
LDLIBS   += $(USER_LDLIBS)
115

116
# Add flags from -CFLAGS and -LDFLAGS on Verilator command line
117
CPPFLAGS += $(VM_USER_CFLAGS)
118
LDFLAGS  += $(VM_USER_LDFLAGS)
119
LDLIBS   += $(VM_USER_LDLIBS)
120

121
######################################################################
122
# Optimization control.
123

124
# See also the BENCHMARKING & OPTIMIZATION section of the manual.
125

126
# Optimization flags for non performance-critical/rarely executed code.
127
# No optimization by default, which improves compilation speed.
128
OPT_SLOW =
129
# Optimization for performance critical/hot code. Most time is spent in these
130
# routines. Optimizing by default for improved execution speed.
131
OPT_FAST = -Os
132
# Optimization applied to the common run-time library used by verilated models.
133
# For compatibility this is called OPT_GLOBAL even though it only applies to
134
# files in the run-time library. Normally there should be no need for the user
135
# to change this as the library is small, but can have significant speed impact.
136
OPT_GLOBAL = -Os
137

138
#######################################################################
139
##### Profile builds
140

141
ifeq ($(VM_PROFC),1)
142
  CPPFLAGS += $(CFG_CXXFLAGS_PROFILE)
143
  LDFLAGS  += $(CFG_CXXFLAGS_PROFILE)
144
endif
145

146
#######################################################################
147
##### SystemC builds
148

149
ifeq ($(VM_SC),1)
150
  CPPFLAGS += $(SYSTEMC_CXX_FLAGS) $(addprefix -I, $(SYSTEMC_INCLUDE))
151
  LDFLAGS  += $(SYSTEMC_CXX_FLAGS) $(addprefix -L, $(SYSTEMC_LIBDIR))
152
  SC_LIBS   = -lsystemc
153
 ifneq ($(wildcard $(SYSTEMC_LIBDIR)/*numeric_bit*),)
154
  # SystemC 1.2.1beta
155
  SC_LIBS   += -lnumeric_bit -lqt
156
 endif
157
endif
158

159
#######################################################################
160
##### Threaded builds
161

162
CPPFLAGS += $(CFG_CXXFLAGS_STD)
163
LDLIBS += $(CFG_LDLIBS_THREADS)
164

165
ifneq ($(VM_TIMING),0)
166
 ifneq ($(VM_TIMING),)
167
  CPPFLAGS += $(CFG_CXXFLAGS_COROUTINES)
168
 endif
169
endif
170

171

172
#######################################################################
173
### Aggregates
174

175
VM_FAST += $(VM_CLASSES_FAST) $(VM_SUPPORT_FAST)
176
VM_SLOW += $(VM_CLASSES_SLOW) $(VM_SUPPORT_SLOW)
177

178
# Precompiled header filename
179
VK_PCH_H = $(VM_PREFIX)__pch.h
180
# Compiler read-a-precompiled-header option for precompiled header filename
181
VK_PCH_I_FAST = $(CFG_CXXFLAGS_PCH_I) $(VM_PREFIX)__pch.h.fast$(CFG_GCH_IF_CLANG)
182
VK_PCH_I_SLOW = $(CFG_CXXFLAGS_PCH_I) $(VM_PREFIX)__pch.h.slow$(CFG_GCH_IF_CLANG)
183

184
#######################################################################
185
### Overall Objects Linking
186

187
VK_OBJS_FAST = $(addsuffix .o, $(VM_FAST))
188
VK_OBJS_SLOW = $(addsuffix .o, $(VM_SLOW))
189

190
VK_USER_OBJS = $(addsuffix .o, $(VM_USER_CLASSES))
191

192
# Note VM_GLOBAL_FAST and VM_GLOBAL_SLOW holds the files required from the
193
# run-time library. In practice everything is actually in VM_GLOBAL_FAST,
194
# but keeping the distinction for compatibility for now.
195
VK_GLOBAL_OBJS = $(addsuffix .o, $(VM_GLOBAL_FAST) $(VM_GLOBAL_SLOW))
196

197
# Need to re-build if the generated makefile changes, as compiler options might
198
# have changed.
199
$(VK_GLOBAL_OBJS): $(VM_PREFIX).mk
200

201
ifneq ($(VM_PARALLEL_BUILDS),1)
202
  # Fast build for small designs: All .cpp files in one fell swoop. This
203
  # saves total compute, but can be slower if only a little changes. It is
204
  # also a lot slower for medium to large designs when the speed of the C
205
  # compiler dominates, which in this mode is not parallelizable.
206

207
  VK_OBJS += $(VM_PREFIX)__ALL.o
208
  $(VM_PREFIX)__ALL.cpp: $(addsuffix .cpp, $(VM_FAST) $(VM_SLOW))
209
	$(VERILATOR_INCLUDER) -DVL_INCLUDE_OPT=include $^ > $@
210
  all_cpp: $(VM_PREFIX)__ALL.cpp
211
else
212
  # Parallel build: Each .cpp file by itself. This can be somewhat slower for
213
  # very small designs and examples, but is a lot faster for large designs.
214

215
  VK_OBJS += $(VK_OBJS_FAST) $(VK_OBJS_SLOW)
216
endif
217

218
# When archiving just objects (.o), use single $(AR) run
219
#   1. Make .verilator_deplist.tmp file with list of objects so don't exceed
220
#      the command line limits when calling $(AR).
221
#      The approach to write the dependency file is compatible with GNU Make 3,
222
#      and can be simplified using the file function once GNU Make 4.x becomes
223
#      the minimum supported version.
224
# When merging objects (.o) and archives (.a) additionally:
225
#   1. Extract object files from .a
226
#   2. Create a new archive from extracted .o and given .o
227
%.a: | %.verilator_deplist.tmp
228
	$(foreach L, $(filter-out %.a,$^), $(shell echo $L >>$@.verilator_deplist.tmp))
229
	@if test $(words $(filter %.a,$^)) -eq 0; then \
230
		$(RM) -f $@; \
231
		cat $@.verilator_deplist.tmp | xargs $(AR) -rc $@; \
232
		$(AR) -s $@; \
233
	else \
234
		$(RM) -rf $@.tmpdir; \
235
		for archive in $(filter %.a,$^); do \
236
			mkdir -p $@.tmpdir/$$(basename $${archive}); \
237
			cd $@.tmpdir/$$(basename $${archive}); \
238
			$(AR) -x ../../$${archive}; \
239
			cd ../..; \
240
		done; \
241
		$(RM) -f $@; \
242
		cat $@.verilator_deplist.tmp | xargs $(AR) -rc $@; \
243
		$(AR) -rcs $@ $@.tmpdir/*/*.o; \
244
	fi \
245
	; $(RM) -rf $@.verilator_deplist.tmp $@.tmpdir
246

247
# Truncate the dependency list file used in the %.a target above.
248
%.verilator_deplist.tmp:
249
	echo "" > $@
250

251
$(VM_PREFIX)__ALL.a: $(VK_OBJS) $(VM_HIER_LIBS)
252

253

254
######################################################################
255
### Compile rules
256

257
ifneq ($(VM_DEFAULT_RULES),0)
258
# Compilation rule for anything not in $(VK_OBJS_FAST), $(VK_OBJS_SLOW), or
259
# $(VK_GLOBAL_OBJS) including verilated.o.  This typically means user files
260
# passed on the Verilator command line.
261
#
262
# These rules put OPT_FAST/OPT_SLOW/OPT_GLOBAL before the other flags to
263
# allow USER_CPPFLAGS to override them
264
%.o: %.cpp
265
	$(OBJCACHE) $(CXX) $(OPT_FAST) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
266

267
$(VK_OBJS_FAST): %.o: %.cpp $(VK_PCH_H).fast.gch
268
	$(OBJCACHE) $(CXX) $(OPT_FAST) $(CXXFLAGS) $(CPPFLAGS) $(VK_PCH_I_FAST) -c -o $@ $<
269

270
$(VK_OBJS_SLOW): %.o: %.cpp $(VK_PCH_H).slow.gch
271
	$(OBJCACHE) $(CXX) $(OPT_SLOW) $(CXXFLAGS) $(CPPFLAGS) $(VK_PCH_I_SLOW) -c -o $@ $<
272

273
$(VK_GLOBAL_OBJS): %.o: %.cpp
274
	$(OBJCACHE) $(CXX) $(OPT_GLOBAL) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
275

276
# Precompile a header file
277
# PCH's compiler flags must match exactly the rules' above FAST/SLOW
278
# arguments used for the .cpp files, or the PCH file won't be used.
279
%.fast.gch: %
280
	$(OBJCACHE) $(CXX) $(OPT_FAST) $(CXXFLAGS) $(CPPFLAGS) $(CFG_CXXFLAGS_PCH) $< -o $@
281
%.slow.gch: %
282
	$(OBJCACHE) $(CXX) $(OPT_SLOW) $(CXXFLAGS) $(CPPFLAGS) $(CFG_CXXFLAGS_PCH) $< -o $@
283

284
endif
285

286
#Default rule embedded in make:
287
#.cpp.o:
288
#	$(CXX) $(CXXFLAGS) $(CPPFLAGS) -c -o $@ $<
289

290
######################################################################
291
### ccache report
292

293
ifneq ($(findstring ccache-report,$(MAKECMDGOALS)),)
294
  ifneq ($(OBJCACHE),ccache)
295
    $(error ccache-report requires OBJCACHE to equal 'ccache')
296
  endif
297
  VK_OTHER_GOALS := $(strip $(subst ccache-report,,$(MAKECMDGOALS)))
298
  ifeq ($(VK_OTHER_GOALS),)
299
    $(error ccache-report must be used with at least one other explicit target)
300
  endif
301

302
  # Report ccache behaviour for this invocation of make
303
  VK_CCACHE_LOGDIR := ccache-logs
304
  VK_CCACHE_REPORT := $(VM_PREFIX)__ccache_report.txt
305
  # Remove previous logfiles and report
306
  $(shell rm -rf $(VK_CCACHE_LOGDIR) $(VK_CCACHE_REPORT))
307

308
$(VK_CCACHE_LOGDIR):
309
	mkdir -p $@
310

311
$(VK_OBJS): | $(VK_CCACHE_LOGDIR)
312

313
$(VK_OBJS): export CCACHE_LOGFILE=$(VK_CCACHE_LOGDIR)/$@.log
314

315
$(VK_CCACHE_REPORT): $(VK_OBJS)
316
	$(VERILATOR_CCACHE_REPORT) -o $@ $(VK_CCACHE_LOGDIR)
317

318
.PHONY: ccache-report
319
ccache-report: $(VK_CCACHE_REPORT)
320
	@cat $<
321

322
# ccache-report runs last
323
ccache-report: $(VK_OTHER_GOALS)
324
endif
325

326
######################################################################
327
### Debugging
328

329
debug-make::
330
	@echo
331
	@echo CPPFLAGS: $(CPPFLAGS)
332
	@echo CXXFLAGS: $(CXXFLAGS)
333
	@echo OPT_FAST: $(OPT_FAST)
334
	@echo OPT_SLOW: $(OPT_SLOW)
335
	@echo VK_OBJS: $(VK_OBJS)
336
	@echo VK_OBJS_FAST: $(VK_OBJS_FAST)
337
	@echo VK_OBJS_SLOW: $(VK_OBJS_SLOW)
338
	@echo VM_CLASSES_FAST: $(VM_CLASSES_FAST)
339
	@echo VM_CLASSES_SLOW: $(VM_CLASSES_SLOW)
340
	@echo VM_GLOBAL_FAST: $(VM_GLOBAL_FAST)
341
	@echo VM_GLOBAL_SLOW: $(VM_GLOBAL_SLOW)
342
	@echo VM_PARALLEL_BUILDS:  $(VM_PARALLEL_BUILDS)
343
	@echo VM_PREFIX:  $(VM_PREFIX)
344
	@echo VM_SUPPORT_FAST: $(VM_SUPPORT_FAST)
345
	@echo VM_SUPPORT_SLOW: $(VM_SUPPORT_SLOW)
346
	@echo
347

348
######################################################################
349
### Detect out of date files and rebuild.
350

351
DEPS := $(wildcard *.d)
352
ifneq ($(DEPS),)
353
include $(DEPS)
354
endif
355

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.