From 94472f67c57e42828ede308898c795b82cdb5c4d Mon Sep 17 00:00:00 2001 From: Matt Whitlock Date: Fri, 28 Aug 2020 03:26:12 -0400 Subject: [PATCH] configure: Use pg_config to locate the library location too Also, allow the pg_config binary to be specified through the PG_CONFIG environment variable, defaulting to 'pg_config' if unset. Explicitly setting PG_CONFIG to an empty string will forcibly disable PostgreSQL support, even if a PostgreSQL library is installed. Changelog-Fixed: build: On systems with multiple installed versions of the PostgreSQL client library, C-Lightning might link against the wrong version or fail to find the library entirely. `./configure` now uses `pg_config` to locate the library. --- Makefile | 2 +- configure | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index a8cfa466f..25dec1d42 100644 --- a/Makefile +++ b/Makefile @@ -228,7 +228,7 @@ endif # If we have the postgres client library we need to link against it as well ifeq ($(HAVE_POSTGRES),1) -LDLIBS += -lpq +LDLIBS += $(POSTGRES_LDLIBS) endif default: show-flags all-programs all-test-programs doc-all diff --git a/configure b/configure index 2311d917a..5b5b73e23 100755 --- a/configure +++ b/configure @@ -230,8 +230,10 @@ fi require 'python3-mako' "You need the mako module for python3: see doc/INSTALL.md" python3 -c 'import mako' POSTGRES_INCLUDE="" -if command -v pg_config 2> /dev/null; then - POSTGRES_INCLUDE="-I$(pg_config --includedir)" +POSTGRES_LDLIBS="" +if command -v "${PG_CONFIG-pg_config}" >/dev/null; then + POSTGRES_INCLUDE="-I$("${PG_CONFIG-pg_config}" --includedir)" + POSTGRES_LDLIBS="-L$("${PG_CONFIG-pg_config}" --libdir) -lpq" fi rm -f $CONFIG_VAR_FILE.$$ @@ -290,7 +292,7 @@ int main(void) var=HAVE_POSTGRES desc=postgres style=DEFINES_EVERYTHING|EXECUTE|MAY_NOT_COMPILE -link=-lpq +link=$POSTGRES_LDLIBS code= #include #include @@ -360,6 +362,7 @@ add_var CWARNFLAGS "$CWARNFLAGS" add_var CDEBUGFLAGS "$CDEBUGFLAGS" add_var COPTFLAGS "$COPTFLAGS" add_var POSTGRES_INCLUDE "$POSTGRES_INCLUDE" +add_var POSTGRES_LDLIBS "$POSTGRES_LDLIBS" add_var VALGRIND "$VALGRIND" add_var DEVELOPER "$DEVELOPER" $CONFIG_HEADER add_var EXPERIMENTAL_FEATURES "$EXPERIMENTAL_FEATURES" $CONFIG_HEADER