From 2df7f0e80912d2e834f51ad0b095d38ddc55f5b5 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 11:18:51 -0500 Subject: [PATCH 01/16] 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 52792463642d..4d6e5b156e72 100755 --- a/configure +++ b/configure @@ -147,7 +147,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/16] 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 4d6e5b156e72..b245940d5097 100755 --- a/configure +++ b/configure @@ -147,12 +147,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 } @@ -290,9 +290,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" @@ -347,10 +347,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 @@ -366,7 +366,7 @@ fi 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 @@ -400,16 +400,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 @@ -420,7 +420,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 68527eef533b6311ea3245d78f4a00c1725ff15c Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Tue, 11 Aug 2026 10:13:14 -0400 Subject: [PATCH 03/16] 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 b245940d5097..06e2ebeb52ae 100755 --- a/configure +++ b/configure @@ -249,7 +249,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 96f75cedf6cda1c279d35aae6a16f37fd1dccf3a Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sun, 23 Aug 2026 20:31:23 -0400 Subject: [PATCH 04/16] 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 7bfa24d880a0..111f88e8ef64 100644 --- a/Makefile +++ b/Makefile @@ -347,7 +347,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 d353bd5de41e4139063a4b5f9c877ff7077874d9 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Thu, 20 Aug 2026 12:33:55 -0400 Subject: [PATCH 05/16] 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 ++++++++++++++++--------- tools/update-mocks.sh | 8 ++++++-- 3 files changed, 34 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 111f88e8ef64..7d01458f6980 100644 --- a/Makefile +++ b/Makefile @@ -38,6 +38,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 = + # Homebrew lives in /opt/homebrew on Apple Silicon and /usr/local on Intel. # Ask brew rather than guessing, and use nothing from it if it isn't found # (e.g. in a nix build), so we don't pick up stray headers and tools. @@ -305,8 +313,10 @@ endif 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 . $(CPATH_CFLAGS) $(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 . $(CPATH_CFLAGS) $(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 @@ -318,8 +328,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) @@ -329,10 +337,6 @@ else LDLIBS = $(LIBRARY_PATH_LDFLAGS) -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 06e2ebeb52ae..e2ccc5d541e4 100755 --- a/configure +++ b/configure @@ -254,6 +254,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 @@ -327,6 +330,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;; @@ -390,18 +396,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 @@ -455,7 +460,7 @@ CONFIGURATOR_PATH_FLAGS= [ -z "$CPATH" ] || CONFIGURATOR_PATH_FLAGS="$CONFIGURATOR_PATH_FLAGS -I$CPATH" [ -z "$LIBRARY_PATH" ] || CONFIGURATOR_PATH_FLAGS="$CONFIGURATOR_PATH_FLAGS -L$LIBRARY_PATH" -$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 $CONFIGURATOR_PATH_FLAGS $SQLITE3_CFLAGS $SODIUM_CFLAGS $POSTGRES_INCLUDE < "${BASE}.err" >/dev/null + $MAKE SUPPRESS_GENERATION=1 "${FILE/%.c/}" DEBUGBUILD=1 COPTFLAGS= LDFLAGS="${LDFLAGS}" 2>"${BASE}.err" >/dev/null } if [ -n "$START" ]; then @@ -29,7 +33,7 @@ if [ -n "$START" ]; then # this in the output: # ld: error: too many errors emitted, stopping now (use -error-limit=0 to see all errors) if grep -q 'too many errors emitted.*-error-limit=0' "${BASE}.err"; then - LDFLAGS=-Wl,-error-limit=0 make_binary || : + make_binary -Wl,-error-limit=0 || : fi tools/mockup.sh "$FILE" < "${BASE}.err" >> "${BASE}.stubs" # If there are no link errors, maybe compile fail for other reason? From 60249d30bbaa6d9941ba2d25042ee2d12692c995 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 08:28:31 -0500 Subject: [PATCH 06/16] 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 7d01458f6980..210e64f30587 100644 --- a/Makefile +++ b/Makefile @@ -314,9 +314,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 . $(CPATH_CFLAGS) $(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. $(CPATH_CFLAGS) $(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 @@ -350,8 +350,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 @@ -359,7 +359,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) @@ -819,7 +819,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 @@ -840,7 +840,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 @@ -1106,113 +1106,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 994721897e81aa8c4b15ca7eaca57cb81f1af23e Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 7 Mar 2026 11:18:51 -0500 Subject: [PATCH 07/16] 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 e2ccc5d541e4..3f85be372470 100755 --- a/configure +++ b/configure @@ -183,10 +183,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)" @@ -195,7 +199,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 26e1a618e4d04c183891dbe8df36d2e96edab6f3 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Wed, 12 Aug 2026 01:07:40 -0400 Subject: [PATCH 08/16] 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 3f85be372470..1c12349244fd 100755 --- a/configure +++ b/configure @@ -240,7 +240,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 069ecc66483deb83f0047b66b7e58a510c7cd834 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sat, 22 Aug 2026 17:09:34 -0400 Subject: [PATCH 09/16] 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 b4e1e63f2e7f760fa06a6a1f467d24677a02d5e6 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sun, 23 Aug 2026 16:54:23 -0400 Subject: [PATCH 10/16] 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 | 150 ++++++++++++++++++++++++++++++++----------------------- 1 file changed, 88 insertions(+), 62 deletions(-) diff --git a/Makefile b/Makefile index 210e64f30587..c7d009e105d7 100644 --- a/Makefile +++ b/Makefile @@ -358,6 +358,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 $@ $<) @@ -967,10 +970,56 @@ 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) = installation source file +# $(3) = installation target file +# Expands to the installation target file, defining its rule as a side effect. +INSTALL_TARGET_tmpl = $(eval $(call INSTALL_RULE_tmpl,$(1),$(2),$(3)))$(3) + +# $(1) = install command +# $(2) = list of files to install to $(3) +# $(3) = installation target directory +install_targets = $(foreach f,$(2),$(call INSTALL_TARGET_tmpl,$(1),$(f),$(3)/$(notdir $(f)))) + +# $(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) = source directory (with trailing slash) +# $(2) = paths within that directory +# $(3) = installation target path +# Expands to the installation target path, defining its rules as a side effect. +PY_PLUGIN_TARGET_tmpl = $(eval $(call TOUCH_RULE_tmpl,$(1),$(2)))$(eval $(call INSTALL_RULE_tmpl,$(RM) -r $$@ && $(CP_A),$(1),$(3)))$(3) + +# $(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))),$(call PY_PLUGIN_TARGET_tmpl,$(d),$(filter $(d)%,$(1)),$(2)/$(notdir $(patsubst %/,%,$(d))))) + # Tags needed by some package systems. PRE_INSTALL = : NORMAL_INSTALL = : @@ -979,28 +1028,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 @@ -1014,13 +1061,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 @@ -1040,44 +1089,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 @@ -1093,7 +1119,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 98851d4eaf7b738ac79551ec1fa1c729f62b5c03 Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Sun, 23 Aug 2026 21:18:34 -0400 Subject: [PATCH 11/16] 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 1c12349244fd..2b1143d1db53 100755 --- a/configure +++ b/configure @@ -27,14 +27,19 @@ if [ -z "$IN_NIX_SHELL" ]; then fi 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() { @@ -436,25 +441,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. From 2e2aaee4cc29085548205bbbb7565110c9f46ca4 Mon Sep 17 00:00:00 2001 From: Andezion Date: Wed, 11 Nov 2026 18:57:08 +0100 Subject: [PATCH 12/16] configure: keep -std=gnu11 when CPPFLAGS is set Changelog-None --- configure | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 2b1143d1db53..2a9dea233bbd 100755 --- a/configure +++ b/configure @@ -188,10 +188,13 @@ 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}" + # Always select our C dialect, even when the user sets CPPFLAGS (as many + # packaging tools do), unless they chose a -std= option themselves. Put it + # first so that a later -std= in CPPFLAGS still wins. + case " $CPPFLAGS " in + *" -std="*) ;; + *) CPPFLAGS="-std=gnu11${CPPFLAGS:+ $CPPFLAGS}";; + esac # Detect macOS and use appropriate debug flags for libbacktrace compatibility if [ "$(uname -s)" = "Darwin" ]; then # Always override to avoid DWARF 5 From 9a327be7d17f7194f9d4af5feb48110e43f353ae Mon Sep 17 00:00:00 2001 From: Andezion Date: Wed, 11 Nov 2026 18:57:08 +0100 Subject: [PATCH 13/16] Makefile: add CFLAGS, CPPFLAGS and LDFLAGS from make's environment and command line Changelog-None --- Makefile | 45 ++++++++++++++++++++++++++++--------------- bitcoin/test/Makefile | 2 +- tools/Makefile | 2 +- 3 files changed, 32 insertions(+), 17 deletions(-) diff --git a/Makefile b/Makefile index c7d009e105d7..0856e8814a7e 100644 --- a/Makefile +++ b/Makefile @@ -36,15 +36,28 @@ DEFAULT_BOLTVERSION := 4b539711d4726f274482051150bc6612e370b4e2 # Can be overridden on cmdline. BOLTVERSION := $(DEFAULT_BOLTVERSION) +USER_FLAGS_VARS := CFLAGS CPPFLAGS LDFLAGS + +# config.vars takes precedence over make's environment, so remember any of +# these flags given in the environment before including it. +$(foreach v,$(USER_FLAGS_VARS),$(if $(filter environment,$(origin $(v))),$(eval MAKE_ENV_$(v) := $$($(v))))) + -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 = +# Save the user's flags before we start munging them: those recorded by +# configure (or given on the command line, which replaces them), followed by +# any different ones given in make's environment. We prepend our own flags +# below; "override" makes that work for command-line values too. +define SAVE_USER_FLAGS_tmpl = +$(1)_FROM_ENV := $$($(1)) +ifneq ($$(origin $(1)),command line) +ifneq ($$(strip $$(MAKE_ENV_$(1))),$$(strip $$($(1)))) +$(1)_FROM_ENV += $$(MAKE_ENV_$(1)) +endif +endif +override $(1) = +endef +$(foreach v,$(USER_FLAGS_VARS),$(eval $(call SAVE_USER_FLAGS_tmpl,$(v)))) # Homebrew lives in /opt/homebrew on Apple Silicon and /usr/local on Intel. # Ask brew rather than guessing, and use nothing from it if it isn't found @@ -302,28 +315,30 @@ ifneq ($(BREW_PREFIX),) OPENSSL_PREFIX := $(shell brew --prefix openssl@3 2>/dev/null || brew --prefix openssl 2>/dev/null || echo "") SQLITE_PREFIX := $(shell brew --prefix sqlite 2>/dev/null || echo "") ifneq ("$(OPENSSL_PREFIX)", "") -LDFLAGS += -L$(OPENSSL_PREFIX)/lib -CPPFLAGS += -I$(OPENSSL_PREFIX)/include +override LDFLAGS += -L$(OPENSSL_PREFIX)/lib +override CPPFLAGS += -I$(OPENSSL_PREFIX)/include endif ifneq ("$(SQLITE_PREFIX)", "") -LDFLAGS += -L$(SQLITE_PREFIX)/lib -CPPFLAGS += -I$(SQLITE_PREFIX)/include +override LDFLAGS += -L$(SQLITE_PREFIX)/lib +override CPPFLAGS += -I$(SQLITE_PREFIX)/include PKG_CONFIG_PATH := $(SQLITE_PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH) endif 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. $(CPATH_CFLAGS) $(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) +override 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. $(CPATH_CFLAGS) $(POSTGRES_INCLUDE) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(COMPAT_CFLAGS) $(CPPFLAGS_FROM_ENV) +override CFLAGS = $(CWARNFLAGS) $(CDEBUGFLAGS) $(COPTFLAGS) $(SQLITE3_CFLAGS) $(SODIUM_CFLAGS) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) $(PIE_CFLAGS) $(CSANFLAGS) $(CFLAGS_FROM_ENV) +override 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 # we set, including CWARNFLAGS which by default contains -Wall -Werror. This # breaks at least libwally-core which tries to switch off some warnings with # -Wno-whatever. So, tell make to not export our CFLAGS to subprocesses. -unexport CFLAGS +# The same goes for CPPFLAGS and LDFLAGS, which now hold our include paths, +# defines and linker flags. +unexport $(USER_FLAGS_VARS) # We can get configurator to run a different compile cmd to cross-configure. CONFIGURATOR_CC := $(CC) diff --git a/bitcoin/test/Makefile b/bitcoin/test/Makefile index eadb3ed3585b..db7dc90e1a96 100644 --- a/bitcoin/test/Makefile +++ b/bitcoin/test/Makefile @@ -9,6 +9,6 @@ ALL_TEST_PROGRAMS += $(BITCOIN_TEST_PROGRAMS) ALL_C_SOURCES += $(BITCOIN_TEST_PROGRAMS:=.c) # This needs to know what level of optimization we're using. -bitcoin/test/run-secret_eq_consttime.o: CFLAGS += -DCOPTFLAGS="\"${COPTFLAGS}\"" +bitcoin/test/run-secret_eq_consttime.o: CPPFLAGS += -DCOPTFLAGS="\"${COPTFLAGS}\"" check-units: $(BITCOIN_TEST_PROGRAMS:%=unittest/%) diff --git a/tools/Makefile b/tools/Makefile index 4ffac102af94..db3437db739f 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -17,7 +17,7 @@ $(TOOLS): libcommon.a tools/headerversions.o: ccan/config.h tools/lightning-hsmtool: tools/lightning-hsmtool.o -tools/lightning-downgrade.o: CFLAGS:=$(CFLAGS) -DCLN_PREV_VERSION=$(CLN_PREV_VERSION) +tools/lightning-downgrade.o: CPPFLAGS += -DCLN_PREV_VERSION=$(CLN_PREV_VERSION) tools/lightning-downgrade: \ db/exec.o \ From 8af90da0629304bf1559ff74dec2193d5f4fd96e Mon Sep 17 00:00:00 2001 From: Andezion Date: Wed, 11 Nov 2026 18:57:09 +0100 Subject: [PATCH 14/16] configure: pass LDFLAGS to have_function_sections, avoid [ -a ] Changelog-None --- configure | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 2a9dea233bbd..6a5114578b2e 100755 --- a/configure +++ b/configure @@ -408,7 +408,7 @@ 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 $CFLAGS $CPPFLAGS"; then +if have_function_sections $CC "${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTFLAGS $CFLAGS $CPPFLAGS $LDFLAGS"; then case "$LDFLAGS" in *'--gc-sections'*) ;; *) LDFLAGS="-Wl,--gc-sections $LDFLAGS";; @@ -447,7 +447,7 @@ fi # 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 +if [ -z "${SQLITE3_CFLAGS+x}" ] && [ -z "${SQLITE3_LDLIBS+x}" ]; then SQLITE3_LDLIBS="-lsqlite3" if command -v "${PKG_CONFIG}" >/dev/null; then SQLITE3_CFLAGS="$("${PKG_CONFIG}" --silence-errors --cflags sqlite3 || :)" @@ -458,7 +458,7 @@ fi # 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 +if [ -z "${SODIUM_CFLAGS+x}" ] && [ -z "${SODIUM_LDLIBS+x}" ]; then SODIUM_LDLIBS="-lsodium" if command -v "${PKG_CONFIG}" >/dev/null; then SODIUM_CFLAGS="$("${PKG_CONFIG}" --silence-errors --cflags libsodium || :)" @@ -469,7 +469,7 @@ fi # 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 +if [ -z "${POSTGRES_INCLUDE+x}" ] && [ -z "${POSTGRES_LDLIBS+x}" ]; then POSTGRES_LDLIBS="-lpq" if command -v "${PG_CONFIG}" >/dev/null; then POSTGRES_INCLUDE="-I$("${PG_CONFIG}" --includedir)" From 869c4bece0586730edb08b407792cf512e42de14 Mon Sep 17 00:00:00 2001 From: Andezion Date: Wed, 11 Nov 2026 18:57:09 +0100 Subject: [PATCH 15/16] Makefile: simplify installation and uninstallation Changelog-None --- Makefile | 43 +++++++++++-------------------------------- 1 file changed, 11 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 0856e8814a7e..561aeb4b1e4f 100644 --- a/Makefile +++ b/Makefile @@ -985,8 +985,6 @@ 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 @@ -1015,26 +1013,6 @@ install_targets = $(foreach f,$(2),$(call INSTALL_TARGET_tmpl,$(1),$(f),$(3)/$(n 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) = source directory (with trailing slash) -# $(2) = paths within that directory -# $(3) = installation target path -# Expands to the installation target path, defining its rules as a side effect. -PY_PLUGIN_TARGET_tmpl = $(eval $(call TOUCH_RULE_tmpl,$(1),$(2)))$(eval $(call INSTALL_RULE_tmpl,$(RM) -r $$@ && $(CP_A),$(1),$(3)))$(3) - -# $(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))),$(call PY_PLUGIN_TARGET_tmpl,$(d),$(filter $(d)%,$(1)),$(2)/$(notdir $(patsubst %/,%,$(d))))) - # Tags needed by some package systems. PRE_INSTALL = : NORMAL_INSTALL = : @@ -1043,13 +1021,15 @@ PRE_UNINSTALL = : NORMAL_UNINSTALL = : POST_UNINSTALL = : -$(DESTDIR)$(plugindir)/clnrest: uninstall-old-clnrest-plugin +# clnrest and wss-proxy used to be Python plugins, installed as directories. +# Remove such old directories (only if present) before installing the binaries. +$(DESTDIR)$(plugindir)/clnrest: $(if $(wildcard $(DESTDIR)$(plugindir)/clnrest/.),uninstall-old-clnrest-plugin) uninstall-old-clnrest-plugin: - @[ ! -d $(DESTDIR)$(plugindir)/clnrest ] || $(RM) -r $(DESTDIR)$(plugindir)/clnrest + $(RM) -r $(DESTDIR)$(plugindir)/clnrest -$(DESTDIR)$(plugindir)/wss-proxy: uninstall-old-wss-proxy-plugin +$(DESTDIR)$(plugindir)/wss-proxy: $(if $(wildcard $(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 + $(RM) -r $(DESTDIR)$(plugindir)/wss-proxy .PHONY: uninstall-old-clnrest-plugin uninstall-old-wss-proxy-plugin @@ -1058,8 +1038,7 @@ uninstall-old-wss-proxy-plugin: 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)) + $(call install_program_targets,$(PLUGINS),$(DESTDIR)$(plugindir)) install-program: $(INSTALL_PROGRAM_TARGETS) @$(NORMAL_INSTALL) @@ -1107,15 +1086,15 @@ testpack.tar.gz: all-programs all-fuzz-programs all-test-programs default-target uninstall-program: @$(NORMAL_UNINSTALL) ifneq ($(strip $(INSTALL_PROGRAM_TARGETS)),) - $(RM) -r $(INSTALL_PROGRAM_TARGETS) - $(RMDIR_P) $(sort $(dir $(INSTALL_PROGRAM_TARGETS))) 2>/dev/null || : + $(RM) $(INSTALL_PROGRAM_TARGETS) + rmdir $(DESTDIR)$(plugindir) $(DESTDIR)$(pkglibexecdir) 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 || : + $(RM) $(INSTALL_DATA_TARGETS) + rmdir $(DESTDIR)$(docdir) 2>/dev/null || : endif uninstall: uninstall-program uninstall-data From 1bd36305103e0463ab9ba61a84cd09cc7ea6fc37 Mon Sep 17 00:00:00 2001 From: Andezion Date: Wed, 11 Nov 2026 19:07:18 +0100 Subject: [PATCH 16/16] configure: don't add -ffunction-sections again on --reconfigure Changelog-None --- configure | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/configure b/configure index 6a5114578b2e..916bc3b06661 100755 --- a/configure +++ b/configure @@ -413,7 +413,10 @@ if have_function_sections $CC "${CWARNFLAGS-$BASE_WARNFLAGS} $CDEBUGFLAGS $COPTF *'--gc-sections'*) ;; *) LDFLAGS="-Wl,--gc-sections $LDFLAGS";; esac - COPTFLAGS="$COPTFLAGS -ffunction-sections" + case " $COPTFLAGS " in + *' -ffunction-sections '*) ;; + *) COPTFLAGS="$COPTFLAGS -ffunction-sections";; + esac fi # We assume warning flags don't affect congfigurator that much!