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