xref: /PHP-8.2/ext/pgsql/config.m4 (revision ce668c0e)
1PHP_ARG_WITH([pgsql],
2  [for PostgreSQL support],
3  [AS_HELP_STRING([[--with-pgsql[=DIR]]],
4    [Include PostgreSQL support. DIR is the PostgreSQL base install directory or
5    the path to pg_config])])
6
7if test "$PHP_PGSQL" != "no"; then
8  PHP_EXPAND_PATH($PGSQL_INCLUDE, PGSQL_INCLUDE)
9
10  dnl pg_config is still the default way to retrieve build options
11  dnl pkgconfig support was only introduced in 9.3
12
13  AC_MSG_CHECKING(for pg_config)
14  for i in $PHP_PGSQL $PHP_PGSQL/bin /usr/local/pgsql/bin /usr/local/bin /usr/bin ""; do
15	if test -x $i/pg_config; then
16      PG_CONFIG="$i/pg_config"
17      break;
18    fi
19  done
20
21  if test -n "$PG_CONFIG"; then
22    AC_MSG_RESULT([$PG_CONFIG])
23    PGSQL_INCLUDE=`$PG_CONFIG --includedir`
24    PGSQL_LIBDIR=`$PG_CONFIG --libdir`
25  else
26    AC_MSG_RESULT(not found)
27    if test "$PHP_PGSQL" = "yes"; then
28      PGSQL_SEARCH_PATHS="/usr /usr/local /usr/local/pgsql"
29    else
30      PGSQL_SEARCH_PATHS=$PHP_PGSQL
31    fi
32
33    for i in $PGSQL_SEARCH_PATHS; do
34      for j in include include/pgsql include/postgres include/postgresql ""; do
35        if test -r "$i/$j/libpq-fe.h"; then
36          PGSQL_INC_BASE=$i
37          PGSQL_INCLUDE=$i/$j
38        fi
39      done
40
41      for j in lib $PHP_LIBDIR/pgsql $PHP_LIBDIR/postgres $PHP_LIBDIR/postgresql ""; do
42        if test -f "$i/$j/libpq.so" || test -f "$i/$j/libpq.a"; then
43          PGSQL_LIBDIR=$i/$j
44        fi
45      done
46    done
47  fi
48
49  if test -z "$PGSQL_INCLUDE"; then
50    AC_MSG_ERROR(Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path)
51  fi
52
53  if test -z "$PGSQL_LIBDIR"; then
54    AC_MSG_ERROR(Cannot find libpq.so. Please specify correct PostgreSQL installation path)
55  fi
56
57  if test -z "$PGSQL_INCLUDE" -a -z "$PGSQL_LIBDIR" ; then
58    AC_MSG_ERROR([Unable to find libpq anywhere under $PGSQL_SEARCH_PATHS])
59  fi
60
61  AC_DEFINE(HAVE_PGSQL,1,[Whether to build PostgreSQL support or not])
62  old_LIBS=$LIBS
63  old_LDFLAGS=$LDFLAGS
64  LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
65  AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PostgreSQL extension: at least libpq 9.1 is required]))
66  AC_CHECK_LIB(pq, pg_encoding_to_char,AC_DEFINE(HAVE_PGSQL_WITH_MULTIBYTE_SUPPORT,1,[Whether libpq is compiled with --enable-multibyte]))
67  AC_CHECK_LIB(pq, lo_truncate64, AC_DEFINE(HAVE_PG_LO64,1,[PostgreSQL 9.3 or later]))
68  LIBS=$old_LIBS
69  LDFLAGS=$old_LDFLAGS
70
71  PHP_ADD_LIBRARY_WITH_PATH(pq, $PGSQL_LIBDIR, PGSQL_SHARED_LIBADD)
72  PHP_SUBST(PGSQL_SHARED_LIBADD)
73
74  PHP_ADD_INCLUDE($PGSQL_INCLUDE)
75
76  PHP_NEW_EXTENSION(pgsql, pgsql.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
77fi
78