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