From 1e30a0244cc691a0d0cdd6b515e2a2b099774f04 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 11:18:51 -0500 Subject: [PATCH 1/7] configure: don't use 'echo -n' under /bin/sh It's not POSIX-compatible. Use printf instead. Changelog-None --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 0cd88749dc92..cd66c46ba27e 100755 --- a/configure +++ b/configure @@ -134,7 +134,7 @@ check_command() name="$1" shift 1 - echo -n "checking for $name... " + printf 'checking for %s... ' "${name}" if "$@" >/dev/null 2>&1 Date: Sat, 7 Mar 2026 12:07:58 -0500 Subject: [PATCH 2/7] configure: be consistent in writing status output to stderr Changelog-None --- configure | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/configure b/configure index cd66c46ba27e..a79e14dd910e 100755 --- a/configure +++ b/configure @@ -134,12 +134,12 @@ check_command() name="$1" shift 1 - printf 'checking for %s... ' "${name}" + printf 'checking for %s... ' "${name}" >&2 if "$@" >/dev/null 2>&1 &2 return 0 fi - echo 'not found' + echo 'not found' >&2 return 1 } @@ -277,9 +277,9 @@ usage() add_var() { if [ -n "$2" ]; then - echo "Setting $1... $2" + echo "Setting $1... $2" >&2 else - echo "$1 not found" + echo "$1 not found" >&2 fi echo "$1=$2" >> $CONFIG_VAR_FILE.$$ [ -z "$3" ] || echo "#define $1 $2" >> "$3" @@ -334,10 +334,10 @@ for opt in "$@"; do --disable-fuzzing) FUZZING=0;; --enable-rust) RUST=1;; --disable-rust) RUST=0;; - --help|-h) usage;; + --help|-h) usage >&2;; *) echo "Unknown option '$opt'" >&2 - usage + usage >&2 ;; esac done @@ -347,7 +347,7 @@ set_defaults if [ "$ASAN" = "1" ]; then if [ "$VALGRIND" = "1" ]; then - echo "Address sanitizer (ASAN) and valgrind cannot be enabled at the same time" + echo "Address sanitizer (ASAN) and valgrind cannot be enabled at the same time" >&2 exit 1 fi @@ -381,16 +381,16 @@ else fi # We assume warning flags don't affect congfigurator that much! -printf 'Compiling %s...' "${CONFIGURATOR}" +printf 'Compiling %s...' "${CONFIGURATOR}" >&2 $CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $LDFLAGS -o $CONFIGURATOR $CONFIGURATOR.c -echo "done" +echo "done" >&2 if [ "$CLANG_COVERAGE" = "1" ]; then case "$CC" in (*"clang"*) ;; (*) - echo "Clang coverage requires building with CC=clang." + echo "Clang coverage requires building with CC=clang." >&2 exit 1 ;; esac @@ -401,7 +401,7 @@ if [ "$FUZZING" = "1" ]; then (*"clang"*) ;; (*) - echo "Fuzzing is currently only supported with clang." + echo "Fuzzing is currently only supported with clang." >&2 exit 1 ;; esac From f3b62f5ca340a235b545e4dca78600f337aa6f93 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 08:28:31 -0500 Subject: [PATCH 3/7] Makefile: use standard variables for compiling and linking C programs Make predefines variables COMPILE.c and LINK.c, providing the default commands for compiling and linking C programs: COMPILE.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(TARGET_ARCH) -c LINK.c = $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(TARGET_ARCH) Use these variables where appropriate. A few points of interest: * Using $(LINK.o) to link a C program is not correct, as it does not pass $(CFLAGS) to the linker driver. Passing $(CFLAGS) may be necessary for correct operation. For instance, -m32 can be specified in CFLAGS to build for a 32-bit ABI on a 64-bit-native system, and -flto can be specified in CFLAGS to enable link-time optimization. The linker driver needs to be told both of these in order to produce correct output. * CFLAGS is not supposed to subsume CPPFLAGS. The latter are logically the flags for the C preprocessor, while the former are the flags for the C compiler. The standard COMPILE.c variable incorporates both sets of flags since it invokes both the preprocessor and the compiler with one command. The standard LINK.c variable also incorporates both since it can be used to preprocess, compile, and link a C program all in one shot. In its more typical usage (linking precompiled object files), the linker driver accepts but makes no use of any preprocessor flags supplied to it. * CFLAGS logically shouldn't include any -D, -U, or -I options, as those are meant for the preprocessor and not the compiler. Changelog-None --- Makefile | 123 +++++++++++++++++++++++++------------------------ tools/Makefile | 2 +- 2 files changed, 63 insertions(+), 62 deletions(-) diff --git a/Makefile b/Makefile index 20d4aedff053..5503a33cbb16 100644 --- a/Makefile +++ b/Makefile @@ -289,8 +289,9 @@ PKG_CONFIG_PATH := $(SQLITE_PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH) endif endif -CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 -CFLAGS = $(CPPFLAGS) $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) -I $(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I . -I$(CPATH) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) $(CSANFLAGS) +# Put the environment-inherited flags *last* so the user has the final say. +CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 -I$(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I. -I$(CPATH) $(POSTGRES_INCLUDE) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(COMPAT_CFLAGS) +CFLAGS = $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) $(PIE_CFLAGS) $(CSANFLAGS) # If CFLAGS is already set in the environment of make (to whatever value, it # does not matter) then it would export it to subprocesses with the above value @@ -330,8 +331,8 @@ FORCE: endif show-flags: config.vars - @$(ECHO) "CC: $(CC) $(CFLAGS) -c -o" - @$(ECHO) "LD: $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) -o" + @$(ECHO) "CC: $(COMPILE.c) -o" + @$(ECHO) "LD: $(LINK.c) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) -o" # We will re-generate, but we won't generate for the first time! ccan/config.h config.vars &: configure ccan/tools/configurator/configurator.c @@ -339,7 +340,7 @@ ccan/config.h config.vars &: configure ccan/tools/configurator/configurator.c ./configure --reconfigure %.o: %.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) # tools/update-mocks.sh does nasty recursive make, must not do this! ifeq ($(SUPPRESS_GENERATION),1) @@ -798,7 +799,7 @@ $(ALL_TEST_PROGRAMS) $(ALL_FUZZ_TARGETS): %: %.o # (as per EXTERNAL_LDLIBS) so we filter them out here. We have to put the other # .a files (if any) at the end of the link line. $(ALL_PROGRAMS) $(ALL_TEST_PROGRAMS): - @$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) $(filter-out external/%,$(filter %.a,$^)) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) $($(@)_LDLIBS) -o $@) + @$(call VERBOSE, "ld $@", $(LINK.c) $(filter-out %.a,$^) $(filter-out external/%,$(filter %.a,$^)) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) $($(@)_LDLIBS) -o $@) ifeq ($(OS),Darwin) @$(call VERBOSE, "dsymutil $@", dsymutil $@) endif @@ -819,7 +820,7 @@ endif endif $(ALL_FUZZ_TARGETS): - @$(call VERBOSE, "ld $@", $(LINK.o) $(filter-out %.a,$^) libcommon.a libccan.a $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) $(FUZZ_LDFLAGS) -o $@) + @$(call VERBOSE, "ld $@", $(LINK.c) $(filter-out %.a,$^) libcommon.a libccan.a $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) $(FUZZ_LDFLAGS) -o $@) ifeq ($(OS),Darwin) @$(call VERBOSE, "dsymutil $@", dsymutil $@) endif @@ -1085,113 +1086,113 @@ clightning-$(VERSION)-$(DISTRO).tar.xz: install endif ccan-breakpoint.o: $(CCANDIR)/ccan/breakpoint/breakpoint.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-base64.o: $(CCANDIR)/ccan/base64/base64.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-tal.o: $(CCANDIR)/ccan/tal/tal.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-tal-str.o: $(CCANDIR)/ccan/tal/str/str.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-tal-link.o: $(CCANDIR)/ccan/tal/link/link.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-tal-path.o: $(CCANDIR)/ccan/tal/path/path.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-tal-grab_file.o: $(CCANDIR)/ccan/tal/grab_file/grab_file.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-take.o: $(CCANDIR)/ccan/take/take.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-list.o: $(CCANDIR)/ccan/list/list.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-asort.o: $(CCANDIR)/ccan/asort/asort.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-ptr_valid.o: $(CCANDIR)/ccan/ptr_valid/ptr_valid.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-read_write_all.o: $(CCANDIR)/ccan/read_write_all/read_write_all.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-str.o: $(CCANDIR)/ccan/str/str.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-opt.o: $(CCANDIR)/ccan/opt/opt.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-opt-helpers.o: $(CCANDIR)/ccan/opt/helpers.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-opt-parse.o: $(CCANDIR)/ccan/opt/parse.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-opt-usage.o: $(CCANDIR)/ccan/opt/usage.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-err.o: $(CCANDIR)/ccan/err/err.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-noerr.o: $(CCANDIR)/ccan/noerr/noerr.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-str-hex.o: $(CCANDIR)/ccan/str/hex/hex.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-crc32c.o: $(CCANDIR)/ccan/crc32c/crc32c.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-crypto-hmac.o: $(CCANDIR)/ccan/crypto/hmac_sha256/hmac_sha256.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-crypto-hkdf.o: $(CCANDIR)/ccan/crypto/hkdf_sha256/hkdf_sha256.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-crypto-shachain.o: $(CCANDIR)/ccan/crypto/shachain/shachain.c - @$(call VERBOSE, "cc $< -DSHACHAIN_BITS=48", $(CC) $(CFLAGS) -DSHACHAIN_BITS=48 -c -o $@ $<) + @$(call VERBOSE, "cc $< -DSHACHAIN_BITS=48", $(COMPILE.c) -DSHACHAIN_BITS=48 -o $@ $<) ccan-crypto-sha256.o: $(CCANDIR)/ccan/crypto/sha256/sha256.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-crypto-ripemd160.o: $(CCANDIR)/ccan/crypto/ripemd160/ripemd160.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-cdump.o: $(CCANDIR)/ccan/cdump/cdump.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-strmap.o: $(CCANDIR)/ccan/strmap/strmap.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-strset.o: $(CCANDIR)/ccan/strset/strset.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-crypto-siphash24.o: $(CCANDIR)/ccan/crypto/siphash24/siphash24.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-htable.o: $(CCANDIR)/ccan/htable/htable.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-ilog.o: $(CCANDIR)/ccan/ilog/ilog.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-intmap.o: $(CCANDIR)/ccan/intmap/intmap.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-isaac.o: $(CCANDIR)/ccan/isaac/isaac.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-isaac64.o: $(CCANDIR)/ccan/isaac/isaac64.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-time.o: $(CCANDIR)/ccan/time/time.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-timer.o: $(CCANDIR)/ccan/timer/timer.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-io-io.o: $(CCANDIR)/ccan/io/io.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-io-poll.o: $(CCANDIR)/ccan/io/poll.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-io-fdpass.o: $(CCANDIR)/ccan/io/fdpass/fdpass.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-pipecmd.o: $(CCANDIR)/ccan/pipecmd/pipecmd.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-mem.o: $(CCANDIR)/ccan/mem/mem.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-fdpass.o: $(CCANDIR)/ccan/fdpass/fdpass.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-bitops.o: $(CCANDIR)/ccan/bitops/bitops.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-rbuf.o: $(CCANDIR)/ccan/rbuf/rbuf.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-str-base32.o: $(CCANDIR)/ccan/str/base32/base32.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-utf8.o: $(CCANDIR)/ccan/utf8/utf8.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-bitmap.o: $(CCANDIR)/ccan/bitmap/bitmap.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-membuf.o: $(CCANDIR)/ccan/membuf/membuf.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-json_escape.o: $(CCANDIR)/ccan/json_escape/json_escape.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-json_out.o: $(CCANDIR)/ccan/json_out/json_out.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-closefrom.o: $(CCANDIR)/ccan/closefrom/closefrom.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-rune-rune.o: $(CCANDIR)/ccan/rune/rune.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) ccan-rune-coding.o: $(CCANDIR)/ccan/rune/coding.c - @$(call VERBOSE, "cc $<", $(CC) $(CFLAGS) -c -o $@ $<) + @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) canned-gossmap: devtools/gossmap-compress DATE=`date +%Y-%m-%d` && devtools/gossmap-compress compress --output-node-map /tmp/gossip_store tests/data/gossip-store-$$DATE.compressed > tests/data/gossip-store-$$DATE-node-map && xz -9 tests/data/gossip-store-$$DATE-node-map && ls -l tests/data/gossip-store-$$DATE* diff --git a/tools/Makefile b/tools/Makefile index 2d86221df962..4ffac102af94 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -11,7 +11,7 @@ ALL_PROGRAMS += $(TOOLS) # We force make to relink this every time, to detect version changes. # Do it atomically, otherwise parallel builds can get upset! tools/headerversions: $(FORCE) tools/headerversions.o libccan.a - @trap "rm -f $@.tmp.$$$$" EXIT; $(LINK.o) tools/headerversions.o libccan.a $(LOADLIBES) $(LDLIBS) -o $@.tmp.$$$$ && mv -f $@.tmp.$$$$ $@ + @trap "rm -f $@.tmp.$$$$" EXIT; $(LINK.c) tools/headerversions.o libccan.a $(LOADLIBES) $(LDLIBS) -o $@.tmp.$$$$ && mv -f $@.tmp.$$$$ $@ $(TOOLS): libcommon.a From 5b6c34da76d682dc53b084247ffb2d9b3007b797 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 11:18:51 -0500 Subject: [PATCH 4/7] build: move -std=gnu11 to CPPFLAGS It doesn't logically belong in CDEBUGFLAGS. Makefile now *prepends* its default CPPFLAGS and CFLAGS to the environment- supplied flags. This allows the user to override individual flags by setting these variables through configure, without disturbing all the rest of the flags that Makefile wants by default. Changelog-None --- Makefile | 10 ++++++++-- configure | 14 ++++++++++++-- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5503a33cbb16..0c9ae1bf11a2 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,12 @@ BOLTVERSION := $(DEFAULT_BOLTVERSION) -include config.vars +# Save flags inherited from environment (or config.vars) before we start munging them +CPPFLAGS_FROM_ENV := $(CPPFLAGS) +CPPFLAGS = +CFLAGS_FROM_ENV := $(CFLAGS) +CFLAGS = + # Use Homebrew LLVM toolchain for fuzzing support on macOS ifeq ($(OS),Darwin) export PATH := /opt/homebrew/opt/llvm/bin:$(PATH) @@ -290,8 +296,8 @@ endif endif # Put the environment-inherited flags *last* so the user has the final say. -CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 -I$(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I. -I$(CPATH) $(POSTGRES_INCLUDE) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(COMPAT_CFLAGS) -CFLAGS = $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) $(PIE_CFLAGS) $(CSANFLAGS) +CPPFLAGS += -DCLN_NEXT_VERSION="\"$(CLN_NEXT_VERSION)\"" -DPKGLIBEXECDIR="\"$(pkglibexecdir)\"" -DBINDIR="\"$(bindir)\"" -DPLUGINDIR="\"$(plugindir)\"" -DCCAN_TAL_NEVER_RETURN_NULL=1 -I$(CCANDIR) $(EXTERNAL_INCLUDE_FLAGS) -I. -I$(CPATH) $(POSTGRES_INCLUDE) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(COMPAT_CFLAGS) $(CPPFLAGS_FROM_ENV) +CFLAGS = $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) $(PIE_CFLAGS) $(CSANFLAGS) $(CFLAGS_FROM_ENV) # If CFLAGS is already set in the environment of make (to whatever value, it # does not matter) then it would export it to subprocesses with the above value diff --git a/configure b/configure index a79e14dd910e..78b7d852007a 100755 --- a/configure +++ b/configure @@ -170,10 +170,14 @@ set_defaults() # which matters since you might explicitly set of these blank. PREFIX=${PREFIX:-/usr/local} CC=${CC:-cc} + # A more compact way of setting the default value of a variable. + # Similar to the above, ":=" means assign if empty or unset; "=" means assign only if unset. + # The quotes suppress the globbing that would otherwise occur after variable expansion. + : "${CPPFLAGS=-std=gnu11}" # Detect macOS and use appropriate debug flags for libbacktrace compatibility if [ "$(uname -s)" = "Darwin" ]; then # Always override to avoid DWARF 5 - CDEBUGFLAGS="-std=gnu11 -g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong" + CDEBUGFLAGS="-g -gdwarf-4 -fno-standalone-debug -fstack-protector-strong" # Set SDKROOT for macOS SDKROOT="$(xcrun --sdk macosx --show-sdk-path)" @@ -182,7 +186,7 @@ set_defaults() echo "Warning: dsymutil not found. Install Xcode Command Line Tools for better debug support." fi else - CDEBUGFLAGS=${CDEBUGFLAGS--std=gnu11 -g -fstack-protector-strong} + CDEBUGFLAGS=${CDEBUGFLAGS--g -fstack-protector-strong} fi DEBUGBUILD=${DEBUGBUILD:-0} COMPAT=${COMPAT:-1} @@ -238,6 +242,8 @@ usage() # We assume we have a modern gcc. DEFAULT_CWARNFLAGS="$(default_cwarnflags ""$DEFAULT_COPTFLAGS"" 1 1 ""$DEBUGBUILD"")" usage_with_default "CC" "$CC" + usage_with_default "CPPFLAGS" "$CPPFLAGS" + usage_with_default "CFLAGS" "$CFLAGS" usage_with_default "CWARNFLAGS" "$DEFAULT_CWARNFLAGS" usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS" usage_with_default "CDEBUGFLAGS" "$CDEBUGFLAGS" @@ -311,6 +317,8 @@ for opt in "$@"; do ;; CC=*) CC="${opt#CC=}";; CONFIGURATOR_CC=*) CONFIGURATOR_CC="${opt#CONFIGURATOR_CC=}";; + CPPFLAGS=*) CPPFLAGS="${opt#CPPFLAGS=}";; + CFLAGS=*) CFLAGS="${opt#CFLAGS=}";; CWARNFLAGS=*) CWARNFLAGS="${opt#CWARNFLAGS=}";; CDEBUGFLAGS=*) CDEBUGFLAGS="${opt#CDEBUGFLAGS=}";; COPTFLAGS=*) COPTFLAGS="${opt#COPTFLAGS=}";; @@ -607,6 +615,8 @@ fi add_var PREFIX "$PREFIX" add_var CC "$CC" add_var CONFIGURATOR_CC "$CONFIGURATOR_CC" +add_var CPPFLAGS "$CPPFLAGS" +add_var CFLAGS "$CFLAGS" add_var CWARNFLAGS "$CWARNFLAGS" add_var CDEBUGFLAGS "$CDEBUGFLAGS" add_var COPTFLAGS "$COPTFLAGS" From 5e0cff414d220f4e8ddddbeac2ce3804cb649c21 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Tue, 11 Aug 2026 10:13:14 -0400 Subject: [PATCH 5/7] configure: fix quoting mistake in setting DEFAULT_CWARNFLAGS in usage() The code intends to pass "$DEFAULT_COPTFLAGS" and "$DEBUGBUILD" as arguments $1 and $4 to default_cwarnflags(), but it had mistakenly doubled the double- quotes, which would have caused the values of those variables to be subjected to word splitting after substitution. Remove the extra double-quote marks. Changelog-None --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 78b7d852007a..efe3692da672 100755 --- a/configure +++ b/configure @@ -240,7 +240,7 @@ usage() set_defaults DEFAULT_COPTFLAGS="$(default_coptflags $DEBUGBUILD)" # We assume we have a modern gcc. - DEFAULT_CWARNFLAGS="$(default_cwarnflags ""$DEFAULT_COPTFLAGS"" 1 1 ""$DEBUGBUILD"")" + DEFAULT_CWARNFLAGS="$(default_cwarnflags "$DEFAULT_COPTFLAGS" 1 1 "$DEBUGBUILD")" usage_with_default "CC" "$CC" usage_with_default "CPPFLAGS" "$CPPFLAGS" usage_with_default "CFLAGS" "$CFLAGS" From 500eeece9d5420073aa1ac31a2e2ba210b2aac7a Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Fri, 24 Apr 2026 05:51:53 -0400 Subject: [PATCH 6/7] Makefile: -Wl,--gc-sections goes in LDFLAGS, not LDLIBS Changelog-None --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 0c9ae1bf11a2..a9b8b045e33f 100644 --- a/Makefile +++ b/Makefile @@ -321,7 +321,7 @@ LDLIBS = -L$(CPATH) -lm $(SQLITE3_LDLIBS) $(COVFLAGS) endif ifeq ($(HAVE_FUNCTION_SECTIONS),1) -LDLIBS += -Wl,--gc-sections +LDFLAGS += -Wl,--gc-sections endif # If we have the postgres client library we need to link against it as well From c6aa5c64bc5480e5c58ed6b1f2847dd562349c64 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Wed, 12 Aug 2026 01:07:40 -0400 Subject: [PATCH 7/7] configure: actually invoke the linker when testing --gc-sections Passing -Wl,--gc-sections to the compiler driver does exactly nothing unless the driver is instructed to invoke the linker. When it is not, Clang helpfully raises a warning, which -Werror turns into an error: error: -Wl,--gc-sections: 'linker' input unused [-Werror,-Wunused-command-line-argument] Remove the '-c' flag from the command line in have_function_sections() so that the linker will actually be invoked and thus the linker's support for --gc-sections will actually be tested. Changelog-None --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index efe3692da672..6a29b36f4986 100755 --- a/configure +++ b/configure @@ -227,7 +227,7 @@ have_function_sections() TMPCFILE=$CONFIG_VAR_FILE.$$.c TMPOBJFILE=$CONFIG_VAR_FILE.$$.o - echo "int foo(void); int foo(void) { return 0; }" > $TMPCFILE + echo "int main(void); int main(void) { return 0; }" > $TMPCFILE # We *want* this to fail if we get a warning, hence use -Werror. $1 $2 -Werror -ffunction-sections -Wl,--gc-sections $TMPCFILE -o $TMPOBJFILE }