diff options
Diffstat (limited to 'Makefile')
| -rw-r--r-- | Makefile | 94 |
1 files changed, 52 insertions, 42 deletions
| @@ -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 | ||
| 14 | PREFIX?=.. | 3 | PREFIX?=.. |
| 15 | LIBOWFAT_HEADERS=$(PREFIX)/libowfat | ||
| 16 | LIBOWFAT_LIBRARY=$(PREFIX)/libowfat | ||
| 17 | |||
| 18 | BINDIR?=$(PREFIX)/bin | 4 | BINDIR?=$(PREFIX)/bin |
| 19 | STRIP?=strip | 5 | STRIP?=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 | ||
| 58 | GIT_VERSION=`sh -c 'command -v git >/dev/null && test -d .git && git rev-parse HEAD || echo _git_or_commit_not_found_'` | 42 | VERSION=1.0.0 |
| 43 | TARBALL_VERSION=test -r .tarball-version && read v < .tarball-version && echo "$$v" | ||
| 44 | HAVE_GIT=command -v git >/dev/null && test -d .git | ||
| 45 | GIT_VERSION=`sh -c '$(TARBALL_VERSION) || { $(HAVE_GIT) && git describe --tags --match "v*" --always --dirty 2>/dev/null; }'` | ||
| 46 | OT_TAG=`sh -c '$(TARBALL_VERSION) || { $(HAVE_GIT) && git describe --tags --match "v*" --exact-match 2>/dev/null; }'` | ||
| 59 | 47 | ||
| 60 | OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage | 48 | OPTS_debug=-D_DEBUG -g -ggdb # -pg -fprofile-arcs -ftest-coverage |
| 61 | OPTS_production=-O3 | 49 | OPTS_production=-O3 |
| 62 | 50 | ||
| 63 | CFLAGS+=-DGIT_VERSION=$(GIT_VERSION) -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic | 51 | CFLAGS+=-DOT_VERSION=\"$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\" -DOT_TAG=\"$(OT_TAG)\" -Wall -pipe -pthread -Wextra -Wwrite-strings #-ansi -pedantic |
| 64 | LDFLAGS+=-pthread | 52 | LDFLAGS+=-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. | 55 | BUILDSTAMP=.buildstamp |
| 68 | CFLAGS_libowfat=-I$(LIBOWFAT_HEADERS) | 56 | BUILDDEPS=Makefile $(BUILDSTAMP) |
| 69 | LDFLAGS_libowfat=-L$(LIBOWFAT_LIBRARY) -lowfat | 57 | |
| 58 | $(BUILDSTAMP): FORCE | ||
| 59 | @echo "$(CFLAGS) $(FEATURES) $(LDFLAGS)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(FEATURES) $(LDFLAGS)" > $@ | ||
| 60 | |||
| 61 | FORCE: | ||
| 70 | 62 | ||
| 71 | BINARY =opentracker | 63 | BINARY =opentracker |
| 72 | HEADERS=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 | 64 | HEADERS=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 |
| 73 | SOURCES=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 | 65 | SOURCES=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 |
| 74 | 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 | ||
| 75 | 66 | ||
| 76 | all: $(BINARY) $(BINARY).debug | 67 | all: $(BINARY) $(BINARY).debug |
| 77 | 68 | ||
| 78 | CFLAGS_production = $(CFLAGS) $(OPTS_production) $(FEATURES) | 69 | CFLAGS_production = $(CFLAGS) $(OPTS_production) $(FEATURES) |
| 79 | CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES) | 70 | CFLAGS_debug = $(CFLAGS) $(OPTS_debug) $(FEATURES) |
| 80 | 71 | ||
| 81 | CFLAGS_proxy = $(CFLAGS_production) $(CFLAGS_libowfat) -DWANT_SYNC_LIVE | 72 | $(BINARY): $(SOURCES) $(HEADERS) $(BUILDDEPS) |
| 82 | CFLAGS_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) |
| 89 | proxy: $(SOURCES_proxy) $(HEADERS) | 77 | |
| 90 | $(CC) -o $@ $(CFLAGS_proxy) $(SOURCES_proxy) $(LDFLAGS) $(LDFLAGS_libowfat) | 78 | # The proxy is out of service |
| 91 | proxy.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. |
| 98 | TESTBIN=tests/runner | 93 | TESTBIN=tests/runner |
| 99 | TEST_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 | 94 | TEST_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 |
| 100 | TEST_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 | 95 | TEST_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 |
| 101 | TEST_HEADERS=tests/test.h $(HEADERS) | 96 | TEST_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. |
| 104 | FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE | 99 | FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE |
| 105 | CFLAGS_test = $(CFLAGS) -I. -g -O1 $(FEATURES_test) | 100 | CFLAGS_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 | ||
| 110 | check: $(TESTBIN) $(BINARY) | 105 | check: $(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 | ||
| 116 | check-poll: $(TESTBIN).poll | 111 | check-poll: $(TESTBIN).poll |
| @@ -123,7 +118,7 @@ CC_sanitize?=clang | |||
| 123 | CFLAGS_sanitize=$(CFLAGS_test) -fsanitize=address,undefined -fno-omit-frame-pointer | 118 | CFLAGS_sanitize=$(CFLAGS_test) -fsanitize=address,undefined -fno-omit-frame-pointer |
| 124 | LDFLAGS_sanitize=$(LDFLAGS) -fsanitize=address,undefined | 119 | LDFLAGS_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 | ||
| 129 | check-sanitize: $(TESTBIN).sanitize | 124 | check-sanitize: $(TESTBIN).sanitize |
| @@ -140,7 +135,7 @@ FEATURES_integration=$(FEATURES) -DWANT_IP_FROM_QUERY_STRING -DWANT_ACCESSLIST_B | |||
| 140 | CFLAGS_integration=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer | 135 | CFLAGS_integration=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer |
| 141 | LDFLAGS_integration=$(LDFLAGS) -fsanitize=address,undefined | 136 | LDFLAGS_integration=$(LDFLAGS) -fsanitize=address,undefined |
| 142 | 137 | ||
| 143 | opentracker.integration: $(SOURCES) $(HEADERS) | 138 | opentracker.integration: $(SOURCES) $(HEADERS) $(BUILDDEPS) |
| 144 | $(CC) -o $@ $(CFLAGS_integration) $(SOURCES) $(LDFLAGS_integration) | 139 | $(CC) -o $@ $(CFLAGS_integration) $(SOURCES) $(LDFLAGS_integration) |
| 145 | 140 | ||
| 146 | check-integration: opentracker.integration | 141 | check-integration: opentracker.integration |
| @@ -150,7 +145,7 @@ check-integration: opentracker.integration | |||
| 150 | CFLAGS_tsan=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer | 145 | CFLAGS_tsan=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer |
| 151 | LDFLAGS_tsan=$(LDFLAGS) -fsanitize=thread | 146 | LDFLAGS_tsan=$(LDFLAGS) -fsanitize=thread |
| 152 | 147 | ||
| 153 | opentracker.tsan: $(SOURCES) $(HEADERS) | 148 | opentracker.tsan: $(SOURCES) $(HEADERS) $(BUILDDEPS) |
| 154 | $(CC) -o $@ $(CFLAGS_tsan) $(SOURCES) $(LDFLAGS_tsan) | 149 | $(CC) -o $@ $(CFLAGS_tsan) $(SOURCES) $(LDFLAGS_tsan) |
| 155 | 150 | ||
| 156 | check-tsan: opentracker.tsan | 151 | check-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 | ||
| 169 | BINARIES=opentracker opentracker.debug opentracker.integration opentracker.tsan proxy proxy.debug $(TESTBIN) $(TESTBIN).sanitize $(TESTBIN).poll | 164 | BINARIES=opentracker opentracker.debug opentracker.integration opentracker.tsan $(TESTBIN) $(TESTBIN).sanitize $(TESTBIN).poll |
| 170 | 165 | ||
| 171 | clean: | 166 | clean: |
| 172 | rm -rf $(BINARIES) $(BINARIES:=.dSYM) *.o *~ | 167 | rm -rf $(BINARIES) $(BINARIES:=.dSYM) $(BUILDSTAMP) *.o *~ |
| 173 | 168 | ||
| 174 | install: | 169 | install: |
| 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. | ||
| 176 | DISTNAME=opentracker-$(VERSION) | ||
| 177 | |||
| 178 | dist: | ||
| 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) | ||
