Merge branch 'tor-gitlab/mr/326' into maint-0.4.5
[tor.git] / Makefile.am
blob3056b084469f771e6201c7d1c8d2d4dfc6634834
1 # Copyright (c) 2001-2004, Roger Dingledine
2 # Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 # Copyright (c) 2007-2019, The Tor Project, Inc.
4 # See LICENSE for licensing information
6 ACLOCAL_AMFLAGS = -I m4
8 noinst_LIBRARIES=
9 EXTRA_DIST=
10 noinst_HEADERS=
11 bin_PROGRAMS=
12 EXTRA_PROGRAMS=
13 CLEANFILES=
14 TESTS=
15 noinst_PROGRAMS=
16 DISTCLEANFILES=
17 MOSTLYCLEANFILES=
18 bin_SCRIPTS=
19 AM_CPPFLAGS=\
20         -I$(top_srcdir)/src \
21         -I$(top_srcdir)/src/ext \
22         -I$(top_srcdir)/src/ext/trunnel \
23         -I$(top_srcdir)/src/trunnel
25 AM_CFLAGS=                                      \
26         @TOR_SYSTEMD_CFLAGS@                    \
27         @CFLAGS_BUGTRAP@                        \
28         @TOR_LZMA_CFLAGS@                       \
29         @TOR_ZSTD_CFLAGS@
31 SHELL=@SHELL@
33 if COVERAGE_ENABLED
34 TESTING_TOR_BINARY=$(top_builddir)/src/app/tor-cov$(EXEEXT)
35 else
36 TESTING_TOR_BINARY=$(top_builddir)/src/app/tor$(EXEEXT)
37 endif
39 if USE_RUST
40 rust_ldadd=$(top_builddir)/$(TOR_RUST_LIB_PATH)
41 else
42 rust_ldadd=
43 endif
45 # "Common" libraries used to link tor's utility code.
46 TOR_UTIL_LIBS = \
47         src/lib/libtor-geoip.a \
48         src/lib/libtor-process.a \
49         src/lib/libtor-buf.a \
50         src/lib/libtor-confmgt.a \
51         src/lib/libtor-pubsub.a \
52         src/lib/libtor-dispatch.a \
53         src/lib/libtor-time.a \
54         src/lib/libtor-fs.a \
55         src/lib/libtor-encoding.a \
56         src/lib/libtor-sandbox.a \
57         src/lib/libtor-container.a \
58         src/lib/libtor-net.a \
59         src/lib/libtor-thread.a \
60         src/lib/libtor-memarea.a \
61         src/lib/libtor-math.a \
62         src/lib/libtor-meminfo.a \
63         src/lib/libtor-osinfo.a \
64         src/lib/libtor-log.a \
65         src/lib/libtor-lock.a \
66         src/lib/libtor-fdio.a \
67         src/lib/libtor-string.a \
68         src/lib/libtor-term.a \
69         src/lib/libtor-smartlist-core.a \
70         src/lib/libtor-malloc.a \
71         src/lib/libtor-wallclock.a \
72         src/lib/libtor-err.a \
73         src/lib/libtor-version.a \
74         src/lib/libtor-llharden.a \
75         src/lib/libtor-intmath.a \
76         src/lib/libtor-ctime.a \
77         src/lib/libtor-metrics.a
79 # Variants of the above for linking the testing variant of tor (for coverage
80 # and tests)
81 if UNITTESTS_ENABLED
82 TOR_UTIL_TESTING_LIBS = \
83         src/lib/libtor-geoip-testing.a \
84         src/lib/libtor-process-testing.a \
85         src/lib/libtor-buf-testing.a \
86         src/lib/libtor-confmgt-testing.a \
87         src/lib/libtor-pubsub-testing.a \
88         src/lib/libtor-dispatch-testing.a \
89         src/lib/libtor-time-testing.a \
90         src/lib/libtor-fs-testing.a \
91         src/lib/libtor-encoding-testing.a \
92         src/lib/libtor-sandbox-testing.a \
93         src/lib/libtor-container-testing.a \
94         src/lib/libtor-net-testing.a \
95         src/lib/libtor-thread-testing.a \
96         src/lib/libtor-memarea-testing.a \
97         src/lib/libtor-math-testing.a \
98         src/lib/libtor-meminfo-testing.a \
99         src/lib/libtor-osinfo-testing.a \
100         src/lib/libtor-term-testing.a \
101         src/lib/libtor-log-testing.a \
102         src/lib/libtor-lock-testing.a \
103         src/lib/libtor-fdio-testing.a \
104         src/lib/libtor-string-testing.a \
105         src/lib/libtor-smartlist-core-testing.a \
106         src/lib/libtor-malloc-testing.a \
107         src/lib/libtor-wallclock-testing.a \
108         src/lib/libtor-err-testing.a \
109         src/lib/libtor-version-testing.a \
110         src/lib/libtor-llharden-testing.a \
111         src/lib/libtor-intmath.a \
112         src/lib/libtor-ctime-testing.a \
113         src/lib/libtor-metrics-testing.a
114 endif
116 # Internal crypto libraries used in Tor
117 TOR_CRYPTO_LIBS = \
118         src/lib/libtor-tls.a \
119         src/lib/libtor-crypt-ops.a \
120         $(LIBKECCAK_TINY) \
121         $(LIBDONNA)
123 # Variants of the above for linking the testing variant of tor (for coverage
124 # and tests)
125 if UNITTESTS_ENABLED
126 TOR_CRYPTO_TESTING_LIBS = \
127         src/lib/libtor-tls-testing.a \
128         src/lib/libtor-crypt-ops-testing.a \
129         $(LIBKECCAK_TINY) \
130         $(LIBDONNA)
131 endif
133 # All static libraries used to link tor.
134 TOR_INTERNAL_LIBS = \
135         src/core/libtor-app.a \
136         src/lib/libtor-compress.a \
137         src/lib/libtor-evloop.a \
138         $(TOR_CRYPTO_LIBS) \
139         $(TOR_UTIL_LIBS) \
140         src/trunnel/libor-trunnel.a \
141         src/lib/libtor-trace.a
143 libtor.a: $(TOR_INTERNAL_LIBS)
144         $(AM_V_AR) export AR="$(AR)"; \
145         export ARFLAGS="$(ARFLAGS)"; \
146         export RANLIB="$(RANLIB)"; \
147         $(top_srcdir)/scripts/build/combine_libs libtor.a $(TOR_INTERNAL_LIBS)
149 MOSTLYCLEANFILES += libtor.a
151 # Variants of the above for linking the testing variant of tor (for coverage
152 # and tests)
153 if UNITTESTS_ENABLED
154 TOR_INTERNAL_TESTING_LIBS = \
155         src/core/libtor-app-testing.a \
156         src/lib/libtor-compress-testing.a \
157         src/lib/libtor-evloop-testing.a \
158         $(TOR_CRYPTO_TESTING_LIBS) \
159         $(TOR_UTIL_TESTING_LIBS) \
160         src/trunnel/libor-trunnel-testing.a \
161         src/lib/libtor-trace.a
163 src/test/libtor-testing.a: $(TOR_INTERNAL_TESTING_LIBS)
164         $(AM_V_AR) export AR="$(AR)"; \
165         export ARFLAGS="$(ARFLAGS)"; \
166         export RANLIB="$(RANLIB)"; \
167         $(top_srcdir)/scripts/build/combine_libs src/test/libtor-testing.a $(TOR_INTERNAL_TESTING_LIBS)
169 MOSTLYCLEANFILES += src/test/libtor-testing.a
170 endif
172 TOR_LDFLAGS_CRYPTLIB=@TOR_LDFLAGS_openssl@
173 TOR_LIBS_CRYPTLIB=@TOR_OPENSSL_LIBS@
174 TOR_CFLAGS_CRYPTLIB=
175 if USE_NSS
176 TOR_CFLAGS_CRYPTLIB+=@NSS_CFLAGS@
177 TOR_LIBS_CRYPTLIB+=@NSS_LIBS@
178 endif
180 # All libraries used to link tor-cov
182 include src/include.am
183 include doc/include.am
184 include contrib/include.am
186 manpages: $(nodist_man1_MANS)
188 EXTRA_DIST+= \
189         ChangeLog                                                       \
190         CONTRIBUTING                                                    \
191         CODE_OF_CONDUCT                                                 \
192         INSTALL                                                         \
193         LICENSE                                                         \
194         Makefile.nmake                                                  \
195         README                                                          \
196         ReleaseNotes                                                    \
197         scripts/build/combine_libs                                      \
198         scripts/maint/checkIncludes.py                                  \
199         scripts/maint/checkSpace.pl                                     \
200         scripts/maint/checkSpaceTest.sh                                 \
201         scripts/maint/checkspace_tests/dubious.c                        \
202         scripts/maint/checkspace_tests/dubious.h                        \
203         scripts/maint/checkspace_tests/expected.txt                     \
204         scripts/maint/checkspace_tests/good_guard.h                     \
205         scripts/maint/checkspace_tests/same_guard.h                     \
206         scripts/maint/checkspace_tests/subdir/dubious.c                 \
207         scripts/maint/checkShellScripts.sh                              \
208         scripts/maint/practracker/README                                \
209         scripts/maint/practracker/exceptions.txt                        \
210         scripts/maint/practracker/includes.py                           \
211         scripts/maint/practracker/metrics.py                            \
212         scripts/maint/practracker/practracker.py                        \
213         scripts/maint/practracker/practracker_tests.py                  \
214         scripts/maint/practracker/problem.py                            \
215         scripts/maint/practracker/testdata/.may_include                 \
216         scripts/maint/practracker/testdata/a.c                          \
217         scripts/maint/practracker/testdata/b.c                          \
218         scripts/maint/practracker/testdata/ex0-expected.txt             \
219         scripts/maint/practracker/testdata/ex0.txt                      \
220         scripts/maint/practracker/testdata/ex1-expected.txt             \
221         scripts/maint/practracker/testdata/ex1.txt                      \
222         scripts/maint/practracker/testdata/ex1-overbroad-expected.txt   \
223         scripts/maint/practracker/testdata/ex1-regen-expected.txt       \
224         scripts/maint/practracker/testdata/ex1-regen-overbroad-expected.txt \
225         scripts/maint/practracker/testdata/ex.txt                       \
226         scripts/maint/practracker/testdata/header.h                     \
227         scripts/maint/practracker/testdata/not_c_file                   \
228         scripts/maint/practracker/test_practracker.sh                   \
229         scripts/maint/practracker/util.py                               \
230         scripts/coccinelle/apply.sh                                     \
231         scripts/coccinelle/check_cocci_parse.sh                         \
232         scripts/coccinelle/exceptions.txt                               \
233         scripts/coccinelle/test-operator-cleanup                        \
234         scripts/coccinelle/tor-coccinelle.h                             \
235         scripts/coccinelle/try_parse.sh
237 ## This tells etags how to find mockable function definitions.
238 AM_ETAGSFLAGS=--regex='{c}/MOCK_IMPL([^,]+,\W*\([a-zA-Z0-9_]+\)\W*,/\1/s'
240 if COVERAGE_ENABLED
241 TEST_CFLAGS=-fno-inline -fprofile-arcs -ftest-coverage
242 if DISABLE_ASSERTS_IN_UNIT_TESTS
243 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE -DDISABLE_ASSERTS_IN_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
244 else
245 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE @TOR_MODULES_ALL_ENABLED@
246 endif
247 TEST_NETWORK_FLAGS=--coverage --hs-multi-client 1
248 else
249 TEST_CFLAGS=
250 TEST_CPPFLAGS=-DTOR_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
251 TEST_NETWORK_FLAGS=--hs-multi-client 1
252 endif
253 TEST_NETWORK_SHOW_WARNINGS_FOR_LAST_RUN_FLAGS=--quiet --only-warnings
255 if LIBFUZZER_ENABLED
256 TEST_CFLAGS += -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-div
257 # not "edge"
258 endif
260 TEST_NETWORK_ALL_LOG_DIR=$(top_builddir)/test_network_log
261 TEST_NETWORK_ALL_DRIVER_FLAGS=--color-tests yes
263 #install-data-local:
264 #       $(INSTALL) -m 755 -d $(LOCALSTATEDIR)/lib/tor
266 # Allows to override rpmbuild with rpmbuild-md5 from fedora-packager so that
267 # building for EL5 won't fail on https://bugzilla.redhat.com/show_bug.cgi?id=490613
268 RPMBUILD ?= rpmbuild
270 # Use automake's dist-gzip target to build the tarball
271 dist-rpm: dist-gzip
272         TIMESTAMP=$$(date +"%Y-%m-%d_%H.%M.%S");                                \
273         RPM_BUILD_DIR=$$(mktemp -d "/tmp/tor-rpm-build-$$TIMESTAMP-XXXX");      \
274         mkdir -p "$$RPM_BUILD_DIR"/{BUILD,RPMS,SOURCES/"tor-$(VERSION)",SPECS,SRPMS}; \
275         cp -fa "$(distdir).tar.gz" "$$RPM_BUILD_DIR"/SOURCES/;                  \
276         LIBS=-lrt $(RPMBUILD) -ba --define "_topdir $$RPM_BUILD_DIR" tor.spec;  \
277         cp -fa "$$RPM_BUILD_DIR"/SRPMS/* .;                                     \
278         cp -fa "$$RPM_BUILD_DIR"/RPMS/* .;                                      \
279         rm -rf "$$RPM_BUILD_DIR";                                               \
280         echo "RPM build finished";                                              \
281         #end of dist-rpm
283 .PHONY: doxygen
284 doxygen: Doxyfile
285         mkdir -p doc/doxygen
286         (cd "$(top_srcdir)" && doxygen "$(abs_top_builddir)/Doxyfile")
288 test: all
289         $(top_builddir)/src/test/test
291 shellcheck:
292         $(top_srcdir)/scripts/maint/checkShellScripts.sh
294 check-local:                                    \
295         check-spaces                            \
296         check-changes                           \
297         check-includes                          \
298         shellcheck
300 # test-network requires a copy of Chutney in $CHUTNEY_PATH.
301 # Chutney can be cloned from https://git.torproject.org/chutney.git .
302 .PHONY: need-chutney-path
303 need-chutney-path:
304         @if test ! -d "$$CHUTNEY_PATH"; then \
305                 echo '$$CHUTNEY_PATH was not set.'; \
306                 if test -d "$(top_srcdir)/../chutney" && \
307                    test -x "$(top_srcdir)/../chutney/chutney"; then \
308                         echo "Assuming test-network.sh will find" \
309                           "$(top_srcdir)/../chutney"; \
310                 else \
311                         echo; \
312                         echo "To run these tests," \
313                           "git clone" \
314                           "https://git.torproject.org/chutney.git ;" \
315                           "export CHUTNEY_PATH=\`pwd\`/chutney"; \
316                         exit 1; \
317                 fi \
318         fi
320 # Run some basic tests using automake's test-driver
321 .PHONY: test-network
322 # Hide directory path logs from submakes using $(MAKE) -s
323 test-network:
324         @$(MAKE) -s test-network-mkdir
325         @$(MAKE) -s test-network-clean
326         @$(MAKE) -s test-network-run \
327           ipv4_flavors="$(TEST_CHUTNEY_FLAVOR_QUICK)" \
328           ipv6_flavors="$(TEST_CHUTNEY_FLAVOR_QUICK_IPV6)"
329         @$(MAKE) -s test-network-results
331 # Run all available tests using automake's test-driver
332 .PHONY: test-network-all
333 # Hide directory path logs from submakes using $(MAKE) -s
334 test-network-all:
335         @$(MAKE) -s test-network-mkdir
336         @$(MAKE) -s test-network-clean
337         @$(MAKE) -s test-network-run \
338           ipv4_flavors="$(TEST_CHUTNEY_FLAVORS)" \
339           mixed_flavors="$(TEST_CHUTNEY_FLAVORS_MIXED)" \
340           ipv6_flavors="$(TEST_CHUTNEY_FLAVORS_IPV6)" \
341           ipv6_mixed_flavors="$(TEST_CHUTNEY_FLAVORS_IPV6_MIXED)"
342         @$(MAKE) -s test-network-results
344 # Run IPv4 and mixed tests using automake's test-driver
345 .PHONY: test-network-ipv4
346 # Hide directory path logs from submakes using $(MAKE) -s
347 test-network-ipv4:
348         @$(MAKE) -s test-network-mkdir
349         @$(MAKE) -s test-network-clean
350         @$(MAKE) -s test-network-run \
351           ipv4_flavors="$(TEST_CHUTNEY_FLAVORS)" \
352           mixed_flavors="$(TEST_CHUTNEY_FLAVORS_MIXED)"
353         @$(MAKE) -s test-network-results
355 # Run IPv6 tests using automake's test-driver
356 .PHONY: test-network-ipv6
357 # Hide directory path logs from submakes using $(MAKE) -s
358 test-network-ipv6:
359         @$(MAKE) -s test-network-mkdir
360         @$(MAKE) -s test-network-clean
361         @$(MAKE) -s test-network-run \
362           ipv6_flavors="$(TEST_CHUTNEY_FLAVORS_IPV6)" \
363           ipv6_mixed_flavors="$(TEST_CHUTNEY_FLAVORS_IPV6_MIXED)"
364         @$(MAKE) -s test-network-results
366 # Make the test network log directory, if it does not exist
367 .PHONY: test-network-mkdir
368 test-network-mkdir:
369         @mkdir -p "$(TEST_NETWORK_ALL_LOG_DIR)"
371 # Clean the test network log directory
372 .PHONY: test-network-clean
373 # We need to remove all matching files, so we can't quote the glob part of the
374 # rm arguments
375 test-network-clean:
376         rm -f "$(TEST_NETWORK_ALL_LOG_DIR)"/*.log \
377               "$(TEST_NETWORK_ALL_LOG_DIR)"/*.trs
379 # Run tests using automake's test-driver
380 # When checking if a set of test can be run, log the type of test, and the
381 # list of tests that will be run (or skipped).
383 # Run the IPv4 tests in $(ipv4_flavors), unconditionally
384 #   - tor relays and directory authorities require IPv4.
385 # Run the IPv6 tests in $(ipv6_flavors), if IPv6 is available
386 #   - only run IPv6 tests if we can ping6 or ping -6 ::1 (localhost)
387 #     we try the syntax for BSD ping6, Linux ping6, and Linux ping -6,
388 #     because they're incompatible
389 #   - some IPv6 tests may fail without an IPv6 DNS server
390 #     (see #16971 and #17011)
391 # Run the mixed tests in $(mixed_flavors), if a tor-stable binary is available
392 #   - only run mixed tests if we have a tor-stable binary
393 # Run the IPv6 mixed tests in $(ipv6_mixed_flavors), if IPv6 and mixed are run
394 #   - see above for details about IPv6 and mixed
395 .PHONY: test-network-run
396 # We need the word splitting in the "for" lines, so we can't quote
397 # $(skip_flavors) or $(flavors)
398 test-network-run: need-chutney-path test-driver $(TESTING_TOR_BINARY) src/tools/tor-gencert
399         @flavors=""; \
400         skip_flavors=""; \
401         if test -n "$(ipv4_flavors)"; then \
402                 echo "Running IPv4 flavors: $(ipv4_flavors)."; \
403                 flavors="$$flavors $(ipv4_flavors)"; \
404         fi; \
405         test_network_ipv6=false; \
406         if test -n "$(ipv6_flavors)" || \
407            test -n "$(ipv6_mixed_flavors)"; then \
408                 if ping6 -q -c 1 -o   ::1 >/dev/null 2>&1 || \
409                    ping6 -q -c 1 -W 1 ::1 >/dev/null 2>&1 || \
410                    ping  -6 -c 1 -W 1 ::1 >/dev/null 2>&1; then \
411                         test_network_ipv6=true; \
412                 fi; \
413         fi; \
414         if test -n "$(ipv6_flavors)"; then \
415                 if test "$$test_network_ipv6" = "true"; then \
416                         echo "ping6 ::1 or ping ::1 succeeded, running IPv6" \
417                           "flavors: $(ipv6_flavors)."; \
418                         flavors="$$flavors $(ipv6_flavors)"; \
419                 else \
420                         echo "ping6 ::1 and ping ::1 failed, skipping IPv6" \
421                           "flavors: $(ipv6_flavors)."; \
422                         skip_flavors="$$skip_flavors $(ipv6_flavors)"; \
423                 fi; \
424         fi; \
425         test_network_mixed=false; \
426         if test -n "$(mixed_flavors)" || \
427            test -n "$(ipv6_mixed_flavors)"; then \
428                 if command -v tor-stable >/dev/null 2>&1; then \
429                         test_network_mixed=true; \
430                 fi; \
431         fi; \
432         if test -n "$(mixed_flavors)"; then \
433                 if test "$$test_network_mixed" = "true"; then \
434                         echo "tor-stable found, running mixed flavors:" \
435                           "$(mixed_flavors)."; \
436                         flavors="$$flavors $(mixed_flavors)"; \
437                 else \
438                         echo "tor-stable not found, skipping mixed flavors:" \
439                           "$(mixed_flavors)."; \
440                         skip_flavors="$$skip_flavors $(mixed_flavors)"; \
441                 fi; \
442         fi; \
443         if test -n "$(ipv6_mixed_flavors)"; then \
444                 if test "$$test_network_ipv6" = "true" && \
445                    test "$$test_network_mixed" = "true"; then \
446                         echo "Running IPv6 mixed flavors:" \
447                           "$(ipv6_mixed_flavors)."; \
448                         flavors="$$flavors $(ipv6_mixed_flavors)"; \
449                 else \
450                         echo "Skipping IPv6 mixed flavors:" \
451                           "$(ipv6_mixed_flavors)."; \
452                         skip_flavors="$$skip_flavors $(ipv6_mixed_flavors)"; \
453                 fi; \
454         fi; \
455         for f in $$skip_flavors; do \
456                 echo "SKIP: $$f"; \
457         done; \
458         for f in $$flavors; do \
459                 $(SHELL) "$(top_srcdir)/test-driver" --test-name "$$f" \
460                   --log-file "$(TEST_NETWORK_ALL_LOG_DIR)/$$f.log" \
461                   --trs-file "$(TEST_NETWORK_ALL_LOG_DIR)/$$f.trs" \
462                   $(TEST_NETWORK_ALL_DRIVER_FLAGS) \
463                   "$(top_srcdir)/src/test/test-network.sh" \
464                     --flavor "$$f" $(TEST_NETWORK_FLAGS); \
465                 "$(top_srcdir)/src/test/test-network.sh" \
466                   $(TEST_NETWORK_SHOW_WARNINGS_FOR_LAST_RUN_FLAGS); \
467         done
469 # Print the results from automake's test-driver
470 #   - show tor warnings on the console after each network run
471 #     (otherwise, warnings go to the logs, and people don't see them unless
472 #     there is a network failure)
473 .PHONY: test-network-results
474 # We need to grep all matching files, so we can't quote the glob part of the
475 # grep arguments
476 test-network-results:
477         @echo \
478           "Log and result files are available in $(TEST_NETWORK_ALL_LOG_DIR)."
479         @! grep -q FAIL "$(TEST_NETWORK_ALL_LOG_DIR)"/*.trs
481 need-stem-path:
482         @if test ! -d "$$STEM_SOURCE_DIR"; then \
483                 echo '$$STEM_SOURCE_DIR was not set.'; echo; \
484                 echo "To run these tests, git clone https://git.torproject.org/stem.git/ ; export STEM_SOURCE_DIR=\`pwd\`/stem"; \
485                 exit 1; \
486         fi
488 test-stem: need-stem-path $(TESTING_TOR_BINARY)
489         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --integ --test control.controller --test control.base_controller --test process --log notice;
491 test-stem-full: need-stem-path $(TESTING_TOR_BINARY)
492         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL,ONLINE -v;
494 test-full:                                      \
495         need-stem-path                          \
496         need-chutney-path                       \
497         check                                   \
498         test-network                            \
499         test-stem
501 test-full-online:                               \
502         need-stem-path                          \
503         need-chutney-path                       \
504         check                                   \
505         test-network                            \
506         test-stem-full
508 # We can't delete the gcno files, because they are created when tor is compiled
509 reset-gcov:
510         rm -f $(top_builddir)/src/*/*.gcda $(top_builddir)/src/*/*/*.gcda \
511               $(top_builddir)/src/*/*.gcov $(top_builddir)/src/*/*/*.gcov
513 HTML_COVER_DIR=$(top_builddir)/coverage_html
514 coverage-html: all
515 if COVERAGE_ENABLED
516         test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
517         test -d "$(HTML_COVER_DIR)" || $(MKDIR_P) "$(HTML_COVER_DIR)"
518         lcov --rc lcov_branch_coverage=1 --directory $(top_builddir)/src --zerocounters
519         $(MAKE) reset-gcov
520         $(MAKE) check
521         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory $(top_builddir) --base-directory $(top_srcdir) --output-file "$(HTML_COVER_DIR)/lcov.tmp"
522         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
523         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
524 else
525         @printf "Not configured with --enable-coverage, run ./configure --enable-coverage\n"
526 endif
528 coverage-html-full: all
529         test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
530         test -d "$(HTML_COVER_DIR)" || mkdir -p "$(HTML_COVER_DIR)"
531         lcov --rc lcov_branch_coverage=1 --directory ./src --zerocounters
532         $(MAKE) reset-gcov
533         $(MAKE) check
534         $(MAKE) test-stem-full
535         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh
536         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh --flavor hs
537         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory . --output-file "$(HTML_COVER_DIR)/lcov.tmp"
538         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
539         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
541 # For scripts: avoid src/ext and src/trunnel.
542 # Keep these lists consistent:
543 #   - OWNED_TOR_C_FILES in Makefile.am
544 #   - CHECK_FILES in pre-commit.git-hook and pre-push.git-hook
545 #   - try_parse in check_cocci_parse.sh
546 OWNED_TOR_C_FILES=\
547                 $(top_srcdir)/src/lib/*/*.[ch] \
548                 $(top_srcdir)/src/core/*/*.[ch] \
549                 $(top_srcdir)/src/feature/*/*.[ch] \
550                 $(top_srcdir)/src/app/*/*.[ch] \
551                 $(top_srcdir)/src/test/*.[ch] \
552                 $(top_srcdir)/src/test/*/*.[ch] \
553                 $(top_srcdir)/src/tools/*.[ch]
555 check-spaces:
556 if USE_PERL
557         $(PERL) $(top_srcdir)/scripts/maint/checkSpace.pl -C \
558                 $(OWNED_TOR_C_FILES)
559 endif
561 check-includes:
562 if USEPYTHON
563         $(PYTHON) $(top_srcdir)/scripts/maint/practracker/includes.py $(top_srcdir)
564 endif
566 check-best-practices:
567 if USEPYTHON
568         @$(PYTHON) $(top_srcdir)/scripts/maint/practracker/practracker.py $(top_srcdir) $(TOR_PRACTRACKER_OPTIONS)
569 endif
571 check-cocci:
572         VERBOSE=1 $(top_srcdir)/scripts/coccinelle/check_cocci_parse.sh $(OWNED_TOR_C_FILES)
574 practracker-regen:
575         $(PYTHON) $(top_srcdir)/scripts/maint/practracker/practracker.py --regen $(top_srcdir)
577 check-docs: all
578         $(PERL) $(top_builddir)/scripts/maint/checkOptionDocs.pl
580 check-logs:
581         $(top_srcdir)/scripts/maint/checkLogs.pl \
582                 $(top_srcdir)/src/*/*.[ch] | sort -n
584 .PHONY: check-typos
585 check-typos:
586         @if test -x "`which misspell 2>&1;true`"; then \
587                 echo "Checking for Typos ..."; \
588                 (misspell \
589                         $(top_srcdir)/src/[^e]*/*.[ch] \
590                         $(top_srcdir)/doc \
591                         $(top_srcdir)/contrib \
592                         $(top_srcdir)/scripts \
593                         $(top_srcdir)/README \
594                         $(top_srcdir)/ChangeLog \
595                         $(top_srcdir)/INSTALL \
596                         $(top_srcdir)/ReleaseNotes \
597                         $(top_srcdir)/LICENSE); \
598         else \
599                 echo "Tor can use misspell to check for typos."; \
600                 echo "It seems that you don't have misspell installed."; \
601                 echo "You can install the latest version of misspell here: https://github.com/client9/misspell#install"; \
602         fi
604 .PHONY: rustfmt
605 rustfmt:
606 if USE_RUST
607         @if test -x "`which cargo-fmt 2>&1;true`"; then \
608                 echo "Formatting Rust code ..."; \
609                 (cd "$(top_srcdir)/src/rust" && cargo fmt --all --); \
610         else \
611                 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
612                 echo "However, it seems that you don't have rustfmt installed."; \
613                 printf "You can install rustfmt by following the directions here:"; \
614                 echo " https://github.com/rust-lang-nursery/rustfmt"; \
615         fi
616 endif
618 .PHONY: check-rustfmt
619 check-rustfmt:
620 if USE_RUST
621         @if test -x "`which cargo-fmt 2>&1;true`"; then \
622                 printf "Running rustfmt..."; \
623                 (cd "$(top_srcdir)/src/rust" && cargo fmt --all -- --check && echo "done.") || \
624                 (echo "**************** check-rustfmt failed. ****************"; \
625                  echo "   Run \`make rustfmt\` to apply the above changes."; \
626                  exit 1); \
627         else \
628                 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
629                 echo "However, it seems that you don't have rustfmt installed."; \
630                 printf "You can install rustfmt by following the directions here:"; \
631                 echo " https://github.com/rust-lang-nursery/rustfmt"; \
632         fi
633 endif
635 .PHONY: clippy
636 clippy:
637 if USE_RUST
638         @if test -x "`which cargo-clippy 2>&1;true`"; then \
639                 echo "Running cargo clippy ..."; \
640                 echo "Prepare yourself for the onslaught of suggestions ..."; \
641                 (cd "$(top_srcdir)/src/rust" && cargo clippy); \
642         else \
643                 echo "Tor can use clippy to lint Rust code."; \
644                 echo "However, it seems that you don't have clippy installed."; \
645                 echo "You can install the latest version of clippy by following the directions here: https://github.com/rust-lang-nursery/rust-clippy"; \
646         fi
647 endif
649 .PHONY: check-changes
650 check-changes:
651 if USEPYTHON
652         @if test -d "$(top_srcdir)/changes"; then \
653                 PACKAGE_VERSION=$(PACKAGE_VERSION) $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \
654                 fi
655 endif
657 .PHONY: update-versions
658 update-versions:
659         abs_top_srcdir="$(abs_top_srcdir)" $(PYTHON) $(top_srcdir)/scripts/maint/update_versions.py
661 .PHONY: callgraph
662 callgraph:
663         cd $(top_builddir); $(abs_top_srcdir)/scripts/maint/run_calltool.sh
665 version:
666         @echo "Tor @VERSION@"
667         @if test -d "$(top_srcdir)/.git" && test -x "`which git 2>&1;true`"; then \
668            echo -n "git: " ;\
669            (cd "$(top_srcdir)" && git rev-parse --short=16 HEAD); \
670         fi
672 .PHONY: autostyle-ifdefs
673 autostyle-ifdefs:
674         $(PYTHON) $(top_srcdir)/scripts/maint/annotate_ifdef_directives.py $(OWNED_TOR_C_FILES)
676 .PHONY: autostyle-ifdefs
677 autostyle-operators:
678         $(PERL) $(top_srcdir)/scripts/coccinelle/test-operator-cleanup $(OWNED_TOR_C_FILES)
680 .PHONY: rectify-includes
681 rectify-includes:
682         cd $(top_srcdir); $(PYTHON) $(abs_top_srcdir)/scripts/maint/rectify_include_paths.py
684 .PHONY: update-copyright
685 update-copyright:
686         $(PERL) $(top_srcdir)/scripts/maint/updateCopyright.pl $(OWNED_TOR_C_FILES)
688 .PHONY: autostyle
689 autostyle: update-versions rustfmt autostyle-ifdefs rectify-includes
691 mostlyclean-local:
692         rm -f $(top_builddir)/src/*/*.gc{da,no} $(top_builddir)/src/*/*/*.gc{da,no}
693         rm -rf $(HTML_COVER_DIR)
694         rm -rf $(top_builddir)/doc/doxygen
695         rm -rf $(TEST_NETWORK_ALL_LOG_DIR)
697 clean-local:
698         rm -rf $(top_builddir)/src/rust/target
699         rm -rf $(top_builddir)/src/rust/.cargo/registry
701 if USE_RUST
702 distclean-local: distclean-rust
703 endif
705 # This relies on some internal details of how automake implements
706 # distcheck.  We check two directories because automake-1.15 changed
707 # from $(distdir)/_build to $(distdir)/_build/sub.
708 show-distdir-testlog:
709         @if test -d "$(distdir)/_build/sub"; then \
710           cat $(distdir)/_build/sub/$(TEST_SUITE_LOG); \
711         else \
712           cat $(distdir)/_build/$(TEST_SUITE_LOG); fi
714 # Similarly, this relies on automake internals to run file on an
715 # intermittent core file whose provenance is not known to us.  See
716 # ticket 26787.
717 show-distdir-core:
718         @if test -d "$(distdir)/_build/sub"; then \
719           file $(distdir)/_build/sub/core ; \
720         else \
721           file $(distdir)/_build/core; fi
723 show-libs:
724         @echo libtor.a
726 show-testing-libs:
727         @echo src/test/libtor-testing.a
729 # Note here that we hardcode this -j2 because if the user would pass too many
730 # cores, bear actually chockes and dies :S. For this to work, a make clean
731 # needs to be done else bear will miss some compile flags.
732 lsp:
733         @if test -x "`which bear 2>&1;true`"; then \
734                 echo "Generating LSP compile_commands.json. Might take few minutes..."; \
735                 $(MAKE) clean 2>&1 >/dev/null; \
736                 bear >/dev/null 2>&1 -- $(MAKE) -j2 2>&1 >/dev/null; \
737                 echo "Generating .ccls file..."; \
738                 ./scripts/maint/gen_ccls_file.sh \
739         else \
740                 echo "No bear command found. On debian, apt install bear"; \
741         fi