Makefile.am 18.1 KB
Newer Older
Roger Dingledine's avatar
Roger Dingledine committed
1
# Copyright (c) 2001-2004, Roger Dingledine
2
# Copyright (c) 2004-2006, Roger Dingledine, Nick Mathewson
Nick Mathewson's avatar
Nick Mathewson committed
3
# Copyright (c) 2007-2019, The Tor Project, Inc.
Nick Mathewson's avatar
Nick Mathewson committed
4
5
# See LICENSE for licensing information

6
7
ACLOCAL_AMFLAGS = -I m4

Stewart Smith's avatar
Stewart Smith committed
8
9
10
11
noinst_LIBRARIES=
EXTRA_DIST=
noinst_HEADERS=
bin_PROGRAMS=
12
EXTRA_PROGRAMS=
Stewart Smith's avatar
Stewart Smith committed
13
14
15
16
17
CLEANFILES=
TESTS=
noinst_PROGRAMS=
DISTCLEANFILES=
bin_SCRIPTS=
18
19
20
AM_CPPFLAGS=\
	-I$(top_srcdir)/src \
	-I$(top_srcdir)/src/ext \
Nick Mathewson's avatar
Nick Mathewson committed
21
22
	-I$(top_srcdir)/src/ext/trunnel \
	-I$(top_srcdir)/src/trunnel
23

24
AM_CFLAGS=@TOR_SYSTEMD_CFLAGS@ @CFLAGS_BUGTRAP@ @TOR_LZMA_CFLAGS@ @TOR_ZSTD_CFLAGS@
25
SHELL=@SHELL@
26
27

if COVERAGE_ENABLED
Nick Mathewson's avatar
Nick Mathewson committed
28
TESTING_TOR_BINARY=$(top_builddir)/src/app/tor-cov$(EXEEXT)
29
else
Nick Mathewson's avatar
Nick Mathewson committed
30
TESTING_TOR_BINARY=$(top_builddir)/src/app/tor$(EXEEXT)
31
32
endif

33
if USE_RUST
34
rust_ldadd=$(top_builddir)/$(TOR_RUST_LIB_PATH)
35
36
37
38
else
rust_ldadd=
endif

39
40
# "Common" libraries used to link tor's utility code.
TOR_UTIL_LIBS = \
41
        src/lib/libtor-geoip.a \
42
	src/lib/libtor-process.a \
43
        src/lib/libtor-buf.a \
44
	src/lib/libtor-confmgt.a \
45
	src/lib/libtor-pubsub.a \
46
	src/lib/libtor-dispatch.a \
47
48
49
50
	src/lib/libtor-time.a \
	src/lib/libtor-fs.a \
	src/lib/libtor-encoding.a \
	src/lib/libtor-sandbox.a \
51
	src/lib/libtor-container.a \
52
	src/lib/libtor-net.a \
53
54
	src/lib/libtor-thread.a \
	src/lib/libtor-memarea.a \
55
	src/lib/libtor-math.a \
Nick Mathewson's avatar
Nick Mathewson committed
56
	src/lib/libtor-meminfo.a \
57
	src/lib/libtor-osinfo.a \
58
59
60
61
	src/lib/libtor-log.a \
	src/lib/libtor-lock.a \
	src/lib/libtor-fdio.a \
	src/lib/libtor-string.a \
62
	src/lib/libtor-term.a \
63
	src/lib/libtor-smartlist-core.a \
64
	src/lib/libtor-malloc.a \
65
66
	src/lib/libtor-wallclock.a \
	src/lib/libtor-err.a \
67
	src/lib/libtor-version.a \
68
	src/lib/libtor-intmath.a \
69
	src/lib/libtor-ctime.a
70
71
72

# Variants of the above for linking the testing variant of tor (for coverage
# and tests)
73
if UNITTESTS_ENABLED
74
TOR_UTIL_TESTING_LIBS = \
75
        src/lib/libtor-geoip-testing.a \
76
	src/lib/libtor-process-testing.a \
77
        src/lib/libtor-buf-testing.a \
