From 82a97066f842f34db2556673d421aa9290ffe757 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Mon, 2 Nov 2026 17:04:36 +0100 Subject: Keep the build's own flags out of CFLAGS, CPPFLAGS, LDFLAGS and LDLIBS --- Makefile | 22 ++++++++++++---------- Mk/gzip.mk | 2 +- Mk/release.mk | 2 +- Mk/tests.mk | 12 ++++++------ Mk/zstd.mk | 2 +- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 688a2c4..ddf1e05 100644 --- a/Makefile +++ b/Makefile @@ -29,14 +29,19 @@ include Mk/gzip.mk # arc4random is part of libc on the BSDs, on macOS and on glibc 2.36 and # newer. On an older glibc or on musl it comes from libbsd instead. -#LDFLAGS+=-lbsd +#OT_LDLIBS+=-lbsd -CFLAGS+=-Wall -Wextra -Wwrite-strings -pipe -pthread -LDFLAGS+=-pthread +CFLAGS?=-O3 + +# What the build requires, whatever you do to those. +OT_CFLAGS+=-Wall -Wextra -Wwrite-strings -pipe -pthread +OT_LDFLAGS+=-pthread -OPTS_production=-O3 OPTS_debug=-D_DEBUG -g -ggdb +COMPILE=$(CPPFLAGS) $(OT_CFLAGS) $(FEATURES) +LINK=$(LDFLAGS) $(OT_LDFLAGS) $(LDLIBS) $(OT_LDLIBS) + BINARY=opentracker 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 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 @@ -49,20 +54,17 @@ BINARIES=$(BINARY) $(BINARY).debug BUILDSTAMP=.buildstamp BUILDDEPS=Makefile $(BUILDSTAMP) -CFLAGS_production=$(CFLAGS) $(OPTS_production) $(FEATURES) -CFLAGS_debug=$(CFLAGS) $(OPTS_debug) $(FEATURES) - all: $(BINARY) $(BINARY).debug $(BINARY): $(SOURCES) $(HEADERS) $(BUILDDEPS) - $(CC) -o $@ $(CFLAGS_production) $(SOURCES) $(LDFLAGS) + $(CC) -o $@ $(CFLAGS) $(COMPILE) $(SOURCES) $(LINK) $(STRIP) $@ $(BINARY).debug: $(SOURCES) $(HEADERS) $(BUILDDEPS) - $(CC) -o $@ $(CFLAGS_debug) $(SOURCES) $(LDFLAGS) + $(CC) -o $@ $(OPTS_debug) $(COMPILE) $(SOURCES) $(LINK) $(BUILDSTAMP): FORCE - @echo "$(CFLAGS) $(FEATURES) $(LDFLAGS)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(FEATURES) $(LDFLAGS)" > $@ + @echo "$(CFLAGS) $(COMPILE) $(LINK)" | cmp -s - $@ 2>/dev/null || echo "$(CFLAGS) $(COMPILE) $(LINK)" > $@ clean: rm -rf $(BINARIES) $(BINARIES:=.dSYM) $(BUILDSTAMP) *.o *~ diff --git a/Mk/gzip.mk b/Mk/gzip.mk index 70d6d62..3ae53b3 100644 --- a/Mk/gzip.mk +++ b/Mk/gzip.mk @@ -1,4 +1,4 @@ FEATURES+=-DWANT_COMPRESSION_GZIP #FEATURES+=-DWANT_COMPRESSION_GZIP_ALWAYS -LDFLAGS+=-lz +OT_LDLIBS+=-lz diff --git a/Mk/release.mk b/Mk/release.mk index 63429ad..5c4afe9 100644 --- a/Mk/release.mk +++ b/Mk/release.mk @@ -9,7 +9,7 @@ HAVE_GIT=command -v git >/dev/null && test -d .git GIT_VERSION=`sh -c '$(TARBALL_VERSION) || { $(HAVE_GIT) && git describe --tags --match "v*" --always --dirty 2>/dev/null; }'` OT_TAG=`sh -c '$(TARBALL_VERSION) || { $(HAVE_GIT) && git describe --tags --match "v*" --exact-match 2>/dev/null; }'` -CFLAGS+=-DOT_VERSION=\"$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\" -DOT_TAG=\"$(OT_TAG)\" +OT_CFLAGS+=-DOT_VERSION=\"$(VERSION)\" -DGIT_VERSION=\"$(GIT_VERSION)\" -DOT_TAG=\"$(OT_TAG)\" # Roll a release: tag it v$(VERSION), then make dist. The tarball is HEAD by # construction, so the working tree it was rolled from does not enter into it. diff --git a/Mk/tests.mk b/Mk/tests.mk index d542044..8e63839 100644 --- a/Mk/tests.mk +++ b/Mk/tests.mk @@ -11,12 +11,12 @@ TEST_HEADERS=tests/test.h $(HEADERS) # A test binary is not a production binary, so it is built with the features # the tests need to reach. FEATURES_test=$(FEATURES) -DWANT_ACCESSLIST_BLACK -DWANT_SYNC_LIVE -CFLAGS_test=$(CFLAGS) -I. -g -O1 $(FEATURES_test) +CFLAGS_test=-I. -g -O1 $(CPPFLAGS) $(OT_CFLAGS) $(FEATURES_test) # clang over $(CC) because the two toolchains do not check the same things. CC_sanitize?=clang CFLAGS_sanitize=$(CFLAGS_test) -fsanitize=address,undefined -fno-omit-frame-pointer -LDFLAGS_sanitize=$(LDFLAGS) -fsanitize=address,undefined +LDFLAGS_sanitize=$(LINK) -fsanitize=address,undefined # Black box tests drive the real binary over the wire, so they cover the event # loop and the parsers working together. The client timeout is cut right down @@ -24,10 +24,10 @@ LDFLAGS_sanitize=$(LDFLAGS) -fsanitize=address,undefined # mirrors these two numbers. PYTHON?=python3 FEATURES_integration=$(FEATURES) -DWANT_IP_FROM_QUERY_STRING -DWANT_ACCESSLIST_BLACK -DWANT_DYNAMIC_ACCESSLIST -DWANT_KEEPALIVE -DOT_CLIENT_TIMEOUT=5 -DOT_CLIENT_TIMEOUT_CHECKINTERVAL=1 -CFLAGS_integration=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer -LDFLAGS_integration=$(LDFLAGS) -fsanitize=address,undefined -CFLAGS_tsan=$(CFLAGS) $(OPTS_debug) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer -LDFLAGS_tsan=$(LDFLAGS) -fsanitize=thread +CFLAGS_integration=$(OPTS_debug) $(CPPFLAGS) $(OT_CFLAGS) $(FEATURES_integration) -fsanitize=address,undefined -fno-omit-frame-pointer +LDFLAGS_integration=$(LINK) -fsanitize=address,undefined +CFLAGS_tsan=$(OPTS_debug) $(CPPFLAGS) $(OT_CFLAGS) $(FEATURES_integration) -fsanitize=thread -fno-omit-frame-pointer +LDFLAGS_tsan=$(LINK) -fsanitize=thread BINARIES+=$(TESTBIN) $(TESTBIN).poll $(TESTBIN).sanitize opentracker.integration opentracker.tsan diff --git a/Mk/zstd.mk b/Mk/zstd.mk index 2bb56be..8c1fc40 100644 --- a/Mk/zstd.mk +++ b/Mk/zstd.mk @@ -1,3 +1,3 @@ FEATURES+=-DWANT_COMPRESSION_ZSTD #FEATURES+=-DWANT_COMPRESSION_ZSTD_ALWAYS -LDFLAGS+=-lzstd +OT_LDLIBS+=-lzstd -- cgit v1.3