Merge branch 'maint-0.3.5' into release-0.3.5
[tor.git] / Makefile.am
bloba868be7362b9470606ce2a4cb21c9abb8b5b46e9
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 bin_SCRIPTS=
18 AM_CPPFLAGS=\
19         -I$(top_srcdir)/src \
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@
25 SHELL=@SHELL@
27 if COVERAGE_ENABLED
28 TESTING_TOR_BINARY=$(top_builddir)/src/app/tor-cov$(EXEEXT)
29 else
30 TESTING_TOR_BINARY=$(top_builddir)/src/app/tor$(EXEEXT)
31 endif
33 if USE_RUST
34 ## this MUST be $(), otherwise am__DEPENDENCIES will not track it
35 rust_ldadd=$(top_builddir)/$(TOR_RUST_LIB_PATH) \
36         $(TOR_RUST_EXTRA_LIBS)
37 else
38 rust_ldadd=
39 endif
41 # "Common" libraries used to link tor's utility code.
42 TOR_UTIL_LIBS = \
43         src/lib/libtor-geoip.a \
44         src/lib/libtor-process.a \
45         src/lib/libtor-time.a \
46         src/lib/libtor-fs.a \
47         src/lib/libtor-encoding.a \
48         src/lib/libtor-sandbox.a \
49         src/lib/libtor-container.a \
50         src/lib/libtor-net.a \
51         src/lib/libtor-thread.a \
52         src/lib/libtor-memarea.a \
53         src/lib/libtor-math.a \
54         src/lib/libtor-meminfo.a \
55         src/lib/libtor-osinfo.a \
56         src/lib/libtor-log.a \
57         src/lib/libtor-lock.a \
58         src/lib/libtor-fdio.a \
59         src/lib/libtor-string.a \
60         src/lib/libtor-term.a \
61         src/lib/libtor-smartlist-core.a \
62         src/lib/libtor-malloc.a \
63         src/lib/libtor-wallclock.a \
64         src/lib/libtor-err.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
69 # and tests)
70 if UNITTESTS_ENABLED
71 TOR_UTIL_TESTING_LIBS = \
72         src/lib/libtor-geoip-testing.a \
73         src/lib/libtor-process-testing.a \
74         src/lib/libtor-time-testing.a \
75         src/lib/libtor-fs-testing.a \
76         src/lib/libtor-encoding-testing.a \
77         src/lib/libtor-sandbox-testing.a \
78         src/lib/libtor-container-testing.a \
79         src/lib/libtor-net-testing.a \
80         src/lib/libtor-thread-testing.a \
81         src/lib/libtor-memarea-testing.a \
82         src/lib/libtor-math-testing.a \
83         src/lib/libtor-meminfo-testing.a \
84         src/lib/libtor-osinfo-testing.a \
85         src/lib/libtor-term-testing.a \
86         src/lib/libtor-log-testing.a \
87         src/lib/libtor-lock-testing.a \
88         src/lib/libtor-fdio-testing.a \
89         src/lib/libtor-string-testing.a \
90         src/lib/libtor-smartlist-core-testing.a \
91         src/lib/libtor-malloc-testing.a \
92         src/lib/libtor-wallclock-testing.a \
93         src/lib/libtor-err-testing.a \
94         src/lib/libtor-intmath.a \
95         src/lib/libtor-ctime-testing.a
96 endif
98 # Internal crypto libraries used in Tor
99 TOR_CRYPTO_LIBS = \
100         src/lib/libtor-tls.a \
101         src/lib/libtor-crypt-ops.a \
102         $(LIBKECCAK_TINY) \
103         $(LIBDONNA)
105 # Variants of the above for linking the testing variant of tor (for coverage
106 # and tests)
107 if UNITTESTS_ENABLED
108 TOR_CRYPTO_TESTING_LIBS = \
109         src/lib/libtor-tls-testing.a \
110         src/lib/libtor-crypt-ops-testing.a \
111         $(LIBKECCAK_TINY) \
112         $(LIBDONNA)
113 endif
115 # All static libraries used to link tor.
116 TOR_INTERNAL_LIBS = \
117         src/core/libtor-app.a \
118         src/lib/libtor-compress.a \
119         src/lib/libtor-evloop.a \
120         $(TOR_CRYPTO_LIBS) \
121         $(TOR_UTIL_LIBS) \
122         src/trunnel/libor-trunnel.a \
123         src/lib/libtor-trace.a
125 # Variants of the above for linking the testing variant of tor (for coverage
126 # and tests)
127 if UNITTESTS_ENABLED
128 TOR_INTERNAL_TESTING_LIBS = \
129         src/core/libtor-app-testing.a \
130         src/lib/libtor-compress-testing.a \
131         src/lib/libtor-evloop-testing.a \
132         $(TOR_CRYPTO_TESTING_LIBS) \
133         $(TOR_UTIL_TESTING_LIBS) \
134         src/trunnel/libor-trunnel-testing.a \
135         src/lib/libtor-trace.a
136 endif
138 TOR_LDFLAGS_CRYPTLIB=@TOR_LDFLAGS_openssl@
139 TOR_LIBS_CRYPTLIB=@TOR_OPENSSL_LIBS@
140 TOR_CFLAGS_CRYPTLIB=
141 if USE_NSS
142 TOR_CFLAGS_CRYPTLIB+=@NSS_CFLAGS@
143 TOR_LIBS_CRYPTLIB+=@NSS_LIBS@
144 endif
146 # All libraries used to link tor-cov
148 include src/include.am
149 include doc/include.am
150 include contrib/include.am
152 manpages: $(nodist_man1_MANS)
154 EXTRA_DIST+= \
155         ChangeLog                                       \
156         CONTRIBUTING                                    \
157         CODE_OF_CONDUCT                                 \
158         INSTALL                                         \
159         LICENSE                                         \
160         Makefile.nmake                                  \
161         README                                          \
162         ReleaseNotes                                    \
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'
169 if COVERAGE_ENABLED
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@
173 else
174 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE @TOR_MODULES_ALL_ENABLED@
175 endif
176 TEST_NETWORK_FLAGS=--coverage --hs-multi-client 1
177 else
178 TEST_CFLAGS=
179 TEST_CPPFLAGS=-DTOR_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
180 TEST_NETWORK_FLAGS=--hs-multi-client 1
181 endif
182 TEST_NETWORK_WARNING_FLAGS=--quiet --only-warnings
184 if LIBFUZZER_ENABLED
185 TEST_CFLAGS += -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-div
186 # not "edge"
187 endif
189 TEST_NETWORK_ALL_LOG_DIR=$(top_builddir)/test_network_log
190 TEST_NETWORK_ALL_DRIVER_FLAGS=--color-tests yes
192 #install-data-local:
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
197 RPMBUILD ?= rpmbuild
199 # Use automake's dist-gzip target to build the tarball
200 dist-rpm: dist-gzip
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";                                              \
210         #end of dist-rpm
212 doxygen:
213         doxygen && cd doc/doxygen/latex && make
215 test: all
216         $(top_builddir)/src/test/test
218 check-local: check-spaces check-changes check-includes
220 need-chutney-path:
221         @if test ! -d "$$CHUTNEY_PATH"; then \
222                 echo '$$CHUTNEY_PATH was not set.'; \
223                 if test -d $(top_srcdir)/../chutney -a -x $(top_srcdir)/../chutney/chutney; then \
224                         echo "Assuming test-network.sh will find" $(top_srcdir)/../chutney; \
225                 else \
226                         echo; \
227                         echo "To run these tests, git clone https://git.torproject.org/chutney.git ; export CHUTNEY_PATH=\`pwd\`/chutney"; \
228                         exit 1; \
229                 fi \
230         fi
232 # Note that test-network requires a copy of Chutney in $CHUTNEY_PATH.
233 # Chutney can be cloned from https://git.torproject.org/chutney.git .
234 test-network: need-chutney-path $(TESTING_TOR_BINARY) src/tools/tor-gencert
235         $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_FLAGS)
237 # Run all available tests using automake's test-driver
238 # only run IPv6 tests if we can ping6 ::1 (localhost)
239 # only run IPv6 tests if we can ping ::1 (localhost)
240 # some IPv6 tests will fail without an IPv6 DNS server (see #16971 and #17011)
241 # only run mixed tests if we have a tor-stable binary
242 # Try the syntax for BSD ping6, Linux ping6, and Linux ping -6,
243 # because they're incompatible
244 test-network-all: need-chutney-path test-driver $(TESTING_TOR_BINARY) src/tools/tor-gencert
245         mkdir -p $(TEST_NETWORK_ALL_LOG_DIR)
246         rm -f $(TEST_NETWORK_ALL_LOG_DIR)/*.log $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
247         @flavors="$(TEST_CHUTNEY_FLAVORS)"; \
248         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 \
249                 echo "ping6 ::1 or ping ::1 succeeded, running IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
250                 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
251         else \
252                 echo "ping6 ::1 and ping ::1 failed, skipping IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
253                 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
254         fi; \
255         if command -v tor-stable >/dev/null 2>&1; then \
256                 echo "tor-stable found, running mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
257                 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
258         else \
259                 echo "tor-stable not found, skipping mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
260                 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
261         fi; \
262         for f in $$skip_flavors; do \
263                 echo "SKIP: $$f"; \
264         done; \
265         for f in $$flavors; do \
266                 $(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); \
267                 $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_WARNING_FLAGS); \
268         done; \
269         echo "Log and result files are available in $(TEST_NETWORK_ALL_LOG_DIR)."; \
270         ! grep -q FAIL $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
272 need-stem-path:
273         @if test ! -d "$$STEM_SOURCE_DIR"; then \
274                 echo '$$STEM_SOURCE_DIR was not set.'; echo; \
275                 echo "To run these tests, git clone https://git.torproject.org/stem.git/ ; export STEM_SOURCE_DIR=\`pwd\`/stem"; \
276                 exit 1; \
277         fi
279 test-stem: need-stem-path $(TESTING_TOR_BINARY)
280         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --integ --test control.controller --test control.base_controller --test process --log notice;
282 test-stem-full: need-stem-path $(TESTING_TOR_BINARY)
283         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL,ONLINE -v;
285 test-full: need-stem-path need-chutney-path check test-network test-stem
287 test-full-online: need-stem-path need-chutney-path check test-network test-stem-full
289 # We can't delete the gcno files, because they are created when tor is compiled
290 reset-gcov:
291         rm -f $(top_builddir)/src/*/*.gcda $(top_builddir)/src/*/*/*.gcda \
292               $(top_builddir)/src/*/*.gcov $(top_builddir)/src/*/*/*.gcov
294 HTML_COVER_DIR=$(top_builddir)/coverage_html
295 coverage-html: all
296 if COVERAGE_ENABLED
297         test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
298         test -d "$(HTML_COVER_DIR)" || $(MKDIR_P) "$(HTML_COVER_DIR)"
299         lcov --rc lcov_branch_coverage=1 --directory $(top_builddir)/src --zerocounters
300         $(MAKE) reset-gcov
301         $(MAKE) check
302         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory $(top_builddir) --base-directory $(top_srcdir) --output-file "$(HTML_COVER_DIR)/lcov.tmp"
303         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
304         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
305 else
306         @printf "Not configured with --enable-coverage, run ./configure --enable-coverage\n"
307 endif
309 coverage-html-full: all
310         test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
311         test -d "$(HTML_COVER_DIR)" || mkdir -p "$(HTML_COVER_DIR)"
312         lcov --rc lcov_branch_coverage=1 --directory ./src --zerocounters
313         $(MAKE) reset-gcov
314         $(MAKE) check
315         $(MAKE) test-stem-full
316         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh
317         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh --flavor hs
318         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory . --output-file "$(HTML_COVER_DIR)/lcov.tmp"
319         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
320         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
322 # Avoid strlcpy.c, strlcat.c, aes.c, OpenBSD_malloc_Linux.c, sha256.c,
323 # tinytest*.[ch]
324 check-spaces:
325 if USE_PERL
326         $(PERL) $(top_srcdir)/scripts/maint/checkSpace.pl -C \
327                 $(top_srcdir)/src/lib/*/*.[ch] \
328                 $(top_srcdir)/src/core/*/*.[ch] \
329                 $(top_srcdir)/src/feature/*/*.[ch] \
330                 $(top_srcdir)/src/app/*/*.[ch] \
331                 $(top_srcdir)/src/test/*.[ch] \
332                 $(top_srcdir)/src/test/*/*.[ch] \
333                 $(top_srcdir)/src/tools/*.[ch]
334 endif
336 check-includes:
337 if USEPYTHON
338         $(PYTHON) $(top_srcdir)/scripts/maint/checkIncludes.py
339 endif
341 check-docs: all
342         $(PERL) $(top_builddir)/scripts/maint/checkOptionDocs.pl
344 check-logs:
345         $(top_srcdir)/scripts/maint/checkLogs.pl \
346                 $(top_srcdir)/src/*/*.[ch] | sort -n
348 .PHONY: check-typos
349 check-typos:
350         @if test -x "`which misspell 2>&1;true`"; then \
351                 echo "Checking for Typos ..."; \
352                 (misspell \
353                         $(top_srcdir)/src/[^e]*/*.[ch] \
354                         $(top_srcdir)/doc \
355                         $(top_srcdir)/contrib \
356                         $(top_srcdir)/scripts \
357                         $(top_srcdir)/README \
358                         $(top_srcdir)/ChangeLog \
359                         $(top_srcdir)/INSTALL \
360                         $(top_srcdir)/ReleaseNotes \
361                         $(top_srcdir)/LICENSE); \
362         else \
363                 echo "Tor can use misspell to check for typos."; \
364                 echo "It seems that you don't have misspell installed."; \
365                 echo "You can install the latest version of misspell here: https://github.com/client9/misspell#install"; \
366         fi
368 .PHONY: rustfmt
369 rustfmt:
370 if USE_RUST
371         @if test -x "`which cargo-fmt 2>&1;true`"; then \
372                 echo "Formatting Rust code ..."; \
373                 (cd "$(top_srcdir)/src/rust" && cargo fmt --all --); \
374         else \
375                 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
376                 echo "However, it seems that you don't have rustfmt installed."; \
377                 printf "You can install rustfmt by following the directions here:"; \
378                 echo " https://github.com/rust-lang-nursery/rustfmt"; \
379         fi
380 endif
382 .PHONY: check-rustfmt
383 check-rustfmt:
384 if USE_RUST
385         @if test -x "`which cargo-fmt 2>&1;true`"; then \
386                 printf "Running rustfmt..."; \
387                 (cd "$(top_srcdir)/src/rust" && cargo fmt --all -- --check && echo "done.") || \
388                 (echo "**************** check-rustfmt failed. ****************"; \
389                  echo "   Run \`make rustfmt\` to apply the above changes."; \
390                  exit 1); \
391         else \
392                 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
393                 echo "However, it seems that you don't have rustfmt installed."; \
394                 printf "You can install rustfmt by following the directions here:"; \
395                 echo " https://github.com/rust-lang-nursery/rustfmt"; \
396         fi
397 endif
399 .PHONY: clippy
400 clippy:
401 if USE_RUST
402         @if test -x "`which cargo-clippy 2>&1;true`"; then \
403                 echo "Running cargo clippy ..."; \
404                 echo "Prepare yourself for the onslaught of suggestions ..."; \
405                 (cd "$(top_srcdir)/src/rust" && cargo clippy); \
406         else \
407                 echo "Tor can use clippy to lint Rust code."; \
408                 echo "However, it seems that you don't have clippy installed."; \
409                 echo "You can install the latest version of clippy by following the directions here: https://github.com/rust-lang-nursery/rust-clippy"; \
410         fi
411 endif
413 .PHONY: check-changes
414 check-changes:
415 if USEPYTHON
416         @if test -d "$(top_srcdir)/changes"; then \
417                 $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \
418                 fi
419 endif
421 .PHONY: update-versions
422 update-versions:
423         $(PERL) $(top_builddir)/scripts/maint/updateVersions.pl
425 .PHONY: callgraph
426 callgraph:
427         $(top_builddir)/scripts/maint/run_calltool.sh
429 version:
430         @echo "Tor @VERSION@"
431         @if test -d "$(top_srcdir)/.git" && test -x "`which git 2>&1;true`"; then \
432            echo -n "git: " ;\
433            (cd "$(top_srcdir)" && git rev-parse --short=16 HEAD); \
434         fi
436 mostlyclean-local:
437         rm -f $(top_builddir)/src/*/*.gc{da,no} $(top_builddir)/src/*/*/*.gc{da,no}
438         rm -rf $(HTML_COVER_DIR)
439         rm -rf $(top_builddir)/doc/doxygen
440         rm -rf $(TEST_NETWORK_ALL_LOG_DIR)
442 clean-local:
443         rm -rf $(top_builddir)/src/rust/target
444         rm -rf $(top_builddir)/src/rust/.cargo/registry
446 if USE_RUST
447 distclean-local: distclean-rust
448 endif
450 # This relies on some internal details of how automake implements
451 # distcheck.  We check two directories because automake-1.15 changed
452 # from $(distdir)/_build to $(distdir)/_build/sub.
453 show-distdir-testlog:
454         @if test -d "$(distdir)/_build/sub"; then \
455           cat $(distdir)/_build/sub/$(TEST_SUITE_LOG); \
456         else \
457           cat $(distdir)/_build/$(TEST_SUITE_LOG); fi
459 # Similarly, this relies on automake internals to run file on an
460 # intermittent core file whose provenance is not known to us.  See
461 # ticket 26787.
462 show-distdir-core:
463         @if test -d "$(distdir)/_build/sub"; then \
464           file $(distdir)/_build/sub/core ; \
465         else \
466           file $(distdir)/_build/core; fi
468 show-libs:
469         @echo $(TOR_INTERNAL_LIBS)
471 show-testing-libs:
472         @echo $(TOR_INTERNAL_TESTING_LIBS)