78
	src/lib/libtor-confmgt-testing.a \
79
	src/lib/libtor-pubsub-testing.a \
80
	src/lib/libtor-dispatch-testing.a \
81
82
83
84
	src/lib/libtor-time-testing.a \
	src/lib/libtor-fs-testing.a \
	src/lib/libtor-encoding-testing.a \
	src/lib/libtor-sandbox-testing.a \
85
	src/lib/libtor-container-testing.a \
86
	src/lib/libtor-net-testing.a \
87
88
	src/lib/libtor-thread-testing.a \
	src/lib/libtor-memarea-testing.a \
89
	src/lib/libtor-math-testing.a \
Nick Mathewson's avatar
Nick Mathewson committed
90
	src/lib/libtor-meminfo-testing.a \
91
	src/lib/libtor-osinfo-testing.a \
92
	src/lib/libtor-term-testing.a \
93
94
95
96
97
	src/lib/libtor-log-testing.a \
	src/lib/libtor-lock-testing.a \
	src/lib/libtor-fdio-testing.a \
	src/lib/libtor-string-testing.a \
	src/lib/libtor-smartlist-core-testing.a \
98
	src/lib/libtor-malloc-testing.a \
99
100
	src/lib/libtor-wallclock-testing.a \
	src/lib/libtor-err-testing.a \
101
	src/lib/libtor-version-testing.a \
102
103
	src/lib/libtor-intmath.a \
	src/lib/libtor-ctime-testing.a
104
endif
105
106
107

# Internal crypto libraries used in Tor
TOR_CRYPTO_LIBS = \
108
109
	src/lib/libtor-tls.a \
	src/lib/libtor-crypt-ops.a \
110
111
112
113
114
	$(LIBKECCAK_TINY) \
	$(LIBDONNA)

# Variants of the above for linking the testing variant of tor (for coverage
# and tests)
115
if UNITTESTS_ENABLED
116
TOR_CRYPTO_TESTING_LIBS = \
117
118
	src/lib/libtor-tls-testing.a \
	src/lib/libtor-crypt-ops-testing.a \
119
120
	$(LIBKECCAK_TINY) \
	$(LIBDONNA)
121
endif
122
123
124

# All static libraries used to link tor.
TOR_INTERNAL_LIBS = \
Nick Mathewson's avatar
Nick Mathewson committed
125
	src/core/libtor-app.a \
Nick Mathewson's avatar
Nick Mathewson committed
126
	src/lib/libtor-compress.a \
127
	src/lib/libtor-evloop.a \
128
129
130
	$(TOR_CRYPTO_LIBS) \
	$(TOR_UTIL_LIBS) \
	src/trunnel/libor-trunnel.a \
131
	src/lib/libtor-trace.a
132
133
134

# Variants of the above for linking the testing variant of tor (for coverage
# and tests)
135
if UNITTESTS_ENABLED
136
TOR_INTERNAL_TESTING_LIBS = \
Nick Mathewson's avatar
Nick Mathewson committed
137
	src/core/libtor-app-testing.a \
Nick Mathewson's avatar
Nick Mathewson committed
138
	src/lib/libtor-compress-testing.a \
139
	src/lib/libtor-evloop-testing.a \
140
141
142
	$(TOR_CRYPTO_TESTING_LIBS) \
	$(TOR_UTIL_TESTING_LIBS) \
	src/trunnel/libor-trunnel-testing.a \
143
	src/lib/libtor-trace.a
144
endif
145

146
147
TOR_LDFLAGS_CRYPTLIB=@TOR_LDFLAGS_openssl@
TOR_LIBS_CRYPTLIB=@TOR_OPENSSL_LIBS@
148
149
150
151
152
TOR_CFLAGS_CRYPTLIB=
if USE_NSS
TOR_CFLAGS_CRYPTLIB+=@NSS_CFLAGS@
TOR_LIBS_CRYPTLIB+=@NSS_LIBS@
endif
153

154
155
# All libraries used to link tor-cov

Stewart Smith's avatar
Stewart Smith committed
156
157
158
include src/include.am
include doc/include.am
include contrib/include.am
159

