From 0005d6b7f4341e39a5169daaf56a2397d7268892 Mon Sep 17 00:00:00 2001 From: fanquake Date: Thu, 5 Dec 2024 13:19:28 +0000 Subject: [PATCH] build: fix linking to libsodium on macOS Currently on I see link failures like the following: ```bash ./configure checking for libsodium with IETF chacha20 variants... yes ar libccan.a ld ccan/ccan/cdump/tools/cdump-enumstr ld: library 'sodium' not found clang: error: linker command failed with exit code 1 (use -v to see invocation) ``` The configure check passes under Clang here. Changelog-Fixed: build: fix linking against libsodium on macOS. --- Makefile | 2 +- configure | 13 +++++++++++-- external/Makefile | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 5cd4628db0f2..0198ec82118c 100644 --- a/Makefile +++ b/Makefile @@ -263,7 +263,7 @@ LIBRARY_PATH := /usr/local/lib 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) $(POSTGRES_INCLUDE) $(FEATURES) $(COVFLAGS) $(DEV_CFLAGS) -DSHACHAIN_BITS=48 -DJSMN_PARENT_LINKS $(PIE_CFLAGS) $(COMPAT_CFLAGS) $(CSANFLAGS) +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) # If CFLAGS is already set in the environment of make (to whatever value, it # does not matter) then it would export it to subprocesses with the above value diff --git a/configure b/configure index a2902e6c6817..1c2480e3b533 100755 --- a/configure +++ b/configure @@ -355,6 +355,13 @@ if command -v "${PKG_CONFIG}" >/dev/null; then SQLITE3_LDLIBS="$("${PKG_CONFIG}" --silence-errors --libs sqlite3 || :)" 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 || :)" +fi + POSTGRES_INCLUDE="" POSTGRES_LDLIBS="" if command -v "${PG_CONFIG}" >/dev/null; then @@ -365,7 +372,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 $POSTGRES_INCLUDE < #include @@ -552,6 +559,8 @@ add_var SQLITE3_CFLAGS "$SQLITE3_CFLAGS" add_var SQLITE3_LDLIBS "$SQLITE3_LDLIBS" add_var POSTGRES_INCLUDE "$POSTGRES_INCLUDE" add_var POSTGRES_LDLIBS "$POSTGRES_LDLIBS" +add_var SODIUM_CFLAGS "$SODIUM_CFLAGS" +add_var SODIUM_LDLIBS "$SODIUM_LDLIBS" add_var VALGRIND "$VALGRIND" add_var DEBUGBUILD "$DEBUGBUILD" add_var COMPAT "$COMPAT" $CONFIG_HEADER.$$ diff --git a/external/Makefile b/external/Makefile index a289032a5f68..7ca251205191 100644 --- a/external/Makefile +++ b/external/Makefile @@ -50,7 +50,7 @@ EXTERNAL_INCLUDE_FLAGS += -I external/libsodium/src/libsodium/include \ -I $(TARGET_DIR)/libsodium-build/src/libsodium/include EXTERNAL_LIBS += ${TARGET_DIR}/libsodium.a else -LDLIBS += -lsodium +LDLIBS += $(SODIUM_LDLIBS) endif ifeq ($(HAVE_ZLIB),1)