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.
This commit is contained in:
Matt Whitlock 2020-08-28 03:26:12 -04:00 committed by Rusty Russell
parent dd8cd81e91
commit 94472f67c5
2 changed files with 7 additions and 4 deletions

View File

@ -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

9
configure vendored
View File

@ -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 <libpq-fe.h>
#include <stdio.h>
@ -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