f9f92c62e4c73ac32283ec2d92c3612502f3a443
[m6w6/ext-http] / config9.m4
1 dnl config.m4 for pecl/http
2 dnl $Id: config9.m4 242664 2007-09-18 19:13:37Z mike $
3 dnl vim: noet ts=4 sw=4
4
5 PHP_ARG_WITH([http], [whether to enable extended HTTP support],
6 [ --with-http Enable extended HTTP support])
7 PHP_ARG_WITH([http-zlib-dir], [],
8 [ --with-http-zlib-dir[=DIR] HTTP: where to find zlib], $PHP_HTTP, $PHP_HTTP)
9 PHP_ARG_WITH([http-libcurl-dir], [],
10 [ --with-http-libcurl-dir[=DIR] HTTP: where to find libcurl], $PHP_HTTP, $PHP_HTTP)
11 PHP_ARG_WITH([http-libevent-dir], [],
12 [ --with-http-libevent-dir[=DIR] HTTP: where to find libevent], $PHP_HTTP_LIBCURL_DIR, "")
13
14 if test "$PHP_HTTP" != "no"; then
15
16 HTTP_HAVE_A_REQUEST_LIB=false
17
18 ifdef([AC_PROG_EGREP], [
19 AC_PROG_EGREP
20 ], [
21 AC_CHECK_PROG(EGREP, egrep, egrep)
22 ])
23 ifdef([AC_PROG_SED], [
24 AC_PROG_SED
25 ], [
26 ifdef([LT_AC_PROG_SED], [
27 LT_AC_PROG_SED
28 ], [
29 AC_CHECK_PROG(SED, sed, sed)
30 ])
31 ])
32
33 AC_PROG_CPP
34
35 if test "$PHP_HTTP_SHARED_DEPS" != "no"; then
36 AC_DEFINE([PHP_HTTP_SHARED_DEPS], [1], [ ])
37 else
38 AC_DEFINE([PHP_HTTP_SHARED_DEPS], [0], [ ])
39 fi
40
41 dnl
42 dnl HTTP_SHARED_DEP(name[, code-if-yes[, code-if-not]])
43 dnl
44 AC_DEFUN([HTTP_SHARED_DEP], [
45 extname=$1
46 haveext=$[PHP_HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)
47
48 AC_MSG_CHECKING([whether to add a dependency on ext/$extname])
49 if test "$PHP_HTTP_SHARED_DEPS" = "no"; then
50 AC_MSG_RESULT([no])
51 $3
52 elif test "$haveext"; then
53 AC_MSG_RESULT([yes])
54 AC_DEFINE([PHP_HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__), [1], [ ])
55 ifdef([PHP_ADD_EXTENSION_DEP], [
56 PHP_ADD_EXTENSION_DEP([http], $1, true)
57 ])
58 $2
59 else
60 AC_MSG_RESULT([no])
61 $3
62 fi
63 ])
64
65 dnl
66 dnl HTTP_HAVE_PHP_EXT(name[, code-if-yes[, code-if-not]])
67 dnl
68 AC_DEFUN([HTTP_HAVE_PHP_EXT], [
69 extname=$1
70 haveext=$[PHP_]translit($1,a-z_-,A-Z__)
71
72 AC_MSG_CHECKING([for ext/$extname support])
73 if test -x "$PHP_EXECUTABLE"; then
74 grepext=`$PHP_EXECUTABLE -m | $EGREP ^$extname\$`
75 if test "$grepext" = "$extname"; then
76 [PHP_HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
77 AC_MSG_RESULT([yes])
78 $2
79 else
80 [PHP_HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
81 AC_MSG_RESULT([no])
82 $3
83 fi
84 elif test "$haveext" != "no" && test "x$haveext" != "x"; then
85 [PHP_HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
86 AC_MSG_RESULT([yes])
87 $2
88 else
89 [PHP_HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
90 AC_MSG_RESULT([no])
91 $3
92 fi
93 ])
94
95
96 dnl ----
97 dnl STDC
98 dnl ----
99 AC_CHECK_HEADERS([netdb.h unistd.h])
100 PHP_CHECK_FUNC(gethostname, nsl)
101 PHP_CHECK_FUNC(getdomainname, nsl)
102 PHP_CHECK_FUNC(getservbyport, nsl)
103 PHP_CHECK_FUNC(getservbyname, nsl)
104
105 dnl ----
106 dnl ZLIB
107 dnl ----
108 AC_MSG_CHECKING([for zlib.h])
109 ZLIB_DIR=
110 for i in "$PHP_HTTP_ZLIB_DIR" "$PHP_ZLIB_DIR" "$PHP_ZLIB" /usr/local /usr /opt; do
111 if test -f "$i/include/zlib.h"; then
112 ZLIB_DIR=$i
113 break;
114 fi
115 done
116 if test "x$ZLIB_DIR" = "x"; then
117 AC_MSG_RESULT([not found])
118 AC_MSG_ERROR([could not find zlib.h])
119 else
120 AC_MSG_RESULT([found in $ZLIB_DIR])
121 AC_MSG_CHECKING([for zlib version >= 1.2.0.4])
122 ZLIB_VERSION=`$EGREP "define ZLIB_VERSION" $ZLIB_DIR/include/zlib.h | $SED -e 's/[[^0-9\.]]//g'`
123 AC_MSG_RESULT([$ZLIB_VERSION])
124 if test `echo $ZLIB_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*1000000 + $2*10000 + $3*100 + $4}'` -lt 1020004; then
125 AC_MSG_ERROR([zlib version greater or equal to 1.2.0.4 required])
126 else
127 PHP_ADD_INCLUDE($ZLIB_DIR/include)
128 PHP_ADD_LIBRARY_WITH_PATH(z, $ZLIB_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
129 fi
130 fi
131
132 dnl ----
133 dnl SERF
134 dnl ----
135
136 if test "$PHP_HTTP_LIBSERF_DIR" = "no"; then
137 AC_DEFINE([PHP_HTTP_HAVE_SERF], [0], [ ])
138 else
139 AC_MSG_CHECKING([for serf-?/serf.h])
140 SERF_DIR=
141 for i in "$PHP_HTTP_LIBSERF_DIR" /usr/local /usr /opt; do
142 if test -f "$i/include/serf-0/serf.h"; then
143 SERF_DIR=$i
144 SERF_VER=0
145 break
146 elif test -f "$i/include/serf-1/serf.h"; then
147 SERF_DIR=$i
148 SERF_VER=1
149 fi
150 done
151
152 if test "x$SERF_DIR" = "x"; then
153 AC_MSG_RESULT([not found])
154 AC_DEFINE([PHP_HTTP_HAVE_SERF], [0], [ ])
155 else
156 AC_MSG_RESULT([found in $SERF_DIR])
157
158 PHP_ADD_INCLUDE($SERF_DIR/include/serf-$SERF_VER)
159 PHP_ADD_LIBRARY_WITH_PATH(serf-$SERF_VER, $SERF_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
160 AC_DEFINE([PHP_HTTP_HAVE_SERF], [1], [Have libserf support])
161 HTTP_HAVE_A_REQUEST_LIB=true
162 fi
163 fi
164
165 dnl ----
166 dnl CURL
167 dnl ----
168
169 if test "$PHP_HTTP_LIBCURL_DIR" = "no"; then
170 AC_DEFINE([PHP_HTTP_HAVE_CURL], [0], [ ])
171 else
172 AC_MSG_CHECKING([for curl/curl.h])
173 CURL_DIR=
174 for i in "$PHP_HTTP_LIBCURL_DIR" /usr/local /usr /opt; do
175 if test -f "$i/include/curl/curl.h"; then
176 CURL_DIR=$i
177 break
178 fi
179 done
180 if test "x$CURL_DIR" = "x"; then
181 AC_MSG_RESULT([not found])
182 else
183 AC_MSG_RESULT([found in $CURL_DIR])
184
185 AC_MSG_CHECKING([for curl-config])
186 CURL_CONFIG=
187 for i in "$CURL_DIR/bin/curl-config" "$CURL_DIR/curl-config" `which curl-config`; do
188 if test -x "$i"; then
189 CURL_CONFIG=$i
190 break
191 fi
192 done
193 if test "x$CURL_CONFIG" = "x"; then
194 AC_MSG_RESULT([not found])
195 AC_MSG_ERROR([could not find curl-config])
196 else
197 AC_MSG_RESULT([found: $CURL_CONFIG])
198 fi
199
200 dnl Debian stable has currently 7.18.2
201 AC_MSG_CHECKING([for curl version >= 7.18.2])
202 CURL_VERSION=`$CURL_CONFIG --version | $SED -e 's/[[^0-9\.]]//g'`
203 AC_MSG_RESULT([$CURL_VERSION])
204 if test `echo $CURL_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*10000 + $2*100 + $3}'` -lt 71802; then
205 AC_MSG_ERROR([libcurl version greater or equal to 7.18.2 required])
206 fi
207
208 dnl
209 dnl compile tests
210 dnl
211
212 save_INCLUDES="$INCLUDES"
213 INCLUDES=
214 save_LIBS="$LIBS"
215 LIBS=
216 save_CFLAGS="$CFLAGS"
217 CFLAGS=`$CURL_CONFIG --cflags`
218 save_LDFLAGS="$LDFLAGS"
219 LDFLAGS=`$CURL_CONFIG --libs`
220 LDFLAGS="$LDFLAGS $ld_runpath_switch$CURL_DIR/$PHP_LIBDIR"
221
222 AC_MSG_CHECKING([for SSL support in libcurl])
223 CURL_SSL=`$CURL_CONFIG --feature | $EGREP SSL`
224 if test "$CURL_SSL" = "SSL"; then
225 AC_MSG_RESULT([yes])
226 AC_DEFINE([PHP_HTTP_HAVE_SSL], [1], [ ])
227
228 AC_MSG_CHECKING([for openssl support in libcurl])
229 AC_TRY_RUN([
230 #include <curl/curl.h>
231 int main(int argc, char *argv[]) {
232 curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
233 if (data && data->ssl_version && *data->ssl_version) {
234 const char *ptr = data->ssl_version;
235 while(*ptr == ' ') ++ptr;
236 return strncasecmp(ptr, "OpenSSL", sizeof("OpenSSL")-1);
237 }
238 return 1;
239 }
240 ], [
241 AC_MSG_RESULT([yes])
242 AC_CHECK_HEADER([openssl/crypto.h], [
243 AC_DEFINE([PHP_HTTP_HAVE_OPENSSL], [1], [ ])
244 CURL_SSL="crypto"
245 ])
246 ], [
247 AC_MSG_RESULT([no])
248 ], [
249 AC_MSG_RESULT([no])
250 ])
251
252 AC_MSG_CHECKING([for gnutls support in libcurl])
253 AC_TRY_RUN([
254 #include <curl/curl.h>
255 int main(int argc, char *argv[]) {
256 curl_version_info_data *data = curl_version_info(CURLVERSION_NOW);
257 if (data && data->ssl_version && *data->ssl_version) {
258 const char *ptr = data->ssl_version;
259 while(*ptr == ' ') ++ptr;
260 return strncasecmp(ptr, "GnuTLS", sizeof("GnuTLS")-1);
261 }
262 return 1;
263 }
264 ], [
265 AC_MSG_RESULT([yes])
266 AC_CHECK_HEADER([gcrypt.h], [
267 AC_DEFINE([PHP_HTTP_HAVE_GNUTLS], [1], [ ])
268 CURL_SSL="gcrypt"
269 ])
270 ], [
271 AC_MSG_RESULT([no])
272 ], [
273 AC_MSG_RESULT([no])
274 ])
275 else
276 AC_MSG_RESULT([no])
277 fi
278
279 INCLUDES="$save_INCLUDES"
280 LIBS="$save_LIBS"
281 CFLAGS="$save_CFLAGS"
282 LDFLAGS="$save_LDFLAGS"
283
284 dnl end compile tests
285
286 AC_MSG_CHECKING([for bundled SSL CA info])
287 CURL_CAINFO=
288 for i in `$CURL_CONFIG --ca` "/etc/ssl/certs/ca-certificates.crt"; do
289 if test -f "$i"; then
290 CURL_CAINFO="$i"
291 break
292 fi
293 done
294 if test "x$CURL_CAINFO" = "x"; then
295 AC_MSG_RESULT([not found])
296 else
297 AC_MSG_RESULT([$CURL_CAINFO])
298 AC_DEFINE_UNQUOTED([PHP_HTTP_CURL_CAINFO], ["$CURL_CAINFO"], [path to bundled SSL CA info])
299 fi
300
301 PHP_ADD_INCLUDE($CURL_DIR/include)
302 PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
303 PHP_EVAL_LIBLINE(`$CURL_CONFIG --libs`, HTTP_SHARED_LIBADD)
304 if test "x$CURL_SSL" != "x"; then
305 PHP_ADD_LIBRARY_WITH_PATH([$CURL_SSL], $CURL_DIR/$PHP_LIBDIR, PHP_HTTP_SHARED_LIBADD)
306 fi
307 AC_DEFINE([PHP_HTTP_HAVE_CURL], [1], [Have libcurl support])
308 HTTP_HAVE_A_REQUEST_LIB=true
309 fi
310 fi
311
312 dnl ----
313 dnl EVENT
314 dnl ----
315
316 if test "$PHP_HTTP_LIBEVENT_DIR" = "no"; then
317 AC_DEFINE([PHP_HTTP_HAVE_EVENT], [0], [ ])
318 else
319 HTTP_HAVE_PHP_EXT([event], [
320 AC_MSG_WARN([event support is incompatible with pecl/event; continuing without libevent support])
321 AC_DEFINE([PHP_HTTP_HAVE_EVENT], [0], [ ])
322 ], [
323 AC_MSG_CHECKING([for event2/event.h])
324 EVENT_DIR=
325 for i in "$PHP_HTTP_LIBEVENT_DIR" /usr/local /usr /opt; do
326 if test -f "$i/include/event.h"; then
327 EVENT_DIR=$i
328 break
329 fi
330 done
331 if test "x$EVENT_DIR" = "x"; then
332 AC_MSG_RESULT([not found])
333 AC_MSG_WARN([continuing without libevent support])
334 AC_DEFINE([PHP_HTTP_HAVE_EVENT], [0], [ ])
335 else
336 AC_MSG_RESULT([found in $EVENT_DIR])
337
338 AC_MSG_CHECKING([for libevent version, roughly])
339
340 if test -f "$EVENT_DIR/include/event2/event.h"; then
341 EVENT_VER="`$EGREP _EVENT_VERSION $EVENT_DIR/include/event2/event.h | $AWK '{print $3}'`"
342 AC_DEFINE([PHP_HTTP_HAVE_EVENT2], [1], [ ])
343 else
344 AC_DEFINE([PHP_HTTP_HAVE_EVENT2], [0], [ ])
345 if test -f "$EVENT_DIR/include/evhttp.h" && test -f "$EVENT_DIR/include/evdns.h"; then
346 if test -f "$EVENT_DIR/include/evrpc.h"; then
347 EVENT_VER="1.4 or greater"
348 else
349 EVENT_VER="1.2 or greater"
350 fi
351 else
352 EVENT_VER="1.1b or lower"
353 fi
354 fi
355 AC_DEFINE_UNQUOTED([PHP_HTTP_EVENT_VERSION], ["$EVENT_VER"], [ ])
356 AC_MSG_RESULT([$EVENT_VER])
357
358 PHP_ADD_INCLUDE($EVENT_DIR/include)
359 PHP_ADD_LIBRARY_WITH_PATH(event, $EVENT_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
360 AC_DEFINE([PHP_HTTP_HAVE_EVENT], [1], [Have libevent support for cURL])
361 fi
362 ])
363 fi
364
365 PHP_ARG_WITH([http-shared-deps], [whether to depend on extensions which have been built shared],
366 [ --without-http-shared-deps HTTP: do not depend on extensions like hash
367 and iconv (when they are built shared)], $PHP_HTTP, $PHP_HTTP)
368 dnl ----
369 dnl HASH
370 dnl ----
371 HTTP_HAVE_PHP_EXT([hash], [
372 AC_MSG_CHECKING([for php_hash.h])
373 HTTP_EXT_HASH_INCDIR=
374 for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../hash; do
375 if test -d $i; then
376 if test -f $i/php_hash.h; then
377 HTTP_EXT_HASH_INCDIR=$i
378 break
379 elif test -f $i/ext/hash/php_hash.h; then
380 HTTP_EXT_HASH_INCDIR=$i/ext/hash
381 break
382 fi
383 fi
384 done
385 if test "x$HTTP_EXT_HASH_INCDIR" = "x"; then
386 AC_MSG_RESULT([not found])
387 else
388 AC_MSG_RESULT([$HTTP_EXT_HASH_INCDIR])
389 AC_DEFINE([PHP_HTTP_HAVE_PHP_HASH_H], [1], [Have ext/hash support])
390 PHP_ADD_INCLUDE([$HTTP_EXT_HASH_INCDIR])
391 fi
392 ])
393
394 dnl ----
395 dnl JSON
396 dnl ----
397 HTTP_HAVE_PHP_EXT([json])
398
399
400 dnl ----
401 dnl ICONV
402 dnl ----
403 HTTP_HAVE_PHP_EXT([iconv])
404
405 dnl ----
406 dnl DONE
407 dnl ----
408 PHP_HTTP_SOURCES="\
409 php_http_buffer.c \
410 php_http.c \
411 php_http_client.c \
412 php_http_curl_client.c \
413 php_http_client_datashare.c \
414 php_http_curl_client_datashare.c \
415 php_http_client_factory.c \
416 php_http_client_interface.c \
417 php_http_client_pool.c \
418 php_http_curl_client_pool.c \
419 php_http_client_request.c \
420 php_http_client_response.c \
421 php_http_cookie.c \
422 php_http_curl.c \
423 php_http_encoding.c \
424 php_http_env.c \
425 php_http_env_request.c \
426 php_http_env_response.c \
427 php_http_etag.c \
428 php_http_exception.c \
429 php_http_filter.c \
430 php_http_header_parser.c \
431 php_http_headers.c \
432 php_http_info.c \
433 php_http_message_body.c \
434 php_http_message.c \
435 php_http_message_parser.c \
436 php_http_misc.c \
437 php_http_negotiate.c \
438 php_http_object.c \
439 php_http_params.c \
440 php_http_persistent_handle.c \
441 php_http_property_proxy.c \
442 php_http_querystring.c \
443 php_http_resource_factory.c \
444 php_http_strlist.c \
445 php_http_url.c \
446 php_http_version.c \
447 "
448 PHP_NEW_EXTENSION([http], $PHP_HTTP_SOURCES, $ext_shared)
449
450 dnl shared extension deps
451 HTTP_SHARED_DEP([hash])
452 HTTP_SHARED_DEP([iconv])
453 HTTP_SHARED_DEP([json])
454
455 PHP_SUBST([HTTP_SHARED_LIBADD])
456
457 PHP_HTTP_HEADERS="
458 php_http_api.h \
459 php_http_buffer.h \
460 php_http_curl_client.h \
461 php_http_curl_client_datashare.h \
462 php_http_client_datashare.h \
463 php_http_client_factory.h \
464 php_http_client.h \
465 php_http_client_interface.h \
466 php_http_curl_client_pool.h \
467 php_http_client_pool.h \
468 php_http_client_request.h \
469 php_http_client_response.h \
470 php_http_cookie.h \
471 php_http_curl.h \
472 php_http_encoding.h \
473 php_http_env.h \
474 php_http_env_request.h \
475 php_http_env_response.h \
476 php_http_etag.h \
477 php_http_exception.h \
478 php_http_filter.h \
479 php_http.h \
480 php_http_header_parser.h \
481 php_http_headers.h \
482 php_http_info.h \
483 php_http_message_body.h \
484 php_http_message.h \
485 php_http_message_parser.h \
486 php_http_misc.h \
487 php_http_negotiate.h \
488 php_http_object.h \
489 php_http_params.h \
490 php_http_persistent_handle.h \
491 php_http_property_proxy.h \
492 php_http_querystring.h \
493 php_http_resource_factory.h \
494 php_http_strlist.h \
495 php_http_url.h \
496 php_http_version.h \
497 "
498 PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADERS)
499
500 AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support])
501 fi