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