From 1e30a0244cc691a0d0cdd6b515e2a2b099774f04 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 11:18:51 -0500 Subject: [PATCH 01/11] 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 02/11] 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 10d612b98849ef0481d2dcae284eb121dfc52c29 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Tue, 11 Aug 2026 10:13:14 -0400 Subject: [PATCH 03/11] 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 a79e14dd910e..6ea01f0cb159 100755 --- a/configure +++ b/configure @@ -236,7 +236,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 "CWARNFLAGS" "$DEFAULT_CWARNFLAGS" usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS" From 2a1ff8bad5143f063a910035d67398f207e315c8 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sun, 23 Aug 2026 20:31:23 -0400 Subject: [PATCH 04/11] Makefile: don't show config.vars on the LD line in show-flags This was apparently a copy-paste mistake. The example link command line shown by the 'show-flags' target shouldn't include $^ since 'show-flags' has no prerequisites that are actually object files or libraries. The inclusion of $^ was causing the example command line to contain "config.vars", which makes no sense. Remove the $^. --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 20d4aedff053..cb5f2b824f9d 100644 --- a/Makefile +++ b/Makefile @@ -331,7 +331,7 @@ endif show-flags: config.vars @$(ECHO) "CC: $(CC) $(CFLAGS) -c -o" - @$(ECHO) "LD: $(LINK.o) $(filter-out %.a,$^) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) -o" + @$(ECHO) "LD: $(LINK.o) $(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 From 8b659a3def672e26ebfbe994a6952e2e89e0efea Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Thu, 20 Aug 2026 12:33:55 -0400 Subject: [PATCH 05/11] build: allow overriding CFLAGS, CPPFLAGS, and LDFLAGS Pass these flags variables when building configurator and tests. Makefile now *prepends* its default CFLAGS, CPPFLAGS, and LDFLAGS 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 | 20 ++++++++++++-------- configure | 25 ++++++++++++++++--------- 2 files changed, 28 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index cb5f2b824f9d..483a093d7203 100644 --- a/Makefile +++ b/Makefile @@ -39,6 +39,14 @@ BOLTVERSION := $(DEFAULT_BOLTVERSION) -include config.vars +# Save flags inherited from environment (or config.vars) before we start munging them +CFLAGS_FROM_ENV := $(CFLAGS) +CFLAGS = +CPPFLAGS_FROM_ENV := $(CPPFLAGS) +CPPFLAGS = +LDFLAGS_FROM_ENV := $(LDFLAGS) +LDFLAGS = + # Use Homebrew LLVM toolchain for fuzzing support on macOS ifeq ($(OS),Darwin) export PATH := /opt/homebrew/opt/llvm/bin:$(PATH) @@ -289,8 +297,10 @@ 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 $(CPPFLAGS_FROM_ENV) +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) $(CFLAGS_FROM_ENV) +LDFLAGS += $(PIE_LDFLAGS) $(CSANFLAGS) $(COPTFLAGS) $(LDFLAGS_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 @@ -302,8 +312,6 @@ unexport CFLAGS # We can get configurator to run a different compile cmd to cross-configure. CONFIGURATOR_CC := $(CC) -LDFLAGS += $(PIE_LDFLAGS) $(CSANFLAGS) $(COPTFLAGS) - ifeq ($(STATIC),1) # For MacOS, Jacob Rapoport changed this to: # -L/usr/local/lib -lsqlite3 -lz -Wl,-lm -lpthread -ldl $(COVFLAGS) @@ -313,10 +321,6 @@ else LDLIBS = -L$(CPATH) -lm $(SQLITE3_LDLIBS) $(COVFLAGS) endif -ifeq ($(HAVE_FUNCTION_SECTIONS),1) -LDLIBS += -Wl,--gc-sections -endif - # If we have the postgres client library we need to link against it as well ifeq ($(HAVE_POSTGRES),1) LDLIBS += $(POSTGRES_LDLIBS) diff --git a/configure b/configure index 6ea01f0cb159..036836d3f01a 100755 --- a/configure +++ b/configure @@ -241,6 +241,9 @@ usage() usage_with_default "CWARNFLAGS" "$DEFAULT_CWARNFLAGS" usage_with_default "COPTFLAGS" "$DEFAULT_COPTFLAGS" usage_with_default "CDEBUGFLAGS" "$CDEBUGFLAGS" + usage_with_default "CFLAGS" "$CFLAGS" + usage_with_default "CPPFLAGS" "$CPPFLAGS" + usage_with_default "LDFLAGS" "$LDFLAGS" if [ "$(uname -s)" = "Darwin" ]; then echo " Note: On macOS, -g is used instead of -g3 for libbacktrace compatibility" fi @@ -314,6 +317,9 @@ for opt in "$@"; do CWARNFLAGS=*) CWARNFLAGS="${opt#CWARNFLAGS=}";; CDEBUGFLAGS=*) CDEBUGFLAGS="${opt#CDEBUGFLAGS=}";; COPTFLAGS=*) COPTFLAGS="${opt#COPTFLAGS=}";; + CFLAGS=*) CFLAGS="${opt#CFLAGS=}";; + CPPFLAGS=*) CPPFLAGS="${opt#CPPFLAGS=}";; + LDFLAGS=*) LDFLAGS="${opt#LDFLAGS=}";; PYTEST=*) PYTEST="${opt#PYTEST=}";; --prefix=*) PREFIX="${opt#--prefix=}";; --enable-debugbuild) DEBUGBUILD=1;; @@ -371,18 +377,17 @@ EOF fi # We call this first, so we can make sure configurator runs with it as a sanity check! -if have_function_sections $CC "${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS"; then - HAVE_FUNCTION_SECTIONS=1 - LDFLAGS="-Wl,--gc-sections" +if have_function_sections $CC "${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CFLAGS $CPPFLAGS"; then + case "$LDFLAGS" in + *'--gc-sections'*) ;; + *) LDFLAGS="-Wl,--gc-sections $LDFLAGS";; + esac COPTFLAGS="$COPTFLAGS -ffunction-sections" -else - HAVE_FUNCTION_SECTIONS=0 - LDFLAGS= fi # We assume warning flags don't affect congfigurator that much! printf 'Compiling %s...' "${CONFIGURATOR}" >&2 -$CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $LDFLAGS -o $CONFIGURATOR $CONFIGURATOR.c +$CC ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CFLAGS $CPPFLAGS $LDFLAGS -o $CONFIGURATOR $CONFIGURATOR.c echo "done" >&2 if [ "$CLANG_COVERAGE" = "1" ]; then @@ -432,7 +437,7 @@ fi # Clean up on exit. trap "rm -f $CONFIG_VAR_FILE.$$*" 0 -$CONFIGURATOR --extra-tests --autotools-style --var-file=$CONFIG_VAR_FILE.$$ --header-file=$CONFIG_HEADER.$$ --configurator-cc="$CONFIGURATOR_CC" --wrapper="$CONFIGURATOR_WRAPPER" "$CC" ${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CSANFLAGS -I$CPATH -L$LIBRARY_PATH $SQLITE3_CFLAGS $SODIUM_CFLAGS $POSTGRES_INCLUDE < Date: Sat, 7 Mar 2026 08:28:31 -0500 Subject: [PATCH 06/11] 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. Move such flags to CPPFLAGS. Changelog-None --- Makefile | 124 ++++++++++++++++++++++++------------------------- tools/Makefile | 2 +- 2 files changed, 63 insertions(+), 63 deletions(-) diff --git a/Makefile b/Makefile index 483a093d7203..8c71df2683a6 100644 --- a/Makefile +++ b/Makefile @@ -298,9 +298,9 @@ 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 $(CPPFLAGS_FROM_ENV) -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) $(CFLAGS_FROM_ENV) -LDFLAGS += $(PIE_LDFLAGS) $(CSANFLAGS) $(COPTFLAGS) $(LDFLAGS_FROM_ENV) +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) +LDFLAGS += $(PIE_LDFLAGS) $(LDFLAGS_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 @@ -334,8 +334,8 @@ FORCE: endif show-flags: config.vars - @$(ECHO) "CC: $(CC) $(CFLAGS) -c -o" - @$(ECHO) "LD: $(LINK.o) $(LOADLIBES) $(EXTERNAL_LDLIBS) $(LDLIBS) -o" + @$(ECHO) "CC: $(COMPILE.c) -o" + @$(ECHO) "LD: $(LINK.c) $(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 @@ -343,7 +343,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) @@ -802,7 +802,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 @@ -823,7 +823,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 @@ -1089,113 +1089,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 f8e5b135c20cca762ea4eab16486fbff7d2cca11 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 11:18:51 -0500 Subject: [PATCH 07/11] build: move -std=gnu11 to CPPFLAGS It doesn't logically belong in CDEBUGFLAGS. Changelog-None --- configure | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/configure b/configure index 036836d3f01a..761974ad5d79 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} From 4e29b7ea03a9d4afce8f77ad7657299ca69f164c Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Wed, 12 Aug 2026 01:07:40 -0400 Subject: [PATCH 08/11] configure: fix have_function_sections test Since we're linking a standalone program, we have to define main(). Changelog-None --- configure | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/configure b/configure index 761974ad5d79..f295258b7880 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 } From 26df57f6eb76b3b64fc3d328ff58eac9b87fedbb Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 22 Aug 2026 17:09:34 -0400 Subject: [PATCH 09/11] fix two libwally-core #includes libwally-core's headers directory is present in the include search path, so its headers should not be included as #include but rather as #include . This matters when building CLN against a system-installed libwally-core, as the bundled copy in external/libwally-core might be absent. Changelog-None --- common/test/run-close_tx.c | 2 +- lightningd/test/run-close_tx_check.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/common/test/run-close_tx.c b/common/test/run-close_tx.c index 42a1cea40f76..f5196d0817ac 100644 --- a/common/test/run-close_tx.c +++ b/common/test/run-close_tx.c @@ -7,7 +7,7 @@ #include #include #include -#include +#include #include static void test_create_simple_close_tx_basic(void) diff --git a/lightningd/test/run-close_tx_check.c b/lightningd/test/run-close_tx_check.c index 9b132647bc64..2ef9ff64551a 100644 --- a/lightningd/test/run-close_tx_check.c +++ b/lightningd/test/run-close_tx_check.c @@ -2,7 +2,7 @@ #include "../simple_close_control.c" #include #include -#include +#include #include /* AUTOGENERATED MOCKS START */ From baa1ce2ceb66c5d3977ec5e6c50b68fb10963c5f Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sun, 23 Aug 2026 16:54:23 -0400 Subject: [PATCH 10/11] build: manage installation targets with Make individually Rather than installing all build products monolithically, we can leverage Make's timestamp testing to update only the installed targets whose sources have been modified since the previous install. * Rather than doing 'for' loops in the shell to install build products, use Make's 'foreach' and 'eval' functions to define an explicit rule for each individual installation target file. Then these targets can be listed as prerequisites of the phony 'install-*' targets. * Specify the installation directories as order-only prerequisites of the targets that install into them. This way, Make will create these directories before installing into them only if they do not already exist. * As a happy side effect of letting Make decide which installation targets need to be installed, the user can now disable installation of certain targets just by clearing the source list variables (e.g., MANPAGES, DOC_DATA) on the 'make' command line. Previously, that would cause errors because Make would try to invoke $(INSTALL_DATA) with an empty list of source files. * The Python plugins $(PY_PLUGINS) (of which there are currently none) are handled specially since their entire containing directory needs to be installed. For each distinct directory containing any files listed in $(PY_PLUGINS), define a rule that touches the directory whenever it is older than any listed file contained within it. This ensures that the whole plugin directory will be re-installed whenever any plugin source file within it has changed. * Split the 'uninstall' target into 'uninstall-programs' and 'uninstall-data' to mirror the 'install' target. * Now that we have explicit lists of the installation target files, uninstallation is made simpler, becoming a single '$(RM) -r' command rather than numerous shell 'for' loops. * When uninstalling, also remove the installation target directories if the uninstallation vacated them. Changelog-None --- Makefile | 138 ++++++++++++++++++++++++++++++------------------------- 1 file changed, 76 insertions(+), 62 deletions(-) diff --git a/Makefile b/Makefile index 8c71df2683a6..53acd756303a 100644 --- a/Makefile +++ b/Makefile @@ -342,6 +342,9 @@ ccan/config.h config.vars &: configure ccan/tools/configurator/configurator.c @if [ ! -f config.vars ]; then echo 'File config.vars not found: you must run ./configure before running make.' >&2; exit 1; fi ./configure --reconfigure +%/: + @$(MKDIR_P) $(@D) + %.o: %.c @$(call VERBOSE, "cc $<", $(COMPILE.c) -o $@ $<) @@ -950,10 +953,44 @@ fuzzunittest/%: % bolt-precheck # Commands MKDIR_P = mkdir -p +RMDIR_P = rmdir -p +CP_A = cp -a INSTALL = install INSTALL_PROGRAM = $(INSTALL) INSTALL_DATA = $(INSTALL) -m 644 +# $(1) = install command +# $(2) = installation source file +# $(3) = installation target file +define INSTALL_RULE_tmpl = +$(3): $(2) | $(dir $(3)) + @$$(call VERBOSE,"install $$@",$(1) $$< $$|) +endef + +# $(1) = install command +# $(2) = list of files to install to $(3) +# $(3) = installation target directory +install_targets = $(foreach f,$(2),$(let t,$(3)/$(notdir $(f)),$(eval $(call INSTALL_RULE_tmpl,$(1),$(f),$(t)))$(t))) + +# $(1) = list of files to install to $(2) +# $(2) = installation target directory +install_program_targets = $(call install_targets,$(INSTALL_PROGRAM),$(1),$(2)) +install_data_targets = $(call install_targets,$(INSTALL_DATA),$(1),$(2)) + +# Defines a rule that touches $(1) whenever it is older than any file listed in $(2). +define TOUCH_RULE_tmpl = +$(1): $(2) + @touch $(1) +endef + +# $(1) = list of files whose containing directories are to be installed to $(2) +# $(2) = installation target directory +# An installation target rule is defined for each distinct directory containing +# any file listed in $(1). A containing directory will be touched whenever any +# listed contained file is newer than it. The touched directory then will +# trigger a re-installation of the whole directory. +install_py_plugin_targets = $(foreach d,$(sort $(dir $(1))),$(let t,$(2)/$(notdir $(patsubst %/,%,$(d))),$(eval $(call TOUCH_RULE_tmpl,$(d),$(filter $(d)%,$(1))))$(eval $(call INSTALL_RULE_tmpl,$(RM) -r $$@ && $(CP_A),$(d),$(t)))$(t))) + # Tags needed by some package systems. PRE_INSTALL = : NORMAL_INSTALL = : @@ -962,28 +999,26 @@ PRE_UNINSTALL = : NORMAL_UNINSTALL = : POST_UNINSTALL = : -# Target to create directories. -installdirs: - @$(NORMAL_INSTALL) - $(MKDIR_P) $(DESTDIR)$(bindir) - $(MKDIR_P) $(DESTDIR)$(pkglibexecdir) - $(MKDIR_P) $(DESTDIR)$(plugindir) - $(MKDIR_P) $(DESTDIR)$(man1dir) - $(MKDIR_P) $(DESTDIR)$(man5dir) - $(MKDIR_P) $(DESTDIR)$(man7dir) - $(MKDIR_P) $(DESTDIR)$(man8dir) - $(MKDIR_P) $(DESTDIR)$(docdir) +$(DESTDIR)$(plugindir)/clnrest: uninstall-old-clnrest-plugin +uninstall-old-clnrest-plugin: + @[ -d $(DESTDIR)$(plugindir)/clnrest ] && $(RM) -r $(DESTDIR)$(plugindir)/clnrest + +$(DESTDIR)$(plugindir)/wss-proxy: uninstall-old-wss-proxy-plugin +uninstall-old-wss-proxy-plugin: + @[ -d $(DESTDIR)$(plugindir)/wss-proxy ] && $(RM) -r $(DESTDIR)$(plugindir)/wss-proxy + +.PHONY: uninstall-old-clnrest-plugin uninstall-old-wss-proxy-plugin # $(PLUGINS) is defined in plugins/Makefile. -install-program: installdirs $(BIN_PROGRAMS) $(PKGLIBEXEC_PROGRAMS) $(PLUGINS) $(PY_PLUGINS) +INSTALL_PROGRAM_TARGETS := \ + $(call install_program_targets,$(BIN_PROGRAMS),$(DESTDIR)$(bindir)) \ + $(call install_program_targets,$(PKGLIBEXEC_PROGRAMS),$(DESTDIR)$(pkglibexecdir)) \ + $(call install_program_targets,$(PLUGINS),$(DESTDIR)$(plugindir)) \ + $(call install_py_plugin_targets,$(PY_PLUGINS),$(DESTDIR)$(plugindir)) + +install-program: $(INSTALL_PROGRAM_TARGETS) @$(NORMAL_INSTALL) - $(INSTALL_PROGRAM) $(BIN_PROGRAMS) $(DESTDIR)$(bindir) - $(INSTALL_PROGRAM) $(PKGLIBEXEC_PROGRAMS) $(DESTDIR)$(pkglibexecdir) - @if [ -d "$(DESTDIR)$(plugindir)/clnrest" ]; then rm -rf $(DESTDIR)$(plugindir)/clnrest; fi - @if [ -d "$(DESTDIR)$(plugindir)/wss-proxy" ]; then rm -rf $(DESTDIR)$(plugindir)/wss-proxy; fi - [ -z "$(PLUGINS)" ] || $(INSTALL_PROGRAM) $(PLUGINS) $(DESTDIR)$(plugindir) - for PY in $(PY_PLUGINS); do DIR=`dirname $$PY`; DST=$(DESTDIR)$(plugindir)/`basename $$DIR`; if [ -d $$DST ]; then rm -rf $$DST; fi; $(INSTALL_PROGRAM) -d $$DIR; cp -a $$DIR $$DST ; done ifeq ($(OS),Darwin) # Install dSYM bundles alongside binaries on macOS for BIN in $(BIN_PROGRAMS); do if [ -d $$BIN.dSYM ]; then cp -a $$BIN.dSYM $(DESTDIR)$(bindir)/; fi; done @@ -997,13 +1032,15 @@ MAN7PAGES = $(filter %.7,$(MANPAGES)) MAN8PAGES = $(filter %.8,$(MANPAGES)) DOC_DATA = README.md LICENSE -install-data: installdirs $(MAN1PAGES) $(MAN5PAGES) $(MAN7PAGES) $(MAN8PAGES) $(DOC_DATA) +INSTALL_DATA_TARGETS := \ + $(call install_data_targets,$(MAN1PAGES),$(DESTDIR)$(man1dir)) \ + $(call install_data_targets,$(MAN5PAGES),$(DESTDIR)$(man5dir)) \ + $(call install_data_targets,$(MAN7PAGES),$(DESTDIR)$(man7dir)) \ + $(call install_data_targets,$(MAN8PAGES),$(DESTDIR)$(man8dir)) \ + $(call install_data_targets,$(DOC_DATA),$(DESTDIR)$(docdir)) + +install-data: $(INSTALL_DATA_TARGETS) @$(NORMAL_INSTALL) - $(INSTALL_DATA) $(MAN1PAGES) $(DESTDIR)$(man1dir) - $(INSTALL_DATA) $(MAN5PAGES) $(DESTDIR)$(man5dir) - $(INSTALL_DATA) $(MAN7PAGES) $(DESTDIR)$(man7dir) - $(INSTALL_DATA) $(MAN8PAGES) $(DESTDIR)$(man8dir) - $(INSTALL_DATA) $(DOC_DATA) $(DESTDIR)$(docdir) install: install-program install-data @@ -1023,44 +1060,21 @@ TESTPACK_EXTRAS := \ testpack.tar.gz: all-programs all-fuzz-programs all-test-programs default-targets (find * -path external -prune -o -path target -prune -o -newer config.vars -type f -print; ls $(TESTPACK_EXTRAS)) | tar --verbatim-files-from -T- -c --format=posix -f - | gzip -5 > $@ -uninstall: +uninstall-program: @$(NORMAL_UNINSTALL) - @for f in $(BIN_PROGRAMS); do \ - $(ECHO) rm -f $(DESTDIR)$(bindir)/`basename $$f`; \ - rm -f $(DESTDIR)$(bindir)/`basename $$f`; \ - done - @for f in $(PLUGINS); do \ - $(ECHO) rm -f $(DESTDIR)$(plugindir)/`basename $$f`; \ - rm -f $(DESTDIR)$(plugindir)/`basename $$f`; \ - done - @for f in $(PY_PLUGINS); do \ - $(ECHO) rm -rf $(DESTDIR)$(plugindir)/$$(basename $$(dirname $$f)); \ - rm -rf $(DESTDIR)$(plugindir)/$$(basename $$(dirname $$f)); \ - done - @for f in $(PKGLIBEXEC_PROGRAMS); do \ - $(ECHO) rm -f $(DESTDIR)$(pkglibexecdir)/`basename $$f`; \ - rm -f $(DESTDIR)$(pkglibexecdir)/`basename $$f`; \ - done - @for f in $(MAN1PAGES); do \ - $(ECHO) rm -f $(DESTDIR)$(man1dir)/`basename $$f`; \ - rm -f $(DESTDIR)$(man1dir)/`basename $$f`; \ - done - @for f in $(MAN5PAGES); do \ - $(ECHO) rm -f $(DESTDIR)$(man5dir)/`basename $$f`; \ - rm -f $(DESTDIR)$(man5dir)/`basename $$f`; \ - done - @for f in $(MAN7PAGES); do \ - $(ECHO) rm -f $(DESTDIR)$(man7dir)/`basename $$f`; \ - rm -f $(DESTDIR)$(man7dir)/`basename $$f`; \ - done - @for f in $(MAN8PAGES); do \ - $(ECHO) rm -f $(DESTDIR)$(man8dir)/`basename $$f`; \ - rm -f $(DESTDIR)$(man8dir)/`basename $$f`; \ - done - @for f in $(DOC_DATA); do \ - $(ECHO) rm -f $(DESTDIR)$(docdir)/`basename $$f`; \ - rm -f $(DESTDIR)$(docdir)/`basename $$f`; \ - done +ifneq ($(strip $(INSTALL_PROGRAM_TARGETS)),) + $(RM) -r $(INSTALL_PROGRAM_TARGETS) + $(RMDIR_P) $(sort $(dir $(INSTALL_PROGRAM_TARGETS))) 2>/dev/null || : +endif + +uninstall-data: + @$(NORMAL_UNINSTALL) +ifneq ($(strip $(INSTALL_DATA_TARGETS)),) + $(RM) -r $(INSTALL_DATA_TARGETS) + $(RMDIR_P) $(sort $(dir $(INSTALL_DATA_TARGETS))) 2>/dev/null || : +endif + +uninstall: uninstall-program uninstall-data installcheck: all-programs @rm -rf testinstall || true @@ -1076,7 +1090,7 @@ installcheck: all-programs version: @echo ${VERSION} -.PHONY: installdirs install-program install-data install uninstall \ +.PHONY: install-program install-data install uninstall-program uninstall-data uninstall \ installcheck ncc bin-tarball show-flags version # Make a tarball of opt/clightning/, optionally with label for distribution. From 271810b30568caadc224b12aeac79107a1ca46d5 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sun, 23 Aug 2026 21:18:34 -0400 Subject: [PATCH 11/11] configure: allow overriding library flags via environment vars Appropriate preprocessor and linker flags for libsodium, libsqlite3, and libpq (PostgreSQL client) are normally looked up automagically via pkg-config and pg_config, but advanced users may wish to override them. * For libsodium, disable automagic detection when SODIUM_CFLAGS and/or SODIUM_LDLIBS is set in the environment (even to an empty string). * For libsqlite3, disable automagic detection when SQLITE3_CFLAGS and/or SQLITE3_LDLIBS is set in the environment (even to an empty string). * For libpq, disable automagic detection when POSTGRES_INCLUDE and/or POSTGRES_LDLIBS is set in the environment (even to an empty string). Changelog-None --- configure | 63 +++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 40 insertions(+), 23 deletions(-) diff --git a/configure b/configure index f295258b7880..91283bc5708d 100755 --- a/configure +++ b/configure @@ -20,14 +20,19 @@ LIBRARY_PATH=/usr/local/lib export PKG_CONFIG_PATH=${PKG_CONFIG_PATH}:/usr/local/opt/sqlite/lib/pkgconfig fi -: ${PKG_CONFIG=pkg-config} - -# You can set PG_CONFIG in the environment to direct configure to call -# a specific 'pg_config' binary. If you set it to an empty string, then -# PostgreSQL support will be explicitly disabled, even if a 'pg_config' -# binary exists in your PATH. If you leave it unset, then the following -# line enables the automagic detection that most users want. -: ${PG_CONFIG=pg_config} +: "${PKG_CONFIG=pkg-config}" + +# You can set PG_CONFIG in the environment to direct configure to call a +# specific 'pg_config' binary. If you set it to an empty string, then automagic +# detection of PostgreSQL will be explicitly disabled even if a 'pg_config' +# binary exists in your PATH. However, fallback detection will still happen. +# You can disable PostgreSQL support entirely by setting POSTGRES_LDLIBS to an +# empty string, or you can set POSTGRES_INCLUDE and POSTGRES_LDLIBS (which +# specify options to pass to the C preprocessor and linker respectively) to +# attempt to build against a specific PostgreSQL installation. If you leave +# all three variables unset, then the following line enables the automagic +# detection that most users want. +: "${PG_CONFIG=pg_config}" usage_with_default() { @@ -417,25 +422,37 @@ if [ "$FUZZING" = "1" ]; then fi -SQLITE3_CFLAGS="" -SQLITE3_LDLIBS="-lsqlite3" -if command -v "${PKG_CONFIG}" >/dev/null; then - SQLITE3_CFLAGS="$("${PKG_CONFIG}" --silence-errors --cflags sqlite3 || :)" - SQLITE3_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs sqlite3 || :)" +# Setting SQLITE3_CFLAGS or SQLITE3_LDLIBS in the environment (even to an empty +# string) disables automagic detection via pkg-config as well as the fallback +# default values. +if [ -z "${SQLITE3_CFLAGS+x}" -a -z "${SQLITE3_LDLIBS+x}" ]; then + SQLITE3_LDLIBS="-lsqlite3" + if command -v "${PKG_CONFIG}" >/dev/null; then + SQLITE3_CFLAGS="$("${PKG_CONFIG}" --silence-errors --cflags sqlite3 || :)" + SQLITE3_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs sqlite3 || :)" + fi fi -SODIUM_CFLAGS="" -SODIUM_LDLIBS="-lsodium" -if command -v "${PKG_CONFIG}" >/dev/null; then - SODIUM_CFLAGS="$("${PKG_CONFIG}" --silence-errors --cflags libsodium || :)" - SODIUM_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs libsodium || :)" +# Setting SODIUM_CFLAGS or SODIUM_LDLIBS in the environment (even to an empty +# string) disables automagic detection via pkg-config as well as the fallback +# default values. +if [ -z "${SODIUM_CFLAGS+x}" -a -z "${SODIUM_LDLIBS+x}" ]; then + SODIUM_LDLIBS="-lsodium" + if command -v "${PKG_CONFIG}" >/dev/null; then + SODIUM_CFLAGS="$("${PKG_CONFIG}" --silence-errors --cflags libsodium || :)" + SODIUM_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs libsodium || :)" + fi fi -POSTGRES_INCLUDE="" -POSTGRES_LDLIBS="" -if command -v "${PG_CONFIG}" >/dev/null; then - POSTGRES_INCLUDE="-I$("${PG_CONFIG}" --includedir)" - POSTGRES_LDLIBS="-L$("${PG_CONFIG}" --libdir) -lpq" +# Setting POSTGRES_INCLUDE or POSTGRES_LDLIBS in the environment (even to an +# empty string) disables automagic detection via pg_config as well as the +# fallback default values. +if [ -z "${POSTGRES_INCLUDE+x}" -a -z "${POSTGRES_LDLIBS+x}" ]; then + POSTGRES_LDLIBS="-lpq" + if command -v "${PG_CONFIG}" >/dev/null; then + POSTGRES_INCLUDE="-I$("${PG_CONFIG}" --includedir)" + POSTGRES_LDLIBS="-L$("${PG_CONFIG}" --libdir) -lpq" + fi fi # Clean up on exit.