Tweak changes file: call this a major feature.
[tor.git] / Makefile.am
blob36a5dd2e9e9aecd2dc57b059f4c14104b0a1262d
1 # Copyright (c) 2001-2004, Roger Dingledine
2 # Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 # Copyright (c) 2007-2018, 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-process.a \
44         src/lib/libtor-time.a \
45         src/lib/libtor-fs.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-intmath.a \
65         src/lib/libtor-ctime.a
67 # Variants of the above for linking the testing variant of tor (for coverage
68 # and tests)
69 if UNITTESTS_ENABLED
70 TOR_UTIL_TESTING_LIBS = \
71         src/lib/libtor-process-testing.a \
72         src/lib/libtor-time-testing.a \
73         src/lib/libtor-fs-testing.a \
74         src/lib/libtor-encoding-testing.a \
75         src/lib/libtor-sandbox-testing.a \
76         src/lib/libtor-container-testing.a \
77         src/lib/libtor-net-testing.a \
78         src/lib/libtor-thread-testing.a \
79         src/lib/libtor-memarea-testing.a \
80         src/lib/libtor-math-testing.a \
81         src/lib/libtor-meminfo-testing.a \
82         src/lib/libtor-osinfo-testing.a \
83         src/lib/libtor-term-testing.a \
84         src/lib/libtor-log-testing.a \
85         src/lib/libtor-lock-testing.a \
86         src/lib/libtor-fdio-testing.a \
87         src/lib/libtor-string-testing.a \
88         src/lib/libtor-smartlist-core-testing.a \
89         src/lib/libtor-malloc-testing.a \
90         src/lib/libtor-wallclock-testing.a \
91         src/lib/libtor-err-testing.a \
92         src/lib/libtor-intmath.a \
93         src/lib/libtor-ctime-testing.a
94 endif
96 # Internal crypto libraries used in Tor
97 TOR_CRYPTO_LIBS = \
98         src/lib/libtor-tls.a \
99         src/lib/libtor-crypt-ops.a \
100         $(LIBKECCAK_TINY) \
101         $(LIBDONNA)
103 # Variants of the above for linking the testing variant of tor (for coverage
104 # and tests)
105 if UNITTESTS_ENABLED
106 TOR_CRYPTO_TESTING_LIBS = \
107         src/lib/libtor-tls-testing.a \
108         src/lib/libtor-crypt-ops-testing.a \
109         $(LIBKECCAK_TINY) \
110         $(LIBDONNA)
111 endif
113 # All static libraries used to link tor.
114 TOR_INTERNAL_LIBS = \
115         src/core/libtor-app.a \
116         src/lib/libtor-compress.a \
117         src/lib/libtor-evloop.a \
118         $(TOR_CRYPTO_LIBS) \
119         $(TOR_UTIL_LIBS) \
120         src/trunnel/libor-trunnel.a \
121         src/lib/libtor-trace.a
123 # Variants of the above for linking the testing variant of tor (for coverage
124 # and tests)
125 if UNITTESTS_ENABLED
126 TOR_INTERNAL_TESTING_LIBS = \
127         src/core/libtor-app-testing.a \
128         src/lib/libtor-compress-testing.a \
129         src/lib/libtor-evloop-testing.a \
130         $(TOR_CRYPTO_TESTING_LIBS) \
131         $(TOR_UTIL_TESTING_LIBS) \
132         src/trunnel/libor-trunnel-testing.a \
133         src/lib/libtor-trace.a
134 endif
136 TOR_LDFLAGS_CRYPTLIB=@TOR_LDFLAGS_openssl@
137 TOR_LIBS_CRYPTLIB=@TOR_OPENSSL_LIBS@
138 TOR_CFLAGS_CRYPTLIB=
139 if USE_NSS
140 TOR_CFLAGS_CRYPTLIB+=@NSS_CFLAGS@
141 TOR_LIBS_CRYPTLIB+=@NSS_LIBS@
142 endif
144 # All libraries used to link tor-cov
146 include src/include.am
147 include doc/include.am
148 include contrib/include.am
150 EXTRA_DIST+= \
151         ChangeLog                                       \
152         CONTRIBUTING                                    \
153         CODE_OF_CONDUCT                                 \
154         INSTALL                                         \
155         LICENSE                                         \
156         Makefile.nmake                                  \
157         README                                          \
158         ReleaseNotes                                    \
159         scripts/maint/checkIncludes.py                  \
160         scripts/maint/checkSpace.pl
162 ## This tells etags how to find mockable function definitions.
163 AM_ETAGSFLAGS=--regex='{c}/MOCK_IMPL([^,]+,\W*\([a-zA-Z0-9_]+\)\W*,/\1/s'
165 if COVERAGE_ENABLED
166 TEST_CFLAGS=-fno-inline -fprofile-arcs -ftest-coverage
167 if DISABLE_ASSERTS_IN_UNIT_TESTS
168 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE -DDISABLE_ASSERTS_IN_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
169 else
170 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE @TOR_MODULES_ALL_ENABLED@
171 endif
172 TEST_NETWORK_FLAGS=--coverage --hs-multi-client 1
173 else
174 TEST_CFLAGS=
175 TEST_CPPFLAGS=-DTOR_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
176 TEST_NETWORK_FLAGS=--hs-multi-client 1
177 endif
178 TEST_NETWORK_WARNING_FLAGS=--quiet --only-warnings
180 if LIBFUZZER_ENABLED
181 TEST_CFLAGS += -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-div
182 # not "edge"
183 endif
185 TEST_NETWORK_ALL_LOG_DIR=$(top_builddir)/test_network_log
186 TEST_NETWORK_ALL_DRIVER_FLAGS=--color-tests yes
188 #install-data-local:
189 #       $(INSTALL) -m 755 -d $(LOCALSTATEDIR)/lib/tor
191 # Allows to override rpmbuild with rpmbuild-md5 from fedora-packager so that
192 # building for EL5 won't fail on https://bugzilla.redhat.com/show_bug.cgi?id=490613
193 RPMBUILD ?= rpmbuild
195 # Use automake's dist-gzip target to build the tarball
196 dist-rpm: dist-gzip
197         TIMESTAMP=$$(date +"%Y-%m-%d_%H.%M.%S");                                \
198         RPM_BUILD_DIR=$$(mktemp -d "/tmp/tor-rpm-build-$$TIMESTAMP-XXXX");      \
199         mkdir -p "$$RPM_BUILD_DIR"/{BUILD,RPMS,SOURCES/"tor-$(VERSION)",SPECS,SRPMS}; \
200         cp -fa "$(distdir).tar.gz" "$$RPM_BUILD_DIR"/SOURCES/;                  \
201         LIBS=-lrt $(RPMBUILD) -ba --define "_topdir $$RPM_BUILD_DIR" tor.spec;  \
202         cp -fa "$$RPM_BUILD_DIR"/SRPMS/* .;                                     \
203         cp -fa "$$RPM_BUILD_DIR"/RPMS/* .;                                      \
204         rm -rf "$$RPM_BUILD_DIR";                                               \
205         echo "RPM build finished";                                              \
206         #end of dist-rpm
208 doxygen:
209         doxygen && cd doc/doxygen/latex && make
211 test: all
212         $(top_builddir)/src/test/test
214 check-local: check-spaces check-changes check-includes
216 need-chutney-path:
217         @if test ! -d "$$CHUTNEY_PATH"; then \
218                 echo '$$CHUTNEY_PATH was not set.'; \
219                 if test -d $(top_srcdir)/../chutney -a -x $(top_srcdir)/../chutney/chutney; then \
220                         echo "Assuming test-network.sh will find" $(top_srcdir)/../chutney; \
221                 else \
222                         echo; \
223                         echo "To run these tests, git clone https://git.torproject.org/chutney.git ; export CHUTNEY_PATH=\`pwd\`/chutney"; \
224                         exit 1; \
225                 fi \
226         fi
228 # Note that test-network requires a copy of Chutney in $CHUTNEY_PATH.
229 # Chutney can be cloned from https://git.torproject.org/chutney.git .
230 test-network: need-chutney-path $(TESTING_TOR_BINARY) src/tools/tor-gencert
231         $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_FLAGS)
233 # Run all available tests using automake's test-driver
234 # only run IPv6 tests if we can ping6 ::1 (localhost)
235 # only run IPv6 tests if we can ping ::1 (localhost)
236 # some IPv6 tests will fail without an IPv6 DNS server (see #16971 and #17011)
237 # only run mixed tests if we have a tor-stable binary
238 # Try the syntax for BSD ping6, Linux ping6, and Linux ping -6,
239 # because they're incompatible
240 test-network-all: need-chutney-path test-driver $(TESTING_TOR_BINARY) src/tools/tor-gencert
241         mkdir -p $(TEST_NETWORK_ALL_LOG_DIR)
242         rm -f $(TEST_NETWORK_ALL_LOG_DIR)/*.log $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
243         @flavors="$(TEST_CHUTNEY_FLAVORS)"; \
244         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 \
245                 echo "ping6 ::1 or ping ::1 succeeded, running IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
246                 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
247         else \
248                 echo "ping6 ::1 and ping ::1 failed, skipping IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
249                 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
250         fi; \
251         if command -v tor-stable >/dev/null 2>&1; then \
252                 echo "tor-stable found, running mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
253                 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
254         else \
255                 echo "tor-stable not found, skipping mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
256                 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
257         fi; \
258         for f in $$skip_flavors; do \
259                 echo "SKIP: $$f"; \
260         done; \
261         for f in $$flavors; do \
262                 $(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); \
263                 $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_WARNING_FLAGS); \
264         done; \
265         echo "Log and result files are available in $(TEST_NETWORK_ALL_LOG_DIR)."; \
266         ! grep -q FAIL $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
268 need-stem-path:
269         @if test ! -d "$$STEM_SOURCE_DIR"; then \
270                 echo '$$STEM_SOURCE_DIR was not set.'; echo; \
271                 echo "To run these tests, git clone https://git.torproject.org/stem.git/ ; export STEM_SOURCE_DIR=\`pwd\`/stem"; \
272                 exit 1; \
273         fi
275 test-stem: need-stem-path $(TESTING_TOR_BINARY)
276         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL;
278 test-stem-full: need-stem-path $(TESTING_TOR_BINARY)
279         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL,ONLINE -v;
281 test-full: need-stem-path need-chutney-path check test-network test-stem
283 test-full-online: need-stem-path need-chutney-path check test-network test-stem-full
285 reset-gcov:
286         rm -f $(top_builddir)/src/*/*.gcda $(top_builddir)/src/*/*/*.gcda
288 HTML_COVER_DIR=$(top_builddir)/coverage_html
289 coverage-html: all
290 if COVERAGE_ENABLED
291         test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
292         test -d "$(HTML_COVER_DIR)" || $(MKDIR_P) "$(HTML_COVER_DIR)"
293         lcov --rc lcov_branch_coverage=1 --directory $(top_builddir)/src --zerocounters
294         $(MAKE) reset-gcov
295         $(MAKE) check
296         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory $(top_builddir) --base-directory $(top_srcdir) --output-file "$(HTML_COVER_DIR)/lcov.tmp"
297         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
298         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
299 else
300         @printf "Not configured with --enable-coverage, run ./configure --enable-coverage\n"
301 endif
303 coverage-html-full: all
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 ./src --zerocounters
307         $(MAKE) reset-gcov
308         $(MAKE) check
309         $(MAKE) test-stem-full
310         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh
311         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh --flavor hs
312         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory . --output-file "$(HTML_COVER_DIR)/lcov.tmp"
313         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
314         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
316 # Avoid strlcpy.c, strlcat.c, aes.c, OpenBSD_malloc_Linux.c, sha256.c,
317 # tinytest*.[ch]
318 check-spaces:
319 if USE_PERL
320         $(PERL) $(top_srcdir)/scripts/maint/checkSpace.pl -C \
321                 $(top_srcdir)/src/lib/*/*.[ch] \
322                 $(top_srcdir)/src/core/*/*.[ch] \
323                 $(top_srcdir)/src/feature/*/*.[ch] \
324                 $(top_srcdir)/src/app/*/*.[ch] \
325                 $(top_srcdir)/src/test/*.[ch] \
326                 $(top_srcdir)/src/test/*/*.[ch] \
327                 $(top_srcdir)/src/tools/*.[ch]
328 endif
330 check-includes:
331 if USEPYTHON
332         $(PYTHON) $(top_srcdir)/scripts/maint/checkIncludes.py
333 endif
335 check-docs: all
336         $(PERL) $(top_builddir)/scripts/maint/checkOptionDocs.pl
338 check-logs:
339         $(top_srcdir)/scripts/maint/checkLogs.pl \
340                 $(top_srcdir)/src/*/*.[ch] | sort -n
342 .PHONY: check-typos
343 check-typos:
344         @if test -x "`which misspell 2>&1;true`"; then \
345                 echo "Checking for Typos ..."; \
346                 (misspell \
347                         $(top_srcdir)/src/[^e]*/*.[ch] \
348                         $(top_srcdir)/doc \
349                         $(top_srcdir)/contrib \
350                         $(top_srcdir)/scripts \
351                         $(top_srcdir)/README \
352                         $(top_srcdir)/ChangeLog \
353                         $(top_srcdir)/INSTALL \
354                         $(top_srcdir)/ReleaseNotes \
355                         $(top_srcdir)/LICENSE); \
356         else \
357                 echo "Tor can use misspell to check for typos."; \
358                 echo "It seems that you don't have misspell installed."; \
359                 echo "You can install the latest version of misspell here: https://github.com/client9/misspell#install"; \
360         fi
362 .PHONY: rustfmt
363 rustfmt:
364 if USE_RUST
365         @if test -x "`which cargo-fmt 2>&1;true`"; then \
366                 echo "Formatting Rust code ..."; \
367                 (cd "$(top_srcdir)/src/rust" && cargo fmt --all --); \
368         else \
369                 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
370                 echo "However, it seems that you don't have rustfmt installed."; \
371                 printf "You can install rustfmt by following the directions here:"; \
372                 echo " https://github.com/rust-lang-nursery/rustfmt"; \
373         fi
374 endif
376 .PHONY: check-rustfmt
377 check-rustfmt:
378 if USE_RUST
379         @if test -x "`which cargo-fmt 2>&1;true`"; then \
380                 printf "Running rustfmt..."; \
381                 (cd "$(top_srcdir)/src/rust" && cargo fmt --all -- --check && echo "done.") || \
382                 (echo "**************** check-rustfmt failed. ****************"; \
383                  echo "   Run \`make rustfmt\` to apply the above changes."; \
384                  exit 1); \
385         else \
386                 echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
387                 echo "However, it seems that you don't have rustfmt installed."; \
388                 printf "You can install rustfmt by following the directions here:"; \
389                 echo " https://github.com/rust-lang-nursery/rustfmt"; \
390         fi
391 endif
393 .PHONY: clippy
394 clippy:
395 if USE_RUST
396         @if test -x "`which cargo-clippy 2>&1;true`"; then \
397                 echo "Running cargo clippy ..."; \
398                 echo "Prepare yourself for the onslaught of suggestions ..."; \
399                 (cd "$(top_srcdir)/src/rust" && cargo clippy); \
400         else \
401                 echo "Tor can use clippy to lint Rust code."; \
402                 echo "However, it seems that you don't have clippy installed."; \
403                 echo "You can install the latest version of clippy by following the directions here: https://github.com/rust-lang-nursery/rust-clippy"; \
404         fi
405 endif
407 .PHONY: check-changes
408 check-changes:
409 if USEPYTHON
410         @if test -d "$(top_srcdir)/changes"; then \
411                 $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \
412                 fi
413 endif
415 .PHONY: update-versions
416 update-versions:
417         $(PERL) $(top_builddir)/scripts/maint/updateVersions.pl
419 .PHONY: callgraph
420 callgraph:
421         $(top_builddir)/scripts/maint/run_calltool.sh
423 version:
424         @echo "Tor @VERSION@"
425         @if test -d "$(top_srcdir)/.git" && test -x "`which git 2>&1;true`"; then \
426            echo -n "git: " ;\
427            (cd "$(top_srcdir)" && git rev-parse --short=16 HEAD); \
428         fi
430 mostlyclean-local:
431         rm -f $(top_builddir)/src/*/*.gc{da,no} $(top_builddir)/src/*/*/*.gc{da,no}
432         rm -rf $(HTML_COVER_DIR)
433         rm -rf $(top_builddir)/doc/doxygen
434         rm -rf $(TEST_NETWORK_ALL_LOG_DIR)
436 clean-local:
437         rm -rf $(top_builddir)/src/rust/target
438         rm -rf $(top_builddir)/src/rust/.cargo/registry
440 if USE_RUST
441 distclean-local: distclean-rust
442 endif
444 # This relies on some internal details of how automake implements
445 # distcheck.  We check two directories because automake-1.15 changed
446 # from $(distdir)/_build to $(distdir)/_build/sub.
447 show-distdir-testlog:
448         @if test -d "$(distdir)/_build/sub"; then \
449           cat $(distdir)/_build/sub/$(TEST_SUITE_LOG); \
450         else \
451           cat $(distdir)/_build/$(TEST_SUITE_LOG); fi
453 show-libs:
454         @echo $(TOR_INTERNAL_LIBS)
456 show-testing-libs:
457         @echo $(TOR_INTERNAL_TESTING_LIBS)