Stewart Smith's avatar
Stewart Smith committed
160
EXTRA_DIST+= \
161
	ChangeLog					\
Nick Mathewson's avatar
Nick Mathewson committed
162
	CONTRIBUTING					\
rl1987's avatar
rl1987 committed
163
	CODE_OF_CONDUCT                                 \
164
165
	INSTALL						\
	LICENSE						\
166
	Makefile.nmake					\
167
	README						\
Nick Mathewson's avatar
Nick Mathewson committed
168
	ReleaseNotes					\
169
	scripts/maint/checkIncludes.py                  \
170
	scripts/maint/checkSpace.pl 			\
171
	scripts/maint/checkShellScripts.sh			\
172
	scripts/maint/practracker/README                \
173
	scripts/maint/practracker/exceptions.txt	\
174
	scripts/maint/practracker/includes.py		\
175
176
	scripts/maint/practracker/metrics.py		\
	scripts/maint/practracker/practracker.py	\
177
	scripts/maint/practracker/practracker_tests.py	\
178
	scripts/maint/practracker/problem.py		\
179
	scripts/maint/practracker/testdata/.may_include	\
180
181
182
183
184
185
	scripts/maint/practracker/testdata/a.c		\
	scripts/maint/practracker/testdata/b.c 		\
	scripts/maint/practracker/testdata/ex0-expected.txt \
	scripts/maint/practracker/testdata/ex0.txt 	\
	scripts/maint/practracker/testdata/ex1-expected.txt \
	scripts/maint/practracker/testdata/ex1.txt 	\
186
	scripts/maint/practracker/testdata/ex1-overbroad-expected.txt 	\
187
	scripts/maint/practracker/testdata/ex.txt 	\
188
	scripts/maint/practracker/testdata/header.h 	\
189
190
	scripts/maint/practracker/testdata/not_c_file	\
	scripts/maint/practracker/test_practracker.sh   \
191
	scripts/maint/practracker/util.py
192

193
194
195
## This tells etags how to find mockable function definitions.
AM_ETAGSFLAGS=--regex='{c}/MOCK_IMPL([^,]+,\W*\([a-zA-Z0-9_]+\)\W*,/\1/s'

196
197
if COVERAGE_ENABLED
TEST_CFLAGS=-fno-inline -fprofile-arcs -ftest-coverage
198
if DISABLE_ASSERTS_IN_UNIT_TESTS
199
TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE -DDISABLE_ASSERTS_IN_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
200
else
201
TEST_CPPFLAGS=-DTOR_UNIT_TESTS -DTOR_COVERAGE @TOR_MODULES_ALL_ENABLED@
202
endif
203
TEST_NETWORK_FLAGS=--coverage --hs-multi-client 1
204
205
else
TEST_CFLAGS=
206
TEST_CPPFLAGS=-DTOR_UNIT_TESTS @TOR_MODULES_ALL_ENABLED@
207
TEST_NETWORK_FLAGS=--hs-multi-client 1
208
endif
209
TEST_NETWORK_SHOW_WARNINGS_FOR_LAST_RUN_FLAGS=--quiet --only-warnings
210

Nick Mathewson's avatar
Nick Mathewson committed
211
if LIBFUZZER_ENABLED
212
213
TEST_CFLAGS += -fsanitize-coverage=trace-pc-guard,trace-cmp,trace-div
# not "edge"
Nick Mathewson's avatar
Nick Mathewson committed
214
215
endif

216
217
218
TEST_NETWORK_ALL_LOG_DIR=$(top_builddir)/test_network_log
TEST_NETWORK_ALL_DRIVER_FLAGS=--color-tests yes

219
220
#install-data-local:
#	$(INSTALL) -m 755 -d $(LOCALSTATEDIR)/lib/tor
221

222
223
224
225
# Allows to override rpmbuild with rpmbuild-md5 from fedora-packager so that
# building for EL5 won't fail on https://bugzilla.redhat.com/show_bug.cgi?id=490613
RPMBUILD ?= rpmbuild

226
227
228
229
230
231
# Use automake's dist-gzip target to build the tarball
dist-rpm: dist-gzip
	TIMESTAMP=$$(date +"%Y-%m-%d_%H.%M.%S"); 				\
	RPM_BUILD_DIR=$$(mktemp -d "/tmp/tor-rpm-build-$$TIMESTAMP-XXXX");	\
	mkdir -p "$$RPM_BUILD_DIR"/{BUILD,RPMS,SOURCES/"tor-$(VERSION)",SPECS,SRPMS}; \
	cp -fa "$(distdir).tar.gz" "$$RPM_BUILD_DIR"/SOURCES/;			\
232
	LIBS=-lrt $(RPMBUILD) -ba --define "_topdir $$RPM_BUILD_DIR" tor.spec; 	\
233
234
235
236
237
	cp -fa "$$RPM_BUILD_DIR"/SRPMS/* .;                           		\
	cp -fa "$$RPM_BUILD_DIR"/RPMS/* .;                            		\
	rm -rf "$$RPM_BUILD_DIR";						\
	echo "RPM build finished";						\
	#end of dist-rpm
238
239

doxygen:
240
	doxygen && cd doc/doxygen/latex && make
241

242
test: all
243
	$(top_builddir)/src/test/test
244

245
shellcheck:
246
	$(top_srcdir)/scripts/maint/checkShellScripts.sh
247

248
check-local: check-spaces check-changes check-includes shellcheck
249

250
251
need-chutney-path:
	@if test ! -d "$$CHUTNEY_PATH"; then \
252
253
254
255
256
257
258
259
		echo '$$CHUTNEY_PATH was not set.'; \
		if test -d $(top_srcdir)/../chutney -a -x $(top_srcdir)/../chutney/chutney; then \
			echo "Assuming test-network.sh will find" $(top_srcdir)/../chutney; \
		else \
			echo; \
			echo "To run these tests, git clone https://git.torproject.org/chutney.git ; export CHUTNEY_PATH=\`pwd\`/chutney"; \
			exit 1; \
		fi \
260
261
	fi

262
263
# Note that test-network requires a copy of Chutney in $CHUTNEY_PATH.
# Chutney can be cloned from https://git.torproject.org/chutney.git .
264
test-network: need-chutney-path $(TESTING_TOR_BINARY) src/tools/tor-gencert
265
	$(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_FLAGS)
266

267
# Run all available tests using automake's test-driver
268
269
270
271
272
273
274
275
276
#   - only run IPv6 tests if we can ping6 or ping -6 ::1 (localhost)
#     we try the syntax for BSD ping6, Linux ping6, and Linux ping -6,
#     because they're incompatible
#   - some IPv6 tests may fail without an IPv6 DNS server
#     (see #16971 and #17011)
#   - only run mixed tests if we have a tor-stable binary
#   - show tor warnings on the console after each network run
#     (otherwise, warnings go to the logs, and people don't see them unless
#     there is a network failure)
277
test-network-all: need-chutney-path test-driver $(TESTING_TOR_BINARY) src/tools/tor-gencert
278
	mkdir -p $(TEST_NETWORK_ALL_LOG_DIR)
279
	rm -f $(TEST_NETWORK_ALL_LOG_DIR)/*.log $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
280
	@flavors="$(TEST_CHUTNEY_FLAVORS)"; \
281
282
	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 \
		echo "ping6 ::1 or ping ::1 succeeded, running IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
283
284
		flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
	else \
285
		echo "ping6 ::1 and ping ::1 failed, skipping IPv6 flavors: $(TEST_CHUTNEY_FLAVORS_IPV6)."; \
286
287
288
289
290
291
292
293
294
295
296
297
298
		skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_IPV6)"; \
	fi; \
	if command -v tor-stable >/dev/null 2>&1; then \
		echo "tor-stable found, running mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
		flavors="$$flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
	else \
		echo "tor-stable not found, skipping mixed flavors: $(TEST_CHUTNEY_FLAVORS_MIXED)."; \
		skip_flavors="$$skip_flavors $(TEST_CHUTNEY_FLAVORS_MIXED)"; \
	fi; \
	for f in $$skip_flavors; do \
		echo "SKIP: $$f"; \
	done; \
	for f in $$flavors; do \
299
		$(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); \
300
		$(top_srcdir)/src/test/test-network.sh $(TEST_NETWORK_SHOW_WARNINGS_FOR_LAST_RUN_FLAGS); \
301
302
	done; \
	echo "Log and result files are available in $(TEST_NETWORK_ALL_LOG_DIR)."; \
303
	! grep -q FAIL $(TEST_NETWORK_ALL_LOG_DIR)/*.trs
304

305
306
need-stem-path:
	@if test ! -d "$$STEM_SOURCE_DIR"; then \
307
308
		echo '$$STEM_SOURCE_DIR was not set.'; echo; \
		echo "To run these tests, git clone https://git.torproject.org/stem.git/ ; export STEM_SOURCE_DIR=\`pwd\`/stem"; \
309
		exit 1; \
310
311
	fi

312
test-stem: need-stem-path $(TESTING_TOR_BINARY)
313
	@$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --integ --test control.controller --test control.base_controller --test process --log notice;
314

315
316
test-stem-full: need-stem-path $(TESTING_TOR_BINARY)
	@$(PYTHON) "$$STEM_SOURCE_DIR"/run_tests.py --tor "$(TESTING_TOR_BINARY)" --all --log notice --target RUN_ALL,ONLINE -v;
317
318
319
320

test-full: need-stem-path need-chutney-path check test-network test-stem

test-full-online: need-stem-path need-chutney-path check test-network test-stem-full
321

322
# We can't delete the gcno files, because they are created when tor is compiled
323
reset-gcov:
324
325
	rm -f $(top_builddir)/src/*/*.gcda $(top_builddir)/src/*/*/*.gcda \
	      $(top_builddir)/src/*/*.gcov $(top_builddir)/src/*/*/*.gcov
326

327
HTML_COVER_DIR=$(top_builddir)/coverage_html
328
coverage-html: all
329
if COVERAGE_ENABLED
Nick Mathewson's avatar
Nick Mathewson committed
330
	test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
331
332
	test -d "$(HTML_COVER_DIR)" || $(MKDIR_P) "$(HTML_COVER_DIR)"
	lcov --rc lcov_branch_coverage=1 --directory $(top_builddir)/src --zerocounters
Nick Mathewson's avatar
Nick Mathewson committed
333
334
	$(MAKE) reset-gcov
	$(MAKE) check
335
	lcov --capture --rc lcov_branch_coverage=1 --no-external --directory $(top_builddir) --base-directory $(top_srcdir) --output-file "$(HTML_COVER_DIR)/lcov.tmp"
336
337
	lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
	genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"
338
339
340
else
	@printf "Not configured with --enable-coverage, run ./configure --enable-coverage\n"
endif
341

342
343
344
345
346
347
348
coverage-html-full: all
	test -e "`which lcov`" || (echo "lcov must be installed. See <http://ltp.sourceforge.net/coverage/lcov.php>." && false)
	test -d "$(HTML_COVER_DIR)" || mkdir -p "$(HTML_COVER_DIR)"
	lcov --rc lcov_branch_coverage=1 --directory ./src --zerocounters
	$(MAKE) reset-gcov
	$(MAKE) check
	$(MAKE) test-stem-full
349
350
	CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh
	CHUTNEY_TOR=tor-cov CHUTNEY_TOR_GENCERT=tor-cov-gencert $(top_srcdir)/src/test/test-network.sh --flavor hs
351
352
353
354
	lcov --capture --rc lcov_branch_coverage=1 --no-external --directory . --output-file "$(HTML_COVER_DIR)/lcov.tmp"
	lcov --remove "$(HTML_COVER_DIR)/lcov.tmp" --rc lcov_branch_coverage=1 'test/*' 'ext/tinytest*' '/usr/*' --output-file "$(HTML_COVER_DIR)/lcov.info"
	genhtml --branch-coverage -o "$(HTML_COVER_DIR)" "$(HTML_COVER_DIR)/lcov.info"

355
356
# For scripts: avoid src/ext and src/trunnel.
OWNED_TOR_C_FILES=\
357
		$(top_srcdir)/src/lib/*/*.[ch] \
358
359
360
		$(top_srcdir)/src/core/*/*.[ch] \
		$(top_srcdir)/src/feature/*/*.[ch] \
		$(top_srcdir)/src/app/*/*.[ch] \
361
		$(top_srcdir)/src/test/*.[ch] \
362
		$(top_srcdir)/src/test/*/*.[ch] \
363
		$(top_srcdir)/src/tools/*.[ch]
364
365
366
367
368

check-spaces:
if USE_PERL
	$(PERL) $(top_srcdir)/scripts/maint/checkSpace.pl -C \
		$(OWNED_TOR_C_FILES)
369
endif
370

371
372
check-includes:
if USEPYTHON
373
	$(PYTHON) $(top_srcdir)/scripts/maint/practracker/includes.py $(top_srcdir)
374
375
endif

376
377
check-best-practices:
if USEPYTHON
378
	@$(PYTHON) $(top_srcdir)/scripts/maint/practracker/practracker.py $(top_srcdir) $(TOR_PRACTRACKER_OPTIONS)
379
380
endif

381
382
383
practracker-regen:
	$(PYTHON) $(top_srcdir)/scripts/maint/practracker/practracker.py --regen $(top_srcdir)

384
385
check-docs: all
	$(PERL) $(top_builddir)/scripts/maint/checkOptionDocs.pl
386

387
check-logs:
388
389
	$(top_srcdir)/scripts/maint/checkLogs.pl \
		$(top_srcdir)/src/*/*.[ch] | sort -n
390

391
392
393
394
.PHONY: check-typos
check-typos:
	@if test -x "`which misspell 2>&1;true`"; then \
		echo "Checking for Typos ..."; \
395
396
		(misspell \
			$(top_srcdir)/src/[^e]*/*.[ch] \
397
398
399
400
401
402
403
404
405
406
407
408
409
410
			$(top_srcdir)/doc \
			$(top_srcdir)/contrib \
			$(top_srcdir)/scripts \
			$(top_srcdir)/README \
			$(top_srcdir)/ChangeLog \
			$(top_srcdir)/INSTALL \
			$(top_srcdir)/ReleaseNotes \
			$(top_srcdir)/LICENSE); \
	else \
		echo "Tor can use misspell to check for typos."; \
		echo "It seems that you don't have misspell installed."; \
		echo "You can install the latest version of misspell here: https://github.com/client9/misspell#install"; \
	fi

cypherpunks's avatar
cypherpunks committed
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
.PHONY: rustfmt
rustfmt:
if USE_RUST
	@if test -x "`which cargo-fmt 2>&1;true`"; then \
		echo "Formatting Rust code ..."; \
		(cd "$(top_srcdir)/src/rust" && cargo fmt --all --); \
	else \
		echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
		echo "However, it seems that you don't have rustfmt installed."; \
		printf "You can install rustfmt by following the directions here:"; \
		echo " https://github.com/rust-lang-nursery/rustfmt"; \
	fi
endif

.PHONY: check-rustfmt
check-rustfmt:
if USE_RUST
	@if test -x "`which cargo-fmt 2>&1;true`"; then \
		printf "Running rustfmt..."; \
		(cd "$(top_srcdir)/src/rust" && cargo fmt --all -- --check && echo "done.") || \
		(echo "**************** check-rustfmt failed. ****************"; \
		 echo "   Run \`make rustfmt\` to apply the above changes."; \
		 exit 1); \
	else \
		echo "Tor uses rustfmt (via cargo-fmt) to format Rust code."; \
		echo "However, it seems that you don't have rustfmt installed."; \
		printf "You can install rustfmt by following the directions here:"; \
		echo " https://github.com/rust-lang-nursery/rustfmt"; \
	fi
endif

442
443
444
445
446
447
448
449
450
451
452
453
454
455
.PHONY: clippy
clippy:
if USE_RUST
	@if test -x "`which cargo-clippy 2>&1;true`"; then \
		echo "Running cargo clippy ..."; \
		echo "Prepare yourself for the onslaught of suggestions ..."; \
		(cd "$(top_srcdir)/src/rust" && cargo clippy); \
	else \
		echo "Tor can use clippy to lint Rust code."; \
		echo "However, it seems that you don't have clippy installed."; \
		echo "You can install the latest version of clippy by following the directions here: https://github.com/rust-lang-nursery/rust-clippy"; \
	fi
endif

456
457
.PHONY: check-changes
check-changes:
458
if USEPYTHON
459
	@if test -d "$(top_srcdir)/changes"; then \
460
		PACKAGE_VERSION=$(PACKAGE_VERSION) $(PYTHON) $(top_srcdir)/scripts/maint/lintChanges.py $(top_srcdir)/changes; \
461
		fi
462
endif
463

464
465
.PHONY: update-versions
update-versions:
466
	abs_top_srcdir="$(abs_top_srcdir)" $(PYTHON) $(top_srcdir)/scripts/maint/update_versions.py
467

468
469
470
471
.PHONY: callgraph
callgraph:
	$(top_builddir)/scripts/maint/run_calltool.sh

472
473
474
475
476
477
478
version:
	@echo "Tor @VERSION@"
	@if test -d "$(top_srcdir)/.git" && test -x "`which git 2>&1;true`"; then \
	   echo -n "git: " ;\
	   (cd "$(top_srcdir)" && git rev-parse --short=16 HEAD); \
	fi

479
480
.PHONY: autostyle-ifdefs
autostyle-ifdefs:
481
	$(PYTHON) scripts/maint/annotate_ifdef_directives.py $(OWNED_TOR_C_FILES)
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497

.PHONY: autostyle-ifdefs
autostyle-operators:
	$(PERL) scripts/coccinelle/test-operator-cleanup $(OWNED_TOR_C_FILES)

.PHONY: rectify-includes
rectify-includes:
	$(PYTHON) scripts/maint/rectify_include_paths.py

.PHONY: update-copyright
update-copyright:
	$(PERL) scripts/maint/updateCopyright.pl $(OWNED_TOR_C_FILES)

.PHONY: autostyle
autostyle: update-versions rustfmt autostyle-ifdefs rectify-includes

498
mostlyclean-local:
499
500
501
	rm -f $(top_builddir)/src/*/*.gc{da,no} $(top_builddir)/src/*/*/*.gc{da,no}
	rm -rf $(HTML_COVER_DIR)
	rm -rf $(top_builddir)/doc/doxygen
502
	rm -rf $(TEST_NETWORK_ALL_LOG_DIR)
503
504
505

clean-local:
	rm -rf $(top_builddir)/src/rust/target
506
	rm -rf $(top_builddir)/src/rust/.cargo/registry
507
508
509
510
511

if USE_RUST
distclean-local: distclean-rust
endif

512
513
514
515
516
517
518
519
# This relies on some internal details of how automake implements
# distcheck.  We check two directories because automake-1.15 changed
# from $(distdir)/_build to $(distdir)/_build/sub.
show-distdir-testlog:
	@if test -d "$(distdir)/_build/sub"; then \
	  cat $(distdir)/_build/sub/$(TEST_SUITE_LOG); \
	else \
	  cat $(distdir)/_build/$(TEST_SUITE_LOG); fi
520

Taylor Yu's avatar
Taylor Yu committed
521
522
523
524
525
526
527
528
529
# Similarly, this relies on automake internals to run file on an
# intermittent core file whose provenance is not known to us.  See
# ticket 26787.
show-distdir-core:
	@if test -d "$(distdir)/_build/sub"; then \
	  file $(distdir)/_build/sub/core ; \
	else \
	  file $(distdir)/_build/core; fi

530
531
532
533
534
show-libs:
	@echo $(TOR_INTERNAL_LIBS)

show-testing-libs:
	@echo $(TOR_INTERNAL_TESTING_LIBS)