fix check for PG constant
[m6w6/ext-pq] / config.m4
1 PHP_ARG_WITH(pq, [whether to enable libpq (PostgreSQL) support],
2 [ --with-pq[=DIR] Include libpq support])
3
4 if test "$PHP_PQ" != "no"; then
5 SEARCH_PATH="/usr/local /usr /opt"
6 if test "$PHP_PQ" != "yes"; then
7 SEARCH_PATH="$PHP_PQ $SEARCH_PATH"
8 fi
9 for i in $SEARCH_PATH; do
10 AC_MSG_CHECKING(for $i/include/libpq-events.h)
11 if test -f "$i/include/libpq-events.h"; then
12 PQ_DIR=$i
13 AC_MSG_RESULT(yep)
14 break
15 fi
16 AC_MSG_RESULT(nope)
17 done
18
19 if test -z "$PQ_DIR"; then
20 AC_MSG_ERROR(could not find include/libpq-events.h)
21 fi
22 PHP_ADD_INCLUDE($PQ_DIR/include)
23
24 ifdef([AC_PROG_EGREP], [
25 AC_PROG_EGREP
26 ], [
27 AC_CHECK_PROG(EGREP, egrep, egrep)
28 ])
29
30 dnl
31 dnl PQ_CHECK_CONST(name)
32 dnl
33 AC_DEFUN([PQ_CHECK_CONST], [
34 AC_MSG_CHECKING(for $1)
35 if $EGREP -q $1 $PQ_DIR/include/libpq-fe.h; then
36 AC_DEFINE(HAVE_$1, 1, [Have $1])
37 AC_MSG_RESULT(yep)
38 else
39 AC_MSG_RESULT(nope)
40 fi
41 ])
42
43 PQ_CHECK_CONST(PGRES_SINGLE_TUPLE)
44 PQ_CHECK_CONST(PGRES_COPY_BOTH)
45
46
47 dnl
48 dnl PQ_CHECK_FUNC(sym, fail-hard)
49 dnl
50 AC_DEFUN([PQ_CHECK_FUNC], [
51 FAIL_HARD=$2
52
53 PHP_CHECK_LIBRARY(pq, $1, [
54 AC_DEFINE([HAVE_]translit($1,a-z,A-Z), 1, Have $1)
55 ], [
56 if test -n "$FAIL_HARD"; then
57 if "$FAIL_HARD"; then
58 AC_MSG_ERROR(could not find $PQ_SYM in -lpq)
59 fi
60 fi
61 ], [
62 -L$PQ_DIR/$PHP_LIBDIR
63 ])
64 ])
65
66 PQ_CHECK_FUNC(PQregisterEventProc, true)
67 PHP_ADD_LIBRARY_WITH_PATH(pq, $PQ_DIR/$PHP_LIBDIR, PQ_SHARED_LIBADD)
68 PHP_SUBST(PQ_SHARED_LIBADD)
69
70 PQ_CHECK_FUNC(PQlibVersion)
71 PQ_CHECK_FUNC(PQconninfo)
72 PQ_CHECK_FUNC(PQsetSingleRowMode)
73
74 dnl
75 dnl PQ_HAVE_PHP_EXT(name[, code-if-yes[, code-if-not]])
76 dnl
77 AC_DEFUN([PQ_HAVE_PHP_EXT], [
78 extname=$1
79 haveext=$[PHP_]translit($1,a-z_-,A-Z__)
80 AC_MSG_CHECKING([for ext/$extname support])
81 if test -x "$PHP_EXECUTABLE"; then
82 grepext=`$PHP_EXECUTABLE -m | $EGREP ^$extname\$`
83 if test "$grepext" = "$extname"; then
84 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
85 AC_MSG_RESULT([yes])
86 $2
87 else
88 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
89 AC_MSG_RESULT([no])
90 $3
91 fi
92 elif test "$haveext" != "no" && test "x$haveext" != "x"; then
93 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
94 AC_MSG_RESULT([yes])
95 $2
96 else
97 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
98 AC_MSG_RESULT([no])
99 $3
100 fi
101 ])
102
103 PQ_SRC="\
104 src/php_pq_module.c\
105 src/php_pq_misc.c\
106 src/php_pq_callback.c\
107 src/php_pq_object.c\
108 src/php_pq_params.c\
109 src/php_pqcancel.c\
110 src/php_pqconn.c\
111 src/php_pqconn_event.c\
112 src/php_pqcopy.c\
113 src/php_pqexc.c\
114 src/php_pqlob.c\
115 src/php_pqres.c\
116 src/php_pqstm.c\
117 src/php_pqtxn.c\
118 src/php_pqtypes.c\
119 src/php_pqcur.c\
120 "
121 PHP_NEW_EXTENSION(pq, $PQ_SRC, $ext_shared)
122 PHP_ADD_BUILD_DIR($ext_builddir/src)
123 PHP_ADD_INCLUDE($ext_srcdir/src)
124
125 PQ_HAVE_PHP_EXT([raphf], [
126 AC_MSG_CHECKING([for php_raphf.h])
127 PQ_EXT_RAPHF_INCDIR=
128 for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../raphf; do
129 if test -d $i; then
130 if test -f $i/php_raphf.h; then
131 PQ_EXT_RAPHF_INCDIR=$i
132 break
133 elif test -f $i/ext/raphf/php_raphf.h; then
134 PQ_EXT_RAPHF_INCDIR=$i/ext/raphf
135 break
136 fi
137 fi
138 done
139 if test "x$PQ_EXT_RAPHF_INCDIR" = "x"; then
140 AC_MSG_ERROR([not found])
141 else
142 AC_MSG_RESULT([$PQ_EXT_RAPHF_INCDIR])
143 AC_DEFINE([PHP_PQ_HAVE_PHP_RAPHF_H], [1], [Have ext/raphf support])
144 PHP_ADD_INCLUDE([$PQ_EXT_RAPHF_INCDIR])
145 fi
146 ], [
147 AC_MSG_ERROR([Please install pecl/raphf and activate extension=raphf.$SHLIB_DL_SUFFIX_NAME in your php.ini])
148 ])
149 PHP_ADD_EXTENSION_DEP(pq, raphf, true)
150 PQ_HAVE_PHP_EXT([json], [
151 AC_MSG_CHECKING([for php_json.h])
152 PQ_EXT_JSON_INCDIR=
153 for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../json ../jsonc ../jsond; do
154 if test -d $i; then
155 if test -f $i/php_json.h; then
156 PQ_EXT_JSON_INCDIR=$i
157 break
158 elif test -f $i/ext/json/php_json.h; then
159 PQ_EXT_JSON_INCDIR=$i/ext/json
160 break
161 fi
162 fi
163 done
164 if test "x$PQ_EXT_JSON_INCDIR" = "x"; then
165 AC_MSG_ERROR([not found])
166 else
167 AC_MSG_RESULT([$PQ_EXT_JSON_INCDIR])
168 AC_DEFINE([PHP_PQ_HAVE_PHP_JSON_H], [1], [Have ext/json support])
169 PHP_ADD_INCLUDE([$PQ_EXT_JSON_INCDIR])
170 fi
171 ])
172 fi
173