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