Skip to content

Commit

Permalink
configure: Use pg_config to locate the library location too
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
whitslack authored and rustyrussell committed Aug 30, 2020
1 parent dd8cd81 commit 94472f6
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 6 additions & 3 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -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.$$
Expand Down Expand Up @@ -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>
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 94472f6

Please sign in to comment.