b32293d389d4f5ebbb2426245286c901a1bb7fc8
[m6w6/ext-pq] / config9.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 AC_PATH_PROG(PG_CONFIG, pg_config, no)
6
7 dnl use pg_config output when no DIR given
8 if test -x "$PG_CONFIG" && test "$PHP_PQ" = "yes"; then
9 AC_MSG_CHECKING(libpq version)
10 PQ_INCDIR=`$PG_CONFIG --includedir`
11 PQ_LIBDIR=`$PG_CONFIG --libdir`
12 PQ_VERSION=`$PG_CONFIG --version`
13
14 if test -z "$PQ_VERSION"; then
15 AC_MSG_RESULT(version not found)
16 AC_MSG_ERROR(Please reinstall libpq)
17 else
18 AC_MSG_RESULT($PQ_VERSION)
19 fi
20
21 else
22 SEARCH_PATH="/usr/local /usr /opt"
23 if test "$PHP_PQ" != "yes"; then
24 SEARCH_PATH="$PHP_PQ $SEARCH_PATH"
25 fi
26 for i in $SEARCH_PATH; do
27 dnl for Debian
28 AC_MSG_CHECKING(for $i/include/postgresql/libpq-events.h)
29 if test -f "$i/include/postgresql/libpq-events.h"; then
30 PQ_INCDIR=$i/include/postgresql
31 AC_MSG_RESULT(yep)
32 break
33 fi
34 AC_MSG_RESULT(nope)
35
36 AC_MSG_CHECKING(for $i/include/libpq-events.h)
37 if test -f "$i/include/libpq-events.h"; then
38 PQ_INCDIR=$i/include
39 AC_MSG_RESULT(yep)
40 break
41 fi
42 AC_MSG_RESULT(nope)
43 done
44
45 if test -z "$PQ_INCDIR"; then
46 AC_MSG_ERROR(could not find include/libpq-events.h)
47 fi
48
49 ARCH=`uname -i`
50 for i in $SEARCH_PATH; do
51 AC_MSG_CHECKING(for $i/$PHP_LIBDIR/libpq.$SHLIB_SUFFIX_NAME)
52 if test -f "$i/$PHP_LIBDIR/libpq.$SHLIB_SUFFIX_NAME"; then
53 PQ_LIBDIR=$i/$PHP_LIBDIR
54 AC_MSG_RESULT(yep)
55 break
56 fi
57 AC_MSG_RESULT(nope)
58
59 dnl for Debian
60 AC_MSG_CHECKING(for $i/$PHP_LIBDIR/$ARCH-linux-gnu/libpq.$SHLIB_SUFFIX_NAME)
61 if test -f "$i/$PHP_LIBDIR/$ARCH-linux-gnu/libpq.$SHLIB_SUFFIX_NAME"; then
62 PQ_LIBDIR=$i/$PHP_LIBDIR/$ARCH-linux-gnu
63 AC_MSG_RESULT(yep)
64 break
65 fi
66 AC_MSG_RESULT(nope)
67 done
68
69 if test -z "$PQ_LIBDIR"; then
70 AC_MSG_ERROR(could not find libpq.$SHLIB_SUFFIX_NAME)
71 fi
72 fi
73
74 PHP_ADD_INCLUDE($PQ_INCDIR)
75
76 ifdef([AC_PROG_EGREP], [
77 AC_PROG_EGREP
78 ], [
79 AC_CHECK_PROG(EGREP, egrep, egrep)
80 ])
81
82 dnl
83 dnl PQ_CHECK_CONST(name)
84 dnl
85 AC_DEFUN([PQ_CHECK_CONST], [
86 AC_MSG_CHECKING(for $1)
87 if $EGREP -q $1 $PQ_INCDIR/libpq-fe.h; then
88 AC_DEFINE(HAVE_$1, 1, [Have $1])
89 AC_MSG_RESULT(yep)
90 else
91 AC_MSG_RESULT(nope)
92 fi
93 ])
94
95 PQ_CHECK_CONST(PGRES_SINGLE_TUPLE)
96 PQ_CHECK_CONST(PGRES_COPY_BOTH)
97
98
99 dnl
100 dnl PQ_CHECK_FUNC(sym, fail-hard)
101 dnl
102 AC_DEFUN([PQ_CHECK_FUNC], [
103 FAIL_HARD=$2
104
105 PHP_CHECK_LIBRARY(pq, $1, [
106 AC_DEFINE([HAVE_]translit($1,a-z,A-Z), 1, Have $1)
107 ], [
108 if test -n "$FAIL_HARD"; then
109 if "$FAIL_HARD"; then
110 AC_MSG_ERROR(could not find $PQ_SYM in -lpq)
111 fi
112 fi
113 ], [
114 -L$PQ_LIBDIR
115 ])
116 ])
117
118 PQ_CHECK_FUNC(PQregisterEventProc, true)
119 PHP_ADD_LIBRARY_WITH_PATH(pq, $PQ_LIBDIR, PQ_SHARED_LIBADD)
120 PHP_SUBST(PQ_SHARED_LIBADD)
121
122 PQ_CHECK_FUNC(PQlibVersion)
123 PQ_CHECK_FUNC(PQconninfo)
124 PQ_CHECK_FUNC(PQsetSingleRowMode)
125
126 dnl
127 dnl PQ_HAVE_PHP_EXT(name[, code-if-yes[, code-if-not]])
128 dnl
129 AC_DEFUN([PQ_HAVE_PHP_EXT], [
130 extname=$1
131 haveext=$[PHP_]translit($1,a-z_-,A-Z__)
132 AC_MSG_CHECKING([for ext/$extname support])
133 if test "$haveext" != "no" && test "x$haveext" != "x"; then
134 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
135 AC_MSG_RESULT([yes])
136 $2
137 elif test -x "$PHP_EXECUTABLE"; then
138 grepext=`$PHP_EXECUTABLE -m | $EGREP ^$extname\$`
139 if test "$grepext" = "$extname"; then
140 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
141 AC_MSG_RESULT([yes])
142 $2
143 else
144 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
145 AC_MSG_RESULT([no])
146 $3
147 fi
148 else
149 [PHP_PQ_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
150 AC_MSG_RESULT([no])
151 $3
152 fi
153 ])
154
155 PQ_SRC="\
156 src/php_pq_module.c\
157 src/php_pq_misc.c\
158 src/php_pq_callback.c\
159 src/php_pq_object.c\
160 src/php_pq_params.c\
161 src/php_pqcancel.c\
162 src/php_pqconn.c\
163 src/php_pqconn_event.c\
164 src/php_pqcopy.c\
165 src/php_pqexc.c\
166 src/php_pqlob.c\
167 src/php_pqres.c\
168 src/php_pqstm.c\
169 src/php_pqtxn.c\
170 src/php_pqtypes.c\
171 src/php_pqcur.c\
172 "
173 PHP_NEW_EXTENSION(pq, $PQ_SRC, $ext_shared)
174 PHP_ADD_BUILD_DIR($ext_builddir/src)
175 PHP_ADD_INCLUDE($ext_srcdir/src)
176
177 PQ_HAVE_PHP_EXT([raphf], [
178 AC_MSG_CHECKING([for php_raphf.h])
179 PQ_EXT_RAPHF_INCDIR=
180 for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../raphf; do
181 if test -d $i; then
182 if test -f $i/php_raphf.h; then
183 PQ_EXT_RAPHF_INCDIR=$i
184 break
185 elif test -f $i/ext/raphf/php_raphf.h; then
186 PQ_EXT_RAPHF_INCDIR=$i/ext/raphf
187 break
188 fi
189 fi
190 done
191 if test "x$PQ_EXT_RAPHF_INCDIR" = "x"; then
192 AC_MSG_ERROR([not found])
193 else
194 AC_MSG_RESULT([$PQ_EXT_RAPHF_INCDIR])
195 AC_DEFINE([PHP_PQ_HAVE_PHP_RAPHF_H], [1], [Have ext/raphf support])
196 PHP_ADD_INCLUDE([$PQ_EXT_RAPHF_INCDIR])
197 fi
198 ], [
199 AC_MSG_ERROR([Please install pecl/raphf and activate extension=raphf.$SHLIB_DL_SUFFIX_NAME in your php.ini])
200 ])
201 PHP_ADD_EXTENSION_DEP(pq, raphf, true)
202 PQ_HAVE_PHP_EXT([json], [
203 AC_MSG_CHECKING([for php_json.h])
204 PQ_EXT_JSON_INCDIR=
205 for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../json ../jsonc ../jsond; do
206 if test -d $i; then
207 if test -f $i/php_json.h; then
208 PQ_EXT_JSON_INCDIR=$i
209 break
210 elif test -f $i/ext/json/php_json.h; then
211 PQ_EXT_JSON_INCDIR=$i/ext/json
212 break
213 fi
214 fi
215 done
216 if test "x$PQ_EXT_JSON_INCDIR" = "x"; then
217 AC_MSG_ERROR([not found])
218 else
219 AC_MSG_RESULT([$PQ_EXT_JSON_INCDIR])
220 AC_DEFINE([PHP_PQ_HAVE_PHP_JSON_H], [1], [Have ext/json support])
221 PHP_ADD_INCLUDE([$PQ_EXT_JSON_INCDIR])
222 fi
223 ])
224 fi