Merge branch 'maint-0.2.9' into maint-0.3.3
[tor.git] / Makefile.am
blobdcb445c9708c8fe4a8a77d3a5ee952756ef28761
1 # Copyright (c) 2001-2004, Roger Dingledine
2 # Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
3 # Copyright (c) 2007-2017, 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 AM_CFLAGS=@TOR_SYSTEMD_CFLAGS@ @CFLAGS_BUGTRAP@ @TOR_LZMA_CFLAGS@ @TOR_ZSTD_CFLAGS@
20 SHELL=@SHELL@
22 if COVERAGE_ENABLED
23 TESTING_TOR_BINARY=$(top_builddir)/src/or/tor-cov$(EXEEXT)
24 else
25 TESTING_TOR_BINARY=$(top_builddir)/src/or/tor$(EXEEXT)
26 endif
28 if USE_RUST
29 rust_ldadd=$(top_builddir)/src/rust/target/release/@TOR_RUST_STATIC_NAME@ \
30         @TOR_RUST_EXTRA_LIBS@
31 else
32 rust_ldadd=
33 endif
35 include src/include.am
36 include doc/include.am
37 include contrib/include.am
39 EXTRA_DIST+= \
40         ChangeLog                                       \
41         INSTALL                                         \
42         LICENSE                                         \
43         Makefile.nmake                                  \
44         README                                          \
45         ReleaseNotes                                    \
46         scripts/maint/checkSpace.pl
48 ## This tells etags how to find mockable function definitions.
49 AM_ETAGSFLAGS=--regex='{c}/MOCK_IMPL([^,]+,\W*\([a-zA-Z0-9_]+\)\W*,/\1/s'
51 if COVERAGE_ENABLED
52 TEST_CFLAGS=-fno-inline -fprofile-arcs -ftest-coverage
53 if DISABLE_ASSERTS_IN_UNIT_TESTS
54 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE -DDISABLE_ASSERTS_IN_UNIT_TESTS
55 else
56 TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE
57 endif
58 TEST_NETWORK_FLAGS=--coverage --hs-multi-client 1
59 else
60 TEST_CFLAGS=
61 TEST_CPPFLAGS=-DTOR_UNIT_TESTS
62 TEST_NETWORK_FLAGS=--hs-multi-client 1
63 endif
64 TEST_NETWORK_WARNING_FLAGS=--quiet --only-warnings
66 if LIBFUZZER_ENABLED
67 TEST_CFLAGS += -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-div
68 # not "edge"
69 endif
71 TEST_NETWORK_ALL_LOG_DIR=$(top_builddir)/test_network_log
72 TEST_NETWORK_ALL_DRIVER_FLAGS=--color-tests yes
74 #install-data-local:
75 #       $(INSTALL) -m 755 -d $(LOCALSTATEDIR)/lib/tor
77 # Allows to override rpmbuild with rpmbuild-md5 from fedora-packager so that
78 # building for EL5 won't fail on https://bugzilla.redhat.com/show_bug.cgi?id=490613
79 RPMBUILD ?= rpmbuild
81 # Use automake's dist-gzip target to build the tarball
82 dist-rpm: dist-gzip
83         TIMESTAMP=$$(date +"%Y-%m-%d_%H.%M.%S");                                \
84         RPM_BUILD_DIR=$$(mktemp -d "/tmp/tor-rpm-build-$$TIMESTAMP-XXXX");      \
85         mkdir -p "$$RPM_BUILD_DIR"/{BUILD,RPMS,SOURCES/"tor-$(VERSION)",SPECS,SRPMS}; \
86         cp -fa "$(distdir).tar.gz" "$$RPM_BUILD_DIR"/SOURCES/;                  \
87         LIBS=-lrt $(RPMBUILD) -ba --define "_topdir $$RPM_BUILD_DIR" tor.spec;  \
88         cp -fa "$$RPM_BUILD_DIR"/SRPMS/* .;                                     \
89         cp -fa "$$RPM_BUILD_DIR"/RPMS/* .;                                      \
90         rm -rf "$$RPM_BUILD_DIR";                                               \
91         echo "RPM build finished";                                              \
92         #end of dist-rpm
94 doxygen:
95         doxygen && cd doc/doxygen/latex && make
97 test: all
98         $(top_builddir)/src/test/test
100 check-local: check-spaces check-changes
102 need-chutney-path:
103         @if test ! -d "$$CHUTNEY_PATH"; then \
104                 echo '$$CHUTNEY_PATH was not set.'; \
105                 if test -d $(top_srcdir)/../chutney -a -x $(top_srcdir)/../chutney/chutney; then \
106                         echo "Assuming test-network.sh will find" $(top_srcdir)/../chutney; \
107                 else \
108                         echo; \
109                         echo "To run these tests, git clone https://git.torproject.org/chutney.git ; export CHUTNEY_PATH=\`pwd\`/chutney"; \
110                         exit 1; \
111                 fi \
112         fi
114 # Note that test-network requires a copy of Chutney in $CHUTNEY_PATH.
115 # Chutney can be cloned from https://git.torproject.org/chutney.git .
116 test-network: need-chutney-path $(TESTING_TOR_BINARY) src/tools/tor-gencert
117         $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_FLAGS)
119 # Run all available tests using automake's test-driver
120 # only run IPv6 tests if we can ping6 ::1 (localhost)
121 # only run IPv6 tests if we can ping ::1 (localhost)
122 # some IPv6 tests will fail without an IPv6 DNS server (see #16971 and #17011)
123 # only run mixed tests if we have a tor-stable binary
124 # Try the syntax for BSD ping6, Linux ping6, and Linux ping -6,
125 # because they're incompatible
126 test-network-all: need-chutney-path test-driver $(TESTING_TOR_BINARY) src/tools/tor-gencert
127         mkdir -p $(TEST_NETWORK_ALL_LOG_DIR)
128         rm -f $(TEST_NETWORK_ALL_LOG_DIR)/*.log $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
129         @flavors="$(TEST_CHUTNEY_FLAVORS)"; \
130         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 \
131                 echo "ping6 ::1 or ping ::1 succeeded, running IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
132                 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
133         else \
134                 echo "ping6 ::1 and ping ::1 failed, skipping IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
135                 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
136         fi; \
137         if command -v tor-stable >/dev/null 2>&1; then \
138                 echo "tor-stable found, running mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
139                 flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
140         else \
141                 echo "tor-stable not found, skipping mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
142                 skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
143         fi; \
144         for f in $$skip_flavors; do \
145                 echo "SKIP: $$f"; \
146         done; \
147         for f in $$flavors; do \
148                 $(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); \
149                 $(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_WARNING_FLAGS); \
150         done; \
151         echo "Log and result files are available in $(TEST_NETWORK_ALL_LOG_DIR)."; \
152         ! grep -q FAIL $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
154 need-stem-path:
155         @if test ! -d "$$STEM_SOURCE_DIR"; then \
156                 echo '$$STEM_SOURCE_DIR was not set.'; echo; \
157                 echo "To run these tests, git clone https://git.torproject.org/stem.git/ ; export STEM_SOURCE_DIR=\`pwd\`/stem"; \
158                 exit 1; \
159         fi
161 test-stem: need-stem-path $(TESTING_TOR_BINARY)
162         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL;
164 test-stem-full: need-stem-path $(TESTING_TOR_BINARY)
165         @$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL,ONLINE -v;
167 test-full: need-stem-path need-chutney-path check test-network test-stem
169 test-full-online: need-stem-path need-chutney-path check test-network test-stem-full
171 reset-gcov:
172         rm -f $(top_builddir)/src/*/*.gcda $(top_builddir)/src/*/*/*.gcda
174 HTML_COVER_DIR=$(top_builddir)/coverage_html
175 coverage-html: all
176 if COVERAGE_ENABLED
177         test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
178         test -d "$(HTML_COVER_DIR)" || $(MKDIR_P) "$(HTML_COVER_DIR)"
179         lcov --rc lcov_branch_coverage=1 --directory $(top_builddir)/src --zerocounters
180         $(MAKE) reset-gcov
181         $(MAKE) check
182         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory $(top_builddir) --base-directory $(top_srcdir) --output-file "$(HTML_COVER_DIR)/lcov.tmp"
183         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
184         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
185 else
186         @printf "Not configured with --enable-coverage, run ./configure --enable-coverage\n"
187 endif
189 coverage-html-full: all
190         test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
191         test -d "$(HTML_COVER_DIR)" || mkdir -p "$(HTML_COVER_DIR)"
192         lcov --rc lcov_branch_coverage=1 --directory ./src --zerocounters
193         $(MAKE) reset-gcov
194         $(MAKE) check
195         $(MAKE) test-stem-full
196         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh
197         CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh --flavor hs
198         lcov --capture --rc lcov_branch_coverage=1 --no-external --directory . --output-file "$(HTML_COVER_DIR)/lcov.tmp"
199         lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
200         genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
202 # Avoid strlcpy.c, strlcat.c, aes.c, OpenBSD_malloc_Linux.c, sha256.c,
203 # tinytest*.[ch]
204 check-spaces:
205 if USE_PERL
206         $(PERL) $(top_srcdir)/scripts/maint/checkSpace.pl -C \
207                 $(top_srcdir)/src/common/*.[ch] \
208                 $(top_srcdir)/src/or/*.[ch] \
209                 $(top_srcdir)/src/test/*.[ch] \
210                 $(top_srcdir)/src/test/*/*.[ch] \
211                 $(top_srcdir)/src/tools/*.[ch]
212 endif
214 check-docs: all
215         $(PERL) $(top_builddir)/scripts/maint/checkOptionDocs.pl
217 check-logs:
218         $(top_srcdir)/scripts/maint/checkLogs.pl \
219                 $(top_srcdir)/src/*/*.[ch] | sort -n
221 .PHONY: check-changes
222 check-changes:
223 if USEPYTHON
224         @if test -d "$(top_srcdir)/changes"; then \
225                 $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \
226                 fi
227 endif
229 .PHONY: update-versions
230 update-versions:
231         $(PERL) $(top_builddir)/scripts/maint/updateVersions.pl
233 .PHONY: callgraph
234 callgraph:
235         $(top_builddir)/scripts/maint/run_calltool.sh
237 version:
238         @echo "Tor @VERSION@"
239         @if test -d "$(top_srcdir)/.git" && test -x "`which git 2>&1;true`"; then \
240            echo -n "git: " ;\
241            (cd "$(top_srcdir)" && git rev-parse --short=16 HEAD); \
242         fi
244 mostlyclean-local:
245         rm -f $(top_builddir)/src/*/*.gc{da,no} $(top_builddir)/src/*/*/*.gc{da,no}
246         rm -rf $(HTML_COVER_DIR)
247         rm -rf $(top_builddir)/doc/doxygen
248         rm -rf $(TEST_NETWORK_ALL_LOG_DIR)
250 clean-local:
251         rm -rf $(top_builddir)/src/rust/target
252         rm -rf $(top_builddir)/src/rust/.cargo/registry
254 if USE_RUST
255 distclean-local: distclean-rust
256 endif
258 # This relies on some internal details of how automake implements
259 # distcheck.  We check two directories because automake-1.15 changed
260 # from $(distdir)/_build to $(distdir)/_build/sub.
261 show-distdir-testlog:
262         @if test -d "$(distdir)/_build/sub"; then \
263           cat $(distdir)/_build/sub/$(TEST_SUITE_LOG); \
264         else \
265           cat $(distdir)/_build/$(TEST_SUITE_LOG); fi