summaryrefslogtreecommitdiff
path: root/Makefile
diff options
context:
space:
mode:
Diffstat (limited to 'Makefile')
-rw-r--r--Makefile94
1 files changed, 52 insertions, 42 deletions
diff --git a/Makefile b/Makefile
index 0e5e985..a665890 100644
--- a/Makefile
+++ b/Makefile
@@ -1,20 +1,6 @@
1# $Id$ 1# $Id$
2 2
3# Linux flavour
4# PREFIX?=/opt/diet
5# LIBOWFAT_HEADERS=$(PREFIX)/include
6# LIBOWFAT_LIBRARY=$(PREFIX)/lib
7
8# BSD flavour
9# PREFIX?=/usr/local
10# LIBOWFAT_HEADERS=$(PREFIX)/include/libowfat
11# LIBOWFAT_LIBRARY=$(PREFIX)/lib
12
13# Debug flavour
14PREFIX?=.. 3PREFIX?=..
15LIBOWFAT_HEADERS=$(PREFIX)/libowfat
16LIBOWFAT_LIBRARY=$(PREFIX)/libowfat
17
18BINDIR?=$(PREFIX)/bin 4BINDIR?=$(PREFIX)/bin
19STRIP?=strip 5STRIP?=strip
20 6
@@ -36,10 +22,8 @@ include Makefile.gzip
36# in Makefile.zstd 22# in Makefile.zstd
37#include Makefile.zstd 23#include Makefile.zstd
38 24
39#FEATURES+=-DWANT_LOG_NETWORKS
40#FEATURES+=-DWANT_RESTRICT_STATS 25#FEATURES+=-DWANT_RESTRICT_STATS
41#FEATURES+=-DWANT_IP_FROM_PROXY 26#FEATURES+=-DWANT_IP_FROM_PROXY
42#FEATURES+=-DWANT_FULLLOG_NETWORKS
43#FEATURES+=-DWANT_LOG_NUMWANT 27#FEATURES+=-DWANT_LOG_NUMWANT
44#FEATURES+=-DWANT_MODEST_FULLSCRAPES 28#FEATURES+=-DWANT_MODEST_FULLSCRAPES
45#FEATURES+=-DWANT_SPOT_WOODPECKER 29#FEATURES+=-DWANT_SPOT_WOODPECKER
@@ -55,62 +39,73 @@ FEATURES+=-DWANT_FULLSCRAPE
55#FEATURES+=-D_DEBUG_HTTPERROR 39#FEATURES+=-D_DEBUG_HTTPERROR
56#FEATURES+=-D_DEBUG_RANDOMTORRENTS 40#FEATURES+=-D_DEBUG_RANDOMTORRENTS
57 41
58GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse HEAD || echo _git_or_commit_not_found_'` 42VERSION=1.0.0
43TARBALL_VERSION=test -r .tarball-version && read v < .tarball-version && echo "$$v"
44HAVE_GIT=command -v git >/dev/null && test -d .git
45GIT_VERSION=`sh -c '$(TARBALL_VERSION) || { $(HAVE_GIT) && git describe --tags --match "v*" --always --dirty 2>/dev/null; }'`
46OT_TAG=`sh -c '$(TARBALL_VERSION) || { $(HAVE_GIT) && git describe --tags --match "v*" --exact-match 2>/dev/null; }'`
59 47
60OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage 48OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage
61OPTS_production=-O3 49OPTS_production=-O3
62 50
63CFLAGS+=-DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic 51CFLAGS+=-DOT_VERSION=\"$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\" -DOT_TAG=\"$(OT_TAG)\" -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic
64LDFLAGS+=-pthread 52LDFLAGS+=-pthread
65 53
66# Only the proxy, which has not been ported since the tracker went dual stack, 54# Record feature flags as a dep to allow rebuild when they change
67# still wants libowfat. 55BUILDSTAMP=.buildstamp
68CFLAGS_libowfat=-I$(LIBOWFAT_HEADERS) 56BUILDDEPS=Makefile $(BUILDSTAMP)
69LDFLAGS_libowfat=-L$(LIBOWFAT_LIBRARY) -lowfat 57
58$(BUILDSTAMP): FORCE
59 @echo "$(CFLAGS) $(FEATURES) $(LDFLAGS)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(FEATURES) $(LDFLAGS)" > $@
60
61FORCE:
70 62
71BINARY =opentracker 63BINARY =opentracker
72HEADERS=trackerlogic.h ot_urlencoded.h ot_batch.h ot_buf.h ot_event.h ot_fdstate.h ot_fmt.h ot_hex.h ot_ip.h ot_config.h ot_scan.h ot_socket.h ot_tcp.h ot_worker.h ot_workqueue.h ot_mutex.h ot_random.h ot_stats.h ot_vector.h ot_clean.h ot_udp.h ot_iovec.h ot_fullscrape.h ot_accesslist.h ot_http.h ot_livesync.h ot_rijndael.h 64HEADERS=trackerlogic.h ot_urlencoded.h ot_batch.h ot_buf.h ot_event.h ot_fdstate.h ot_fmt.h ot_hex.h ot_ip.h ot_config.h ot_scan.h ot_socket.h ot_tcp.h ot_worker.h ot_workqueue.h ot_mutex.h ot_random.h ot_stats.h ot_vector.h ot_clean.h ot_udp.h ot_iovec.h ot_fullscrape.h ot_accesslist.h ot_http.h ot_livesync.h ot_rijndael.h
73SOURCES=opentracker.c trackerlogic.c ot_urlencoded.c ot_batch.c ot_buf.c ot_event.c ot_fdstate.c ot_fmt.c ot_hex.c ot_ip.c ot_config.c ot_scan.c ot_socket.c ot_tcp.c ot_worker.c ot_workqueue.c ot_mutex.c ot_random.c ot_stats.c ot_vector.c ot_clean.c ot_udp.c ot_iovec.c ot_fullscrape.c ot_accesslist.c ot_http.c ot_livesync.c ot_rijndael.c 65SOURCES=opentracker.c trackerlogic.c ot_urlencoded.c ot_batch.c ot_buf.c ot_event.c ot_fdstate.c ot_fmt.c ot_hex.c ot_ip.c ot_config.c ot_scan.c ot_socket.c ot_tcp.c ot_worker.c ot_workqueue.c ot_mutex.c ot_random.c ot_stats.c ot_vector.c ot_clean.c ot_udp.c ot_iovec.c ot_fullscrape.c ot_accesslist.c ot_http.c ot_livesync.c ot_rijndael.c
74SOURCES_proxy=proxy.c ot_batch.c ot_fdstate.c ot_vector.c ot_mutex.c ot_random.c ot_scan.c ot_ip.c ot_socket.c
75 66
76all: $(BINARY) $(BINARY).debug 67all: $(BINARY) $(BINARY).debug
77 68
78CFLAGS_production = $(CFLAGS) $(OPTS_production) $(FEATURES) 69CFLAGS_production = $(CFLAGS) $(OPTS_production) $(FEATURES)
79CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES) 70CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES)
80 71
81CFLAGS_proxy = $(CFLAGS_production) $(CFLAGS_libowfat) -DWANT_SYNC_LIVE 72$(BINARY): $(SOURCES) $(HEADERS) $(BUILDDEPS)
82CFLAGS_proxy_debug = $(CFLAGS_debug) $(CFLAGS_libowfat) -DWANT_SYNC_LIVE
83
84$(BINARY): $(SOURCES) $(HEADERS)
85 $(CC) -o $@ $(CFLAGS_production) $(SOURCES) $(LDFLAGS) 73 $(CC) -o $@ $(CFLAGS_production) $(SOURCES) $(LDFLAGS)
86 $(STRIP) $@ 74 $(STRIP) $@
87$(BINARY).debug: $(SOURCES) $(HEADERS) 75$(BINARY).debug: $(SOURCES) $(HEADERS) $(BUILDDEPS)
88 $(CC) -o $@ $(CFLAGS_debug) $(SOURCES) $(LDFLAGS) 76 $(CC) -o $@ $(CFLAGS_debug) $(SOURCES) $(LDFLAGS)
89proxy: $(SOURCES_proxy) $(HEADERS) 77
90 $(CC) -o $@ $(CFLAGS_proxy) $(SOURCES_proxy) $(LDFLAGS) $(LDFLAGS_libowfat) 78# The proxy is out of service
91proxy.debug: $(SOURCES_proxy) $(HEADERS) 79#
92 $(CC) -o $@ $(CFLAGS_proxy_debug) $(SOURCES_proxy) $(LDFLAGS) $(LDFLAGS_libowfat) 80# SOURCES_proxy=proxy.c ot_batch.c ot_fdstate.c ot_vector.c ot_mutex.c ot_random.c ot_scan.c ot_ip.c ot_socket.c
81# CFLAGS_proxy = $(CFLAGS_production) -DWANT_SYNC_LIVE
82# CFLAGS_proxy_debug = $(CFLAGS_debug) -DWANT_SYNC_LIVE
83#
84# proxy: $(SOURCES_proxy) $(HEADERS) $(BUILDDEPS)
85# $(CC) -o $@ $(CFLAGS_proxy) $(SOURCES_proxy) $(LDFLAGS)
86# proxy.debug: $(SOURCES_proxy) $(HEADERS) $(BUILDDEPS)
87# $(CC) -o $@ $(CFLAGS_proxy_debug) $(SOURCES_proxy) $(LDFLAGS)
93 88
94# Unit tests. The modules under test are compiled straight into the test 89# Unit tests. The modules under test are compiled straight into the test
95# binary, so a test may reach a static function by including the source if it 90# binary, so a test may reach a static function by including the source if it
96# has to. tests/stubs.c supplies the few symbols those modules reference but 91# has to. tests/stubs.c supplies the few symbols those modules reference but
97# the tests never reach. 92# the tests never reach.
98TESTBIN=tests/runner 93TESTBIN=tests/runner
99TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_urlencoded.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c tests/t_mutex.c tests/t_workqueue.c tests/t_batch.c tests/t_fdstate.c tests/t_event.c tests/t_fmt.c 94TEST_SOURCES=tests/runner.c tests/test.c tests/stubs.c tests/t_urlencoded.c tests/t_iovec.c tests/t_vector.c tests/t_random.c tests/t_hex.c tests/t_accesslist.c tests/t_scan.c tests/t_buf.c tests/t_ip.c tests/t_socket.c tests/t_mutex.c tests/t_trackerlogic.c tests/t_workqueue.c tests/t_batch.c tests/t_fdstate.c tests/t_event.c tests/t_fmt.c
100TEST_UNITS=ot_urlencoded.c ot_fmt.c ot_event.c ot_batch.c ot_fdstate.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c ot_mutex.c ot_workqueue.c 95TEST_UNITS=ot_urlencoded.c ot_fmt.c ot_event.c ot_batch.c ot_fdstate.c ot_buf.c ot_ip.c ot_socket.c ot_iovec.c ot_vector.c ot_random.c ot_hex.c ot_scan.c ot_accesslist.c ot_mutex.c ot_workqueue.c trackerlogic.c
101TEST_HEADERS=tests/test.h $(HEADERS) 96TEST_HEADERS=tests/test.h $(HEADERS)
102# Tests reach code that sits behind feature flags, so the units under test are 97# Tests reach code that sits behind feature flags, so the units under test are
103# built with those features enabled. A test binary is not a production binary. 98# built with those features enabled. A test binary is not a production binary.
104FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE 99FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE
105CFLAGS_test = $(CFLAGS) -I. -g -O1 $(FEATURES_test) 100CFLAGS_test = $(CFLAGS) -I. -g -O1 $(FEATURES_test)
106 101
107$(TESTBIN): $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) 102$(TESTBIN): $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
108 $(CC) -o $@ $(CFLAGS_test) $(TEST_SOURCES) $(TEST_UNITS) 103 $(CC) -o $@ $(CFLAGS_test) $(TEST_SOURCES) $(TEST_UNITS)
109 104
110check: $(TESTBIN) $(BINARY) 105check: $(TESTBIN) $(BINARY)
111 ./$(TESTBIN) 106 ./$(TESTBIN)
112 107
113$(TESTBIN).poll: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) 108$(TESTBIN).poll: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
114 $(CC) -o $@ $(CFLAGS_test) -DOT_EVENT_FORCE_POLL $(TEST_SOURCES) $(TEST_UNITS) 109 $(CC) -o $@ $(CFLAGS_test) -DOT_EVENT_FORCE_POLL $(TEST_SOURCES) $(TEST_UNITS)
115 110
116check-poll: $(TESTBIN).poll 111check-poll: $(TESTBIN).poll
@@ -123,7 +118,7 @@ CC_sanitize?=clang
123CFLAGS_sanitize=$(CFLAGS_test) -fsanitize=address,undefined -fno-omit-frame-pointer 118CFLAGS_sanitize=$(CFLAGS_test) -fsanitize=address,undefined -fno-omit-frame-pointer
124LDFLAGS_sanitize=$(LDFLAGS) -fsanitize=address,undefined 119LDFLAGS_sanitize=$(LDFLAGS) -fsanitize=address,undefined
125 120
126$(TESTBIN).sanitize: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) 121$(TESTBIN).sanitize: $(TEST_SOURCES) $(TEST_UNITS) $(TEST_HEADERS) $(BUILDDEPS)
127 $(CC_sanitize) -o $@ $(CFLAGS_sanitize) $(TEST_SOURCES) $(TEST_UNITS) $(LDFLAGS_sanitize) 122 $(CC_sanitize) -o $@ $(CFLAGS_sanitize) $(TEST_SOURCES) $(TEST_UNITS) $(LDFLAGS_sanitize)
128 123
129check-sanitize: $(TESTBIN).sanitize 124check-sanitize: $(TESTBIN).sanitize
@@ -140,7 +135,7 @@ FEATURES_integration=$(FEATURES) -DWANT_IP_FROM_QUERY_STRING -DWANT_ACCESSLIST_B
140CFLAGS_integration=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer 135CFLAGS_integration=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer
141LDFLAGS_integration=$(LDFLAGS) -fsanitize=address,undefined 136LDFLAGS_integration=$(LDFLAGS) -fsanitize=address,undefined
142 137
143opentracker.integration: $(SOURCES) $(HEADERS) 138opentracker.integration: $(SOURCES) $(HEADERS) $(BUILDDEPS)
144 $(CC) -o $@ $(CFLAGS_integration) $(SOURCES) $(LDFLAGS_integration) 139 $(CC) -o $@ $(CFLAGS_integration) $(SOURCES) $(LDFLAGS_integration)
145 140
146check-integration: opentracker.integration 141check-integration: opentracker.integration
@@ -150,7 +145,7 @@ check-integration: opentracker.integration
150CFLAGS_tsan=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer 145CFLAGS_tsan=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer
151LDFLAGS_tsan=$(LDFLAGS) -fsanitize=thread 146LDFLAGS_tsan=$(LDFLAGS) -fsanitize=thread
152 147
153opentracker.tsan: $(SOURCES) $(HEADERS) 148opentracker.tsan: $(SOURCES) $(HEADERS) $(BUILDDEPS)
154 $(CC) -o $@ $(CFLAGS_tsan) $(SOURCES) $(LDFLAGS_tsan) 149 $(CC) -o $@ $(CFLAGS_tsan) $(SOURCES) $(LDFLAGS_tsan)
155 150
156check-tsan: opentracker.tsan 151check-tsan: opentracker.tsan
@@ -164,12 +159,27 @@ check-all:
164 $(MAKE) check-integration 159 $(MAKE) check-integration
165 $(MAKE) check-tsan 160 $(MAKE) check-tsan
166 161
167.PHONY: all check check-poll check-sanitize check-integration check-tsan check-all clean install 162.PHONY: all FORCE dist check check-poll check-sanitize check-integration check-tsan check-all clean install
168 163
169BINARIES=opentracker opentracker.debug opentracker.integration opentracker.tsan proxy proxy.debug $(TESTBIN) $(TESTBIN).sanitize $(TESTBIN).poll 164BINARIES=opentracker opentracker.debug opentracker.integration opentracker.tsan $(TESTBIN) $(TESTBIN).sanitize $(TESTBIN).poll
170 165
171clean: 166clean:
172 rm -rf $(BINARIES) $(BINARIES:=.dSYM) *.o *~ 167 rm -rf $(BINARIES) $(BINARIES:=.dSYM) $(BUILDSTAMP) *.o *~
173 168
174install: 169install:
175 install -m 755 opentracker $(DESTDIR)$(BINDIR) 170 install -m 755 opentracker $(DESTDIR)$(BINDIR)
171
172# Roll a release: tag it v<something>, then make dist. The commit is written
173# into the tarball, so a build from it reports the same version this checkout
174# would, without a git to ask. The tarball is HEAD by construction, so the
175# working tree it was rolled from does not enter into the version.
176DISTNAME=opentracker-$(VERSION)
177
178dist:
179 @test "`git describe --tags --match 'v*' --exact-match 2>/dev/null`" = "v$(VERSION)" || \
180 { echo "HEAD must carry the tag v$(VERSION). Tag the release, or correct VERSION."; exit 1; }
181 rm -rf $(DISTNAME) $(DISTNAME).tar.gz
182 git archive --format=tar --prefix=$(DISTNAME)/ HEAD | tar -xf -
183 git describe --tags --match "v*" --always > $(DISTNAME)/.tarball-version
184 tar -czf $(DISTNAME).tar.gz $(DISTNAME)
185 rm -rf $(DISTNAME)