xref: /PHP-7.3/ext/pdo_pgsql/config.m4 (revision 8d3f8ca1)
1dnl config.m4 for extension pdo_pgsql
2dnl vim:et:sw=2:ts=2:
3
4PHP_ARG_WITH(pdo-pgsql,for PostgreSQL support for PDO,
5[  --with-pdo-pgsql[=DIR]    PDO: PostgreSQL support.  DIR is the PostgreSQL base
6                          install directory or the path to pg_config])
7
8if test "$PHP_PDO_PGSQL" != "no"; then
9
10  if test "$PHP_PDO" = "no" && test "$ext_shared" = "no"; then
11    AC_MSG_ERROR([PDO is not enabled! Add --enable-pdo to your configure line.])
12  fi
13
14  PHP_EXPAND_PATH($PGSQL_INCLUDE, PGSQL_INCLUDE)
15
16  AC_MSG_CHECKING(for pg_config)
17  for i in $PHP_PDO_PGSQL $PHP_PDO_PGSQL/bin /usr/local/pgsql/bin /usr/local/bin /usr/bin ""; do
18    if test -x $i/pg_config; then
19      PG_CONFIG="$i/pg_config"
20      break;
21    fi
22  done
23
24  if test -n "$PG_CONFIG"; then
25    AC_MSG_RESULT([$PG_CONFIG])
26    PGSQL_INCLUDE=`$PG_CONFIG --includedir`
27    PGSQL_LIBDIR=`$PG_CONFIG --libdir`
28    AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
29  else
30    AC_MSG_RESULT(not found)
31    if test "$PHP_PDO_PGSQL" = "yes"; then
32      PGSQL_SEARCH_PATHS="/usr /usr/local /usr/local/pgsql"
33    else
34      PGSQL_SEARCH_PATHS=$PHP_PDO_PGSQL
35    fi
36
37    for i in $PGSQL_SEARCH_PATHS; do
38      for j in include include/pgsql include/postgres include/postgresql ""; do
39        if test -r "$i/$j/libpq-fe.h"; then
40          PGSQL_INC_BASE=$i
41          PGSQL_INCLUDE=$i/$j
42          if test -r "$i/$j/pg_config.h"; then
43            AC_DEFINE(HAVE_PG_CONFIG_H,1,[Whether to have pg_config.h])
44          fi
45        fi
46      done
47
48      for j in $PHP_LIBDIR $PHP_LIBDIR/pgsql $PHP_LIBDIR/postgres $PHP_LIBDIR/postgresql ""; do
49        if test -f "$i/$j/libpq.so" || test -f "$i/$j/libpq.a"; then
50          PGSQL_LIBDIR=$i/$j
51        fi
52      done
53    done
54  fi
55
56  if test -z "$PGSQL_INCLUDE"; then
57    AC_MSG_ERROR(Cannot find libpq-fe.h. Please specify correct PostgreSQL installation path)
58  fi
59
60  if test -z "$PGSQL_LIBDIR"; then
61    AC_MSG_ERROR(Cannot find libpq.so. Please specify correct PostgreSQL installation path)
62  fi
63
64  if test -z "$PGSQL_INCLUDE" -a -z "$PGSQL_LIBDIR" ; then
65    AC_MSG_ERROR([Unable to find libpq anywhere under $PGSQL_SEARCH_PATHS])
66  fi
67
68  AC_DEFINE(HAVE_PDO_PGSQL,1,[Whether to build PostgreSQL for PDO support or not])
69
70  AC_MSG_CHECKING([for openssl dependencies])
71  grep openssl $PGSQL_INCLUDE/libpq-fe.h >/dev/null 2>&1
72  if test $? -eq 0 ; then
73    AC_MSG_RESULT([yes])
74    dnl First try to find pkg-config
75    AC_PATH_PROG(PKG_CONFIG, pkg-config, no)
76    if test -x "$PKG_CONFIG" && $PKG_CONFIG --exists openssl; then
77      PDO_PGSQL_CFLAGS=`$PKG_CONFIG openssl --cflags`
78    fi
79  else
80    AC_MSG_RESULT([no])
81  fi
82
83  old_LIBS=$LIBS
84  old_LDFLAGS=$LDFLAGS
85  LDFLAGS="-L$PGSQL_LIBDIR $LDFLAGS"
86
87  AC_CHECK_LIB(pq, PQprepare,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
88  AC_CHECK_LIB(pq, PQexecParams,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
89  AC_CHECK_LIB(pq, PQescapeStringConn,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
90  AC_CHECK_LIB(pq, PQescapeByteaConn,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: a newer libpq is required]))
91
92  LIBS=$old_LIBS
93  LDFLAGS=$old_LDFLAGS
94
95  PHP_ADD_LIBRARY_WITH_PATH(pq, $PGSQL_LIBDIR, PDO_PGSQL_SHARED_LIBADD)
96  PHP_SUBST(PDO_PGSQL_SHARED_LIBADD)
97
98  PHP_ADD_INCLUDE($PGSQL_INCLUDE)
99
100  ifdef([PHP_CHECK_PDO_INCLUDES],
101  [
102    PHP_CHECK_PDO_INCLUDES
103  ],[
104    AC_MSG_CHECKING([for PDO includes])
105    if test -f $abs_srcdir/include/php/ext/pdo/php_pdo_driver.h; then
106      pdo_cv_inc_path=$abs_srcdir/ext
107    elif test -f $abs_srcdir/ext/pdo/php_pdo_driver.h; then
108      pdo_cv_inc_path=$abs_srcdir/ext
109    elif test -f $phpincludedir/ext/pdo/php_pdo_driver.h; then
110      pdo_cv_inc_path=$phpincludedir/ext
111    else
112      AC_MSG_ERROR([Cannot find php_pdo_driver.h.])
113    fi
114    AC_MSG_RESULT($pdo_cv_inc_path)
115  ])
116
117  PHP_NEW_EXTENSION(pdo_pgsql, pdo_pgsql.c pgsql_driver.c pgsql_statement.c, $ext_shared,,-I$pdo_cv_inc_path $PDO_PGSQL_CFLAGS)
118  ifdef([PHP_ADD_EXTENSION_DEP],
119  [
120    PHP_ADD_EXTENSION_DEP(pdo_pgsql, pdo)
121  ])
122fi
123