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
20 -I$(top_srcdir)/src/ext \
21 -I$(top_srcdir)/src/ext/trunnel \
22 -I$(top_srcdir)/src/trunnel
24 AM_CFLAGS=@TOR_SYSTEMD_CFLAGS@ @CFLAGS_BUGTRAP@ @TOR_LZMA_CFLAGS@ @TOR_ZSTD_CFLAGS@
28 TESTING_TOR_BINARY=$(top_builddir)/src/app/tor-cov$(EXEEXT)
30 TESTING_TOR_BINARY=$(top_builddir)/src/app/tor$(EXEEXT)
34 rust_ldadd=$(top_builddir)/$(TOR_RUST_LIB_PATH)
39 # "Common" libraries used to link tor's utility code.
41 src/lib/libtor-geoip.a \
42 src/lib/libtor-process.a \
43 src/lib/libtor-buf.a \
44 src/lib/libtor-time.a \
46 src/lib/libtor-encoding.a \
47 src/lib/libtor-sandbox.a \
48 src/lib/libtor-container.a \
49 src/lib/libtor-net.a \
50 src/lib/libtor-thread.a \
51 src/lib/libtor-memarea.a \
52 src/lib/libtor-math.a \
53 src/lib/libtor-meminfo.a \
54 src/lib/libtor-osinfo.a \
55 src/lib/libtor-log.a \
56 src/lib/libtor-lock.a \
57 src/lib/libtor-fdio.a \
58 src/lib/libtor-string.a \
59 src/lib/libtor-term.a \
60 src/lib/libtor-smartlist-core.a \
61 src/lib/libtor-malloc.a \
62 src/lib/libtor-wallclock.a \
63 src/lib/libtor-err.a \
64 src/lib/libtor-version.a \
65 src/lib/libtor-intmath.a \
66 src/lib/libtor-ctime.a
68 # Variants of the above for linking the testing variant of tor (for coverage
71 TOR_UTIL_TESTING_LIBS = \
72 src/lib/libtor-geoip-testing.a \
73 src/lib/libtor-process-testing.a \
74 src/lib/libtor-buf-testing.a \
75 src/lib/libtor-time-testing.a \
76 src/lib/libtor-fs-testing.a \
77 src/lib/libtor-encoding-testing.a \
78 src/lib/libtor-sandbox-testing.a \
79 src/lib/libtor-container-testing.a \
80 src/lib/libtor-net-testing.a \
81 src/lib/libtor-thread-testing.a \
82 src/lib/libtor-memarea-testing.a \
83 src/lib/libtor-math-testing.a \
84 src/lib/libtor-meminfo-testing.a \
85 src/lib/libtor-osinfo-testing.a \
86 src/lib/libtor-term-testing.a \
87 src/lib/libtor-log-testing.a \
88 src/lib/libtor-lock-testing.a \
89 src/lib/libtor-fdio-testing.a \
90 src/lib/libtor-string-testing.a \
91 src/lib/libtor-smartlist-core-testing.a \
92 src/lib/libtor-malloc-testing.a \
93 src/lib/libtor-wallclock-testing.a \
94 src/lib/libtor-err-testing.a \
95 src/lib/libtor-version-testing.a \
96 src/lib/libtor-intmath.a \
97 src/lib/libtor-ctime-testing.a
100 # Internal crypto libraries used in Tor
102 src/lib/libtor-tls.a \
103 src/lib/libtor-crypt-ops.a \
107 # Variants of the above for linking the testing variant of tor (for coverage
110 TOR_CRYPTO_TESTING_LIBS = \
111 src/lib/libtor-tls-testing.a \
112 src/lib/libtor-crypt-ops-testing.a \
117 # All static libraries used to link tor.
118 TOR_INTERNAL_LIBS = \
119 src/core/libtor-app.a \
120 src/lib/libtor-compress.a \
121 src/lib/libtor-evloop.a \
124 src/trunnel/libor-trunnel.a \
125 src/lib/libtor-trace.a
127 # Variants of the above for linking the testing variant of tor (for coverage
130 TOR_INTERNAL_TESTING_LIBS = \
131 src/core/libtor-app-testing.a \
132 src/lib/libtor-compress-testing.a \
133 src/lib/libtor-evloop-testing.a \
134 $(TOR_CRYPTO_TESTING_LIBS) \
135 $(TOR_UTIL_TESTING_LIBS) \
136 src/trunnel/libor-trunnel-testing.a \
137 src/lib/libtor-trace.a
140 TOR_LDFLAGS_CRYPTLIB=@TOR_LDFLAGS_openssl@
141 TOR_LIBS_CRYPTLIB=@TOR_OPENSSL_LIBS@
144 TOR_CFLAGS_CRYPTLIB+=@NSS_CFLAGS@
145 TOR_LIBS_CRYPTLIB+=@NSS_LIBS@
148 # All libraries used to link tor-cov
150 include src/include.am
151 include doc/include.am
152 include contrib/include.am
163 scripts/maint/checkIncludes.py \
164 scripts/maint/checkSpace.pl
166 ## This tells etags how to find mockable function definitions.
167 AM_ETAGSFLAGS=--regex='{c}/MOCK_IMPL([^,]+,\W*\([a-zA-Z0-9_]+\)\W*,/\1/s'
170 TEST_CFLAGS=-fno-inline -fprofile-arcs -ftest-coverage
171 if DISABLE_ASSERTS_IN_UNIT_TESTS
172 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE -DDISABLE_ASSERTS_IN_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
174 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE @TOR_MODULES_ALL_ENABLED@
176 TEST_NETWORK_FLAGS=--coverage --hs-multi-client 1
179 TEST_CPPFLAGS=-DTOR_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
180 TEST_NETWORK_FLAGS=--hs-multi-client 1
182 TEST_NETWORK_WARNING_FLAGS=--quiet --only-warnings
185 TEST_CFLAGS += -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-div
189 TEST_NETWORK_ALL_LOG_DIR=$(top_builddir)/test_network_log
190 TEST_NETWORK_ALL_DRIVER_FLAGS=--color-tests yes
193 # $(INSTALL) -m 755 -d $(LOCALSTATEDIR)/lib/tor
195 # Allows to override rpmbuild with rpmbuild-md5 from fedora-packager so that
196 # building for EL5 won't fail on https://bugzilla.redhat.com/show_bug.cgi?id=490613
199 # Use automake's dist-gzip target to build the tarball
201 TIMESTAMP=$$(date +"%Y-%m-%d_%H.%M.%S"); \
202 RPM_BUILD_DIR=$$(mktemp -d "/tmp/tor-rpm-build-$$TIMESTAMP-XXXX"); \
203 mkdir -p "$$RPM_BUILD_DIR"/{BUILD,RPMS,SOURCES/"tor-$(VERSION)",SPECS,SRPMS}; \
204 cp -fa "$(distdir).tar.gz" "$$RPM_BUILD_DIR"/SOURCES/; \
205 LIBS=-lrt $(RPMBUILD) -ba --define "_topdir $$RPM_BUILD_DIR" tor.spec; \
206 cp -fa "$$RPM_BUILD_DIR"/SRPMS/* .; \
207 cp -fa "$$RPM_BUILD_DIR"/RPMS/* .; \
208 rm -rf "$$RPM_BUILD_DIR"; \
209 echo "RPM build finished"; \
213 doxygen && cd doc/doxygen/latex && make
216 $(top_builddir)/src/test/test
219 # Only use shellcheck if it is present
220 if command -v shellcheck; then \
221 find $(top_srcdir)/scripts/ -name "*.sh" -exec shellcheck {} +; \
222 if [ -d "$(top_srcdir)/scripts/test" ]; then \
223 shellcheck $(top_srcdir)/scripts/test/cov-diff $(top_builddir)/scripts/test/coverage; \
227 check-local: check-spaces check-changes check-includes shellcheck
230 @if test ! -d "$$CHUTNEY_PATH"; then \
231 echo '$$CHUTNEY_PATH was not set.'; \
232 if test -d $(top_srcdir)/../chutney -a -x $(top_srcdir)/../chutney/chutney; then \
233 echo "Assuming test-network.sh will find" $(top_srcdir)/../chutney; \
236 echo "To run these tests, git clone https://git.torproject.org/chutney.git ; export CHUTNEY_PATH=\`pwd\`/chutney"; \
241 # Note that test-network requires a copy of Chutney in $CHUTNEY_PATH.
242 # Chutney can be cloned from https://git.torproject.org/chutney.git .
243 test-network: need-chutney-path $(TESTING_TOR_BINARY) src/tools/tor-gencert
244 $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_FLAGS)
246 # Run all available tests using automake's test-driver
247 # only run IPv6 tests if we can ping6 ::1 (localhost)
248 # only run IPv6 tests if we can ping ::1 (localhost)
249 # some IPv6 tests will fail without an IPv6 DNS server (see #16971 and #17011)
250 # only run mixed tests if we have a tor-stable binary
251 # Try the syntax for BSD ping6, Linux ping6, and Linux ping -6,
252 # because they're incompatible
253 test-network-all: need-chutney-path test-driver $(TESTING_TOR_BINARY) src/tools/tor-gencert
254 mkdir -p $(TEST_NETWORK_ALL_LOG_DIR)
255 rm -f $(TEST_NETWORK_ALL_LOG_DIR)/*.log $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
256 @flavors="$(TEST_CHUTNEY_FLAVORS)"; \
257 if ping6 -q -c 1 -o ::1 >/dev/null 2>&1 || ping6 -q -c 1 -W 1 ::1 >/dev/null 2>&1 || ping -6 -c 1 -W 1 ::1 >/dev/null 2>&1; then \
258 echo "ping6 ::1 or ping ::1 succeeded, running IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
259 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
261 echo "ping6 ::1 and ping ::1 failed, skipping IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
262 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
264 if command -v tor-stable >/dev/null 2>&1; then \
265 echo "tor-stable found, running mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
266 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
268 echo "tor-stable not found, skipping mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
269 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
271 for f in $$skip_flavors; do \
274 for f in $$flavors; do \
275 $(SHELL) $(top_srcdir)/test-driver --test-name $$f --log-file $(TEST_NETWORK_ALL_LOG_DIR)/$$f.log --trs-file $(TEST_NETWORK_ALL_LOG_DIR)/$$f.trs $(TEST_NETWORK_ALL_DRIVER_FLAGS) $(top_srcdir)/src/test/test-network.sh --flavor $$f $(TEST_NETWORK_FLAGS); \
276 $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_WARNING_FLAGS); \
278 echo "Log and result files are available in $(TEST_NETWORK_ALL_LOG_DIR)."; \
279 ! grep -q FAIL $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
282 @if test ! -d "$$STEM_SOURCE_DIR"; then \
283 echo '$$STEM_SOURCE_DIR was not set.'; echo; \
284 echo "To run these tests, git clone https://git.torproject.org/stem.git/ ; export STEM_SOURCE_DIR=\`pwd\`/stem"; \
288 test-stem: need-stem-path $(TESTING_TOR_BINARY)
289 @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --integ --log notice --target RUN_ALL;
291 test-stem-full: need-stem-path $(TESTING_TOR_BINARY)
292 @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL,ONLINE -v;
294 test-full: need-stem-path need-chutney-path check test-network test-stem
296 test-full-online: need-stem-path need-chutney-path check test-network test-stem-full
299 rm -f $(top_builddir)/src/*/*.gcda $(top_builddir)/src/*/*/*.gcda
301 HTML_COVER_DIR=$(top_builddir)/coverage_html
304 test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
305 test -d "$(HTML_COVER_DIR)" || $(MKDIR_P) "$(HTML_COVER_DIR)"
306 lcov --rc lcov_branch_coverage=1 --directory $(top_builddir)/src --zerocounters
309 lcov --capture --rc lcov_branch_coverage=1 --no-external --directory $(top_builddir) --base-directory $(top_srcdir) --output-file "$(HTML_COVER_DIR)/lcov.tmp"
310 lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
311 genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
313 @printf "Not configured with --enable-coverage, run ./configure --enable-coverage\n"
316 coverage-html-full: all
317 test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
318 test -d "$(HTML_COVER_DIR)" || mkdir -p "$(HTML_COVER_DIR)"
319 lcov --rc lcov_branch_coverage=1 --directory ./src --zerocounters
322 $(MAKE) test-stem-full
323 CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh
324 CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh --flavor hs
325 lcov --capture --rc lcov_branch_coverage=1 --no-external --directory . --output-file "$(HTML_COVER_DIR)/lcov.tmp"
326 lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
327 genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
329 # Avoid strlcpy.c, strlcat.c, aes.c, OpenBSD_malloc_Linux.c, sha256.c,
333 $(PERL) $(top_srcdir)/scripts/maint/checkSpace.pl -C \
334 $(top_srcdir)/src/lib/*/*.[ch] \
335 $(top_srcdir)/src/core/*/*.[ch] \
336 $(top_srcdir)/src/feature/*/*.[ch] \
337 $(top_srcdir)/src/app/*/*.[ch] \
338 $(top_srcdir)/src/test/*.[ch] \
339 $(top_srcdir)/src/test/*/*.[ch] \
340 $(top_srcdir)/src/tools/*.[ch]
345 $(PYTHON) $(top_srcdir)/scripts/maint/checkIncludes.py
349 $(PERL) $(top_builddir)/scripts/maint/checkOptionDocs.pl
352 $(top_srcdir)/scripts/maint/checkLogs.pl \
353 $(top_srcdir)/src/*/*.[ch] | sort -n
357 @if test -x "`which misspell 2>&1;true`"; then \
358 echo "Checking for Typos ..."; \
360 $(top_srcdir)/src/[^e]*/*.[ch] \
362 $(top_srcdir)/contrib \
363 $(top_srcdir)/scripts \
364 $(top_srcdir)/README \
365 $(top_srcdir)/ChangeLog \
366 $(top_srcdir)/INSTALL \
367 $(top_srcdir)/ReleaseNotes \
368 $(top_srcdir)/LICENSE); \
370 echo "Tor can use misspell to check for typos."; \
371 echo "It seems that you don't have misspell installed."; \
372 echo "You can install the latest version of misspell here: https://github.com/client9/misspell#install"; \
378 @if test -x "`which cargo-fmt 2>&1;true`"; then \
379 echo "Formatting Rust code ..."; \
380 (cd "$(top_srcdir)/src/rust" && cargo fmt --all --); \
382 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
383 echo "However, it seems that you don't have rustfmt installed."; \
384 printf "You can install rustfmt by following the directions here:"; \
385 echo " https://github.com/rust-lang-nursery/rustfmt"; \
389 .PHONY: check-rustfmt
392 @if test -x "`which cargo-fmt 2>&1;true`"; then \
393 printf "Running rustfmt..."; \
394 (cd "$(top_srcdir)/src/rust" && cargo fmt --all -- --check && echo "done.") || \
395 (echo "**************** check-rustfmt failed. ****************"; \
396 echo " Run \`make rustfmt\` to apply the above changes."; \
399 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
400 echo "However, it seems that you don't have rustfmt installed."; \
401 printf "You can install rustfmt by following the directions here:"; \
402 echo " https://github.com/rust-lang-nursery/rustfmt"; \
409 @if test -x "`which cargo-clippy 2>&1;true`"; then \
410 echo "Running cargo clippy ..."; \
411 echo "Prepare yourself for the onslaught of suggestions ..."; \
412 (cd "$(top_srcdir)/src/rust" && cargo clippy); \
414 echo "Tor can use clippy to lint Rust code."; \
415 echo "However, it seems that you don't have clippy installed."; \
416 echo "You can install the latest version of clippy by following the directions here: https://github.com/rust-lang-nursery/rust-clippy"; \
420 .PHONY: check-changes
423 @if test -d "$(top_srcdir)/changes"; then \
424 PACKAGE_VERSION=$(PACKAGE_VERSION) $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \
428 .PHONY: update-versions
430 abs_top_srcdir="$(abs_top_srcdir)" $(PYTHON) $(top_srcdir)/scripts/maint/update_versions.py
434 $(top_builddir)/scripts/maint/run_calltool.sh
437 @echo "Tor @VERSION@"
438 @if test -d "$(top_srcdir)/.git" && test -x "`which git 2>&1;true`"; then \
440 (cd "$(top_srcdir)" && git rev-parse --short=16 HEAD); \
444 rm -f $(top_builddir)/src/*/*.gc{da,no} $(top_builddir)/src/*/*/*.gc{da,no}
445 rm -rf $(HTML_COVER_DIR)
446 rm -rf $(top_builddir)/doc/doxygen
447 rm -rf $(TEST_NETWORK_ALL_LOG_DIR)
450 rm -rf $(top_builddir)/src/rust/target
451 rm -rf $(top_builddir)/src/rust/.cargo/registry
454 distclean-local: distclean-rust
457 # This relies on some internal details of how automake implements
458 # distcheck. We check two directories because automake-1.15 changed
459 # from $(distdir)/_build to $(distdir)/_build/sub.
460 show-distdir-testlog:
461 @if test -d "$(distdir)/_build/sub"; then \
462 cat $(distdir)/_build/sub/$(TEST_SUITE_LOG); \
464 cat $(distdir)/_build/$(TEST_SUITE_LOG); fi
466 # Similarly, this relies on automake internals to run file on an
467 # intermittent core file whose provenance is not known to us. See
470 @if test -d "$(distdir)/_build/sub"; then \
471 file $(distdir)/_build/sub/core ; \
473 file $(distdir)/_build/core; fi
476 @echo $(TOR_INTERNAL_LIBS)
479 @echo $(TOR_INTERNAL_TESTING_LIBS)