1#*****************************************************************************
2# DESCRIPTION: Verilator top level: Makefile pre-configure version
3#
4# This file is part of Verilator.
5#
6# Code available from: https://verilator.org
7#
8#*****************************************************************************
9#
10# Copyright 2003-2021 by Wilson Snyder. This program is free software; you
11# can redistribute it and/or modify it under the terms of either the GNU
12# Lesser General Public License Version 3 or the Perl Artistic License
13# Version 2.0.
14# SPDX-License-Identifier: LGPL-3.0-only OR Artistic-2.0
15#
16#****************************************************************************/
17#
18# make all	to compile and build Verilator.
19# make install	to install it.
20# make TAGS	to update tags tables.
21#
22# make clean  or  make mostlyclean
23#      Delete all files from the current directory that are normally
24#      created by building the program.	 Don't delete the files that
25#      record the configuration.  Also preserve files that could be made
26#      by building, but normally aren't because the distribution comes
27#      with them.
28#
29# make distclean
30#      Delete all files from the current directory that are created by
31#      configuring or building the program.  If you have unpacked the
32#      source and built the program without creating any other files,
33#      `make distclean' should leave only the files that were in the
34#      distribution.
35#
36# make maintainer-clean
37#      Delete everything from the current directory that can be
38#      reconstructed with this Makefile.  This typically includes
39#      everything deleted by distclean, plus more: C source files
40#      produced by Bison, tags tables, info files, and so on.
41
42#### Start of system configuration section. ####
43
44srcdir = @srcdir@
45VPATH = @srcdir@
46HOST = @HOST@
47EXEEXT = @EXEEXT@
48
49DOXYGEN = doxygen
50INSTALL = @INSTALL@
51INSTALL_PROGRAM = @INSTALL_PROGRAM@
52INSTALL_DATA = @INSTALL_DATA@
53MAKEINFO = makeinfo
54POD2TEXT = pod2text
55MKINSTALLDIRS = $(SHELL) $(srcdir)/src/mkinstalldirs
56PERL = @PERL@
57
58# Version (for docs/guide/conf.py)
59PACKAGE_VERSION_NUMBER = @PACKAGE_VERSION_NUMBER@
60
61# Destination prefix for RPMs
62DESTDIR =
63
64#### Don't edit: You're much better using configure switches to set these
65prefix = @prefix@
66exec_prefix = @exec_prefix@
67
68# Directory in which to install scripts.
69bindir = @bindir@
70
71# Directory in which to install manpages.
72mandir = @mandir@
73
74# Directory in which to install library files.
75datadir = @datadir@
76
77# Directory in which to install documentation info files.
78infodir = @infodir@
79
80# Directory in which to install package specific files
81# Generally ${prefix}/share/verilator
82pkgdatadir = @pkgdatadir@
83
84# Directory in which to install pkgconfig file
85# Generally ${prefix}/share/pkgconfig
86pkgconfigdir = /usr/local/libdata/pkgconfig
87
88# Directory in which to install data across multiple architectures
89datarootdir = @datarootdir@
90
91# Compile options
92CFG_WITH_CCWARN = @CFG_WITH_CCWARN@
93CFG_WITH_DEFENV = @CFG_WITH_DEFENV@
94CFG_WITH_LONGTESTS = @CFG_WITH_LONGTESTS@
95PACKAGE_VERSION = @PACKAGE_VERSION@
96
97#### End of system configuration section. ####
98######################################################################
99
100.SUFFIXES:
101
102SHELL = /bin/sh
103
104SUBDIRS = docs src test_regress \
105	examples/cmake_hello_c \
106	examples/cmake_hello_sc \
107	examples/cmake_tracing_c \
108	examples/cmake_tracing_sc \
109	examples/cmake_protect_lib \
110	examples/make_hello_c \
111	examples/make_hello_sc \
112	examples/make_tracing_c \
113	examples/make_tracing_sc \
114	examples/make_protect_lib \
115	examples/xml_py \
116
117INFOS = verilator.html verilator.pdf
118
119INFOS_OLD = README README.html README.pdf
120
121EXAMPLES_FIRST = \
122	examples/make_hello_c \
123	examples/make_hello_sc \
124
125EXAMPLES = $(EXAMPLES_FIRST) $(filter-out $(EXAMPLES_FIRST), $(sort $(wildcard examples/*)))
126
127# See uninstall also - don't put wildcards in this variable, it might uninstall other stuff
128VL_INST_MAN_FILES = verilator.1 verilator_coverage.1
129
130default: all
131all: all_nomsg msg_test
132all_nomsg: verilator_exe $(VL_INST_MAN_FILES)
133
134.PHONY:verilator_exe
135.PHONY:verilator_bin$(EXEEXT)
136.PHONY:verilator_bin_dbg$(EXEEXT)
137.PHONY:verilator_coverage_bin_dbg$(EXEEXT)
138verilator_exe verilator_bin$(EXEEXT) verilator_bin_dbg$(EXEEXT) verilator_coverage_bin_dbg$(EXEEXT):
139	@echo ------------------------------------------------------------
140	@echo "making verilator in src"
141	$(MAKE) -C src $(OBJCACHE_JOBS)
142
143.PHONY:msg_test
144msg_test: all_nomsg
145	@echo "Build complete!"
146	@echo
147	@echo "Now type 'make test' to test."
148	@echo
149
150.PHONY: test
151ifeq ($(CFG_WITH_LONGTESTS),yes)	# Local... Else don't burden users
152test: smoke-test test_regress
153# examples is part of test_regress's test_regress/t/t_a2_examples.pl
154# (because that allows it to run in parallel with other test_regress's)
155else
156test: smoke-test examples
157endif
158	@echo "Tests passed!"
159	@echo
160	@echo "Now type 'make install' to install."
161	@echo "Or type 'make' inside an examples subdirectory."
162	@echo
163
164smoke-test: all_nomsg
165	test_regress/t/t_a1_first_cc.pl
166	test_regress/t/t_a2_first_sc.pl
167
168test_regress: all_nomsg
169	$(MAKE) -C test_regress
170
171examples: all_nomsg
172	for p in $(EXAMPLES) ; do \
173	  $(MAKE) -C $$p VERILATOR_ROOT=`pwd` || exit 10; \
174	done
175
176.PHONY: docs
177docs: info
178
179info: $(INFOS)
180
181%.1: ${srcdir}/bin/%
182	pod2man $< $@
183
184.PHONY: verilator.html
185verilator.html:
186	$(MAKE) -C docs html
187
188# PDF needs DIST variables; but having configure.ac as dependency isn't detected
189.PHONY: verilator.pdf
190verilator.pdf: Makefile
191	$(MAKE) -C docs verilator.pdf
192
193# See uninstall also - don't put wildcards in this variable, it might uninstall other stuff
194VL_INST_BIN_FILES = verilator verilator_bin$(EXEEXT) verilator_bin_dbg$(EXEEXT) verilator_coverage_bin_dbg$(EXEEXT) \
195	verilator_ccache_report verilator_coverage verilator_gantt verilator_includer verilator_profcfunc
196# Some scripts go into both the search path and pkgdatadir,
197# so they can be found by the user, and under $VERILATOR_ROOT.
198
199VL_INST_INC_BLDDIR_FILES = \
200	include/verilated_config.h \
201	include/verilated.mk \
202
203# Files under srcdir, instead of build time
204VL_INST_INC_SRCDIR_FILES = \
205	include/*.[chv]* \
206	include/gtkwave/*.[chv]* \
207	include/vltstd/*.[chv]* \
208
209VL_INST_DATA_SRCDIR_FILES = \
210	examples/*/*.[chv]* \
211	examples/*/CMakeLists.txt \
212	examples/*/Makefile* \
213	examples/*/vl_* \
214
215installbin:
216	$(MKINSTALLDIRS) $(DESTDIR)$(bindir)
217	( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator $(DESTDIR)$(bindir)/verilator )
218	( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_coverage $(DESTDIR)$(bindir)/verilator_coverage )
219	( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_gantt $(DESTDIR)$(bindir)/verilator_gantt )
220	( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_profcfunc $(DESTDIR)$(bindir)/verilator_profcfunc )
221	( cd bin ; $(INSTALL_PROGRAM) verilator_bin$(EXEEXT) $(DESTDIR)$(bindir)/verilator_bin$(EXEEXT) )
222	( cd bin ; $(INSTALL_PROGRAM) verilator_bin_dbg$(EXEEXT) $(DESTDIR)$(bindir)/verilator_bin_dbg$(EXEEXT) )
223	( cd bin ; $(INSTALL_PROGRAM) verilator_coverage_bin_dbg$(EXEEXT) $(DESTDIR)$(bindir)/verilator_coverage_bin_dbg$(EXEEXT) )
224	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/bin
225	( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_includer $(DESTDIR)$(pkgdatadir)/bin/verilator_includer )
226	( cd ${srcdir}/bin ; $(INSTALL_PROGRAM) verilator_ccache_report $(DESTDIR)$(pkgdatadir)/bin/verilator_ccache_report )
227
228# Man files can either be part of the original kit, or built in current directory
229# So important we use $^ so VPATH is searched
230installman: $(VL_INST_MAN_FILES)
231	$(MKINSTALLDIRS) $(DESTDIR)$(mandir)/man1
232	for p in $^ ; do \
233	  $(INSTALL_DATA) $$p $(DESTDIR)$(mandir)/man1/$$p; \
234	done
235
236installdata:
237	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/include/gtkwave
238	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/include/vltstd
239	for p in $(VL_INST_INC_BLDDIR_FILES) ; do \
240	  $(INSTALL_DATA) $$p $(DESTDIR)$(pkgdatadir)/$$p; \
241	done
242	cd $(srcdir) \
243	; for p in $(VL_INST_INC_SRCDIR_FILES) ; do \
244	  $(INSTALL_DATA) $$p $(DESTDIR)$(pkgdatadir)/$$p; \
245	done
246	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/make_hello_c
247	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/make_hello_sc
248	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/make_tracing_c
249	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/make_tracing_sc
250	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/make_protect_lib
251	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/cmake_hello_c
252	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/cmake_hello_sc
253	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/cmake_tracing_c
254	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/cmake_tracing_sc
255	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/cmake_protect_lib
256	$(MKINSTALLDIRS) $(DESTDIR)$(pkgdatadir)/examples/xml_py
257	cd $(srcdir) \
258	; for p in $(VL_INST_DATA_SRCDIR_FILES) ; do \
259	  $(INSTALL_DATA) $$p $(DESTDIR)$(pkgdatadir)/$$p; \
260	done
261	$(MKINSTALLDIRS) $(DESTDIR)$(pkgconfigdir)
262	$(INSTALL_DATA) verilator.pc $(DESTDIR)$(pkgconfigdir)
263	$(INSTALL_DATA) verilator-config.cmake $(DESTDIR)$(pkgdatadir)
264	$(INSTALL_DATA) verilator-config-version.cmake $(DESTDIR)$(pkgdatadir)
265
266# We don't trust rm -rf, so rmdir instead as it will fail if user put in other files
267uninstall:
268	-cd $(DESTDIR)$(bindir) && rm -f $(VL_INST_BIN_FILES)
269	-cd $(DESTDIR)$(pkgdatadir)/bin && rm -f $(VL_INST_BIN_FILES)
270	-cd $(DESTDIR)$(mandir)/man1 && rm -f $(VL_INST_MAN_FILES)
271	-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_INC_BLDDIR_FILES)
272	-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_INC_SRCDIR_FILES)
273	-cd $(DESTDIR)$(pkgdatadir) && rm -f $(VL_INST_DATA_SRCDIR_FILES)
274	-rm $(DESTDIR)$(pkgconfigdir)/verilator.pc
275	-rm $(DESTDIR)$(pkgdatadir)/verilator-config.cmake
276	-rm $(DESTDIR)$(pkgdatadir)/verilator-config-version.cmake
277	-rmdir $(DESTDIR)$(pkgdatadir)/bin
278	-rmdir $(DESTDIR)$(pkgdatadir)/include/gtkwave
279	-rmdir $(DESTDIR)$(pkgdatadir)/include/vltstd
280	-rmdir $(DESTDIR)$(pkgdatadir)/include
281	-rmdir $(DESTDIR)$(pkgdatadir)/examples/make_hello_c
282	-rmdir $(DESTDIR)$(pkgdatadir)/examples/make_hello_sc
283	-rmdir $(DESTDIR)$(pkgdatadir)/examples/make_tracing_c
284	-rmdir $(DESTDIR)$(pkgdatadir)/examples/make_tracing_sc
285	-rmdir $(DESTDIR)$(pkgdatadir)/examples/make_protect_lib
286	-rmdir $(DESTDIR)$(pkgdatadir)/examples/cmake_hello_c
287	-rmdir $(DESTDIR)$(pkgdatadir)/examples/cmake_hello_sc
288	-rmdir $(DESTDIR)$(pkgdatadir)/examples/cmake_tracing_c
289	-rmdir $(DESTDIR)$(pkgdatadir)/examples/cmake_tracing_sc
290	-rmdir $(DESTDIR)$(pkgdatadir)/examples/cmake_protect_lib
291	-rmdir $(DESTDIR)$(pkgdatadir)/examples/xml_py
292	-rmdir $(DESTDIR)$(pkgdatadir)/examples
293	-rmdir $(DESTDIR)$(pkgdatadir)
294	-rmdir $(DESTDIR)$(pkgconfigdir)
295
296install: all_nomsg install-all
297install-all: installbin installman installdata install-msg
298
299install-here: installman info
300
301# Use --xml flag to see the cppcheck code to use for suppression
302CPPCHECK_CPP = $(wildcard \
303	$(srcdir)/examples/*/*.cpp \
304	$(srcdir)/include/*.cpp \
305	$(srcdir)/src/*.cpp )
306CPPCHECK_H = $(wildcard \
307	$(srcdir)/include/*.h \
308	$(srcdir)/src/*.h )
309CPPCHECK_YL = $(wildcard \
310	$(srcdir)/src/*.y \
311	$(srcdir)/src/*.l )
312CPPCHECK = src/cppcheck_filtered cppcheck
313CPPCHECK_FLAGS = --enable=all --inline-suppr \
314	--suppress=unusedScopedObject --suppress=cstyleCast --suppress=useInitializationList \
315	--suppress=nullPointerRedundantCheck
316CPPCHECK_FLAGS += --xml
317CPPCHECK_DEP = $(subst .cpp,.cppcheck,$(CPPCHECK_CPP))
318CPPCHECK_INC = -I$(srcdir)/include -I$(srcdir)/src/obj_dbg -I$(srcdir)/src
319
320cppcheck: $(CPPCHECK_DEP)
321%.cppcheck: %.cpp
322	$(CPPCHECK) $(CPPCHECK_FLAGS) -DVL_DEBUG=1 -DVL_CPPCHECK=1 -DVL_THREADED=1 $(CPPCHECK_INC) $<
323
324CLANGTIDY = clang-tidy
325CLANGTIDY_FLAGS = -config='' -checks='-fuchsia-*,-cppcoreguidelines-avoid-c-arrays,-cppcoreguidelines-init-variables'
326CLANGTIDY_DEP = $(subst .h,.h.tidy,$(CPPCHECK_H)) \
327	$(subst .cpp,.cpp.tidy,$(CPPCHECK_CPP))
328CLANGTIDY_DEFS = -DVL_DEBUG=1 -DVL_THREADED=1 -DVL_CPPCHECK=1
329
330clang-tidy: $(CLANGTIDY_DEP)
331%.cpp.tidy: %.cpp
332	$(CLANGTIDY) $(CLANGTIDY_FLAGS) $< -- $(CLANGTIDY_DEFS) $(CPPCHECK_INC) | 2>&1 tee $@
333%.h.tidy: %.h
334	$(CLANGTIDY) $(CLANGTIDY_FLAGS) $< -- $(CLANGTIDY_DEFS) $(CPPCHECK_INC) | 2>&1 tee $@
335
336analyzer-src:
337	-rm -rf src/obj_dbg
338	scan-build $(MAKE) -k verilator_coverage_bin_dbg$(EXEEXT) verilator_bin_dbg$(EXEEXT)
339
340analyzer-include:
341	-rm -rf examples/*/obj*
342	scan-build $(MAKE) -k examples
343
344format: clang-format yapf format-pl-exec
345
346CLANGFORMAT = clang-format-11
347CLANGFORMAT_FLAGS = -i
348CLANGFORMAT_FILES = $(CPPCHECK_CPP) $(CPPCHECK_H) $(CPPCHECK_YL) test_regress/t/*.c* test_regress/t/*.h
349
350clang-format:
351	@$(CLANGFORMAT) --version | egrep 11.0 > /dev/null \
352		|| echo "*** You are not using clang-format 11.0, indents may differ from master's ***"
353	$(CLANGFORMAT) $(CLANGFORMAT_FLAGS) $(CLANGFORMAT_FILES)
354
355PY_PROGRAMS = \
356	bin/verilator_ccache_report \
357	bin/verilator_difftree \
358	bin/verilator_gantt \
359	bin/verilator_profcfunc \
360	examples/xml_py/vl_file_copy \
361	examples/xml_py/vl_hier_graph \
362	docs/guide/conf.py \
363	docs/bin/vl_sphinx_extract \
364	docs/bin/vl_sphinx_fix \
365	src/astgen \
366	src/bisonpre \
367	src/config_rev \
368	src/cppcheck_filtered \
369	src/flexfix \
370	src/vlcovgen \
371	test_regress/t/*.pf \
372	nodist/code_coverage \
373	nodist/dot_importer \
374	nodist/fuzzer/actual_fail \
375	nodist/fuzzer/generate_dictionary \
376	nodist/install_test \
377
378PY_FILES = \
379	$(PY_PROGRAMS) \
380	nodist/code_coverage.dat \
381
382YAPF = yapf3
383YAPF_FLAGS = -i
384
385yapf:
386	$(YAPF) $(YAPF_FLAGS) $(PY_FILES)
387
388FLAKE8 = flake8
389FLAKE8_FLAGS = \
390	--extend-exclude=fastcov.py \
391	--ignore=E123,E129,E251,E501,W503,W504,E701
392
393PYLINT = pylint
394PYLINT_FLAGS = --disable=R0801
395
396lint-py:
397	-$(FLAKE8) $(FLAKE8_FLAGS) $(PY_PROGRAMS)
398	-$(PYLINT) $(PYLINT_FLAGS) $(PY_PROGRAMS)
399
400format-pl-exec:
401	-chmod a+x test_regress/t/*.pl
402
403install-msg:
404	@echo
405	@echo "Installed binaries to $(DESTDIR)$(bindir)/verilator"
406	@echo "Installed man to $(DESTDIR)$(mandir)/man1"
407	@echo "Installed examples to $(DESTDIR)$(pkgdatadir)/examples"
408	@echo
409	@echo "For documentation see 'man verilator' or 'verilator --help'"
410	@echo "For forums and to report bugs see https://verilator.org"
411	@echo
412
413IN_WILD := ${srcdir}/*.in ${srcdir}/*/*.in
414
415# autoheader might not change config_build.h.in, so touch it
416${srcdir}/config_build.h: ${srcdir}/config_build.h.in configure
417	cd ${srcdir} && autoheader
418	touch $@
419Makefile: Makefile.in config.status $(IN_WILD)
420	./config.status
421src/Makefile: src/Makefile.in Makefile
422config.status: configure
423	./config.status --recheck
424
425configure: configure.ac
426ifeq ($(CFG_WITH_CCWARN),yes)	# Local... Else don't burden users
427	autoconf --warnings=all
428else
429	autoconf
430endif
431
432maintainer-clean::
433	@echo "This command is intended for maintainers to use;"
434	@echo "rebuilding the deleted files requires autoconf."
435	rm -f configure
436
437clean mostlyclean distclean maintainer-clean maintainer-copy::
438	for dir in $(SUBDIRS); do \
439	  echo making $@ in $$dir ; \
440	  $(MAKE) -C $$dir $@ ; \
441	done
442
443clean mostlyclean distclean maintainer-clean::
444	rm -f $(SCRIPTS) *.tmp
445	rm -f *.aux *.cp *.cps *.dvi *.fn *.fns *.ky *.kys *.log
446	rm -f *.pg *.pgs *.toc *.tp *.tps *.vr *.vrs *.idx
447	rm -f *.ev *.evs *.ov *.ovs *.cv *.cvs *.ma *.mas
448	rm -f *.tex
449	rm -rf examples/*/obj_dir* examples/*/logs
450	rm -rf test_*/obj_dir
451	rm -rf nodist/fuzzer/dictionary
452	rm -rf nodist/obj_dir
453	rm -rf verilator.txt
454
455distclean maintainer-clean::
456	rm -f *.info* *.1 $(INFOS) $(INFOS_OLD) $(VL_INST_MAN_FILES)
457	rm -f Makefile config.status config.cache config.log TAGS
458	rm -f verilator_bin* verilator_coverage_bin*
459	rm -f bin/verilator_bin* bin/verilator_coverage_bin*
460	rm -f include/verilated.mk include/verilated_config.h
461
462TAGFILES=${srcdir}/*/*.cpp ${srcdir}/*/*.h ${srcdir}/*/*.in \
463	${srcdir}/*.in ${srcdir}/*.pod
464
465TAGS:	$(TAGFILES)
466	etags $(TAGFILES)
467
468.PHONY: doxygen
469
470doxygen:
471	$(MAKE) -C docs doxygen
472
473######################################################################
474# Distributions
475
476DISTTITLE := Verilator $(word 1,$(PACKAGE_VERSION))
477DISTNAME := verilator-$(word 1,$(PACKAGE_VERSION))
478DISTDATEPRE := $(word 2,$(PACKAGE_VERSION))
479DISTDATE := $(subst /,-,$(DISTDATEPRE))
480DISTTAGNAME := $(subst .,_,$(subst -,_,$(DISTNAME)))
481
482tag:
483	svnorcvs tag $(DISTTAGNAME)
484
485maintainer-diff:
486	svnorcvs diff $(DISTTAGNAME)
487
488preexist:
489	svnorcvs nexists $(DISTTAGNAME)
490
491maintainer-dist: preexist tag
492	svnorcvs release $(DISTTAGNAME)
493