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