A bit of a Yahoo'ism, but it makes adding pecl/http to our automatic pecl
[m6w6/ext-http] / config9.m4
1 dnl config.m4 for pecl/http
2 dnl $Id$
3 dnl vim: noet ts=1 sw=1
4
5 PHP_ARG_ENABLE([http], [whether to enable extended HTTP support],
6 [ --enable-http Enable extended HTTP support])
7 PHP_ARG_WITH([http-curl-requests], [whether to enable cURL HTTP request support],
8 [ --with-http-curl-requests[=LIBCURLDIR]
9 HTTP: with cURL request support], $PHP_HTTP, $PHP_HTTP)
10 PHP_ARG_WITH([http-zlib-compression], [whether to enable zlib encodings support],
11 [ --with-http-zlib-compression[=LIBZDIR]
12 HTTP: with zlib encodings support], $PHP_HTTP, $PHP_HTTP)
13 PHP_ARG_WITH([http-magic-mime], [whether to enable response content type guessing],
14 [ --with-http-magic-mime[=LIBMAGICDIR]
15 HTTP: with magic mime response content type guessing], "no", "no")
16 PHP_ARG_WITH([http-shared-deps], [whether to depend on extensions which have been built shared],
17 [ --with-http-shared-deps HTTP: disable to not depend on extensions like hash,
18 iconv and session (when built shared)], $PHP_HTTP, $PHP_HTTP)
19
20 if test "$PHP_HTTP" != "no"; then
21
22 ifdef([AC_PROG_EGREP], [
23 AC_PROG_EGREP
24 ], [
25 AC_CHECK_PROG(EGREP, egrep, egrep)
26 ])
27 ifdef([AC_PROG_SED], [
28 AC_PROG_SED
29 ], [
30 ifdef([LT_AC_PROG_SED], [
31 LT_AC_PROG_SED
32 ], [
33 AC_CHECK_PROG(SED, sed, sed)
34 ])
35 ])
36
37 if test "$PHP_HTTP_SHARED_DEPS" != "no"; then
38 AC_DEFINE([HTTP_SHARED_DEPS], [1], [ ])
39 else
40 AC_DEFINE([HTTP_SHARED_DEPS], [0], [ ])
41 fi
42
43 dnl
44 dnl HTTP_SHARED_DEP(name[, code-if-yes[, code-if-not]])
45 dnl
46 AC_DEFUN([HTTP_SHARED_DEP], [
47 extname=$1
48 haveext=$[HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)
49
50 AC_MSG_CHECKING([whether to add a dependency on ext/$extname])
51 if test "$PHP_HTTP_SHARED_DEPS" = "no"; then
52 AC_MSG_RESULT([no])
53 $3
54 elif test "$haveext"; then
55 AC_MSG_RESULT([yes])
56 ifdef([PHP_ADD_EXTENSION_DEP], [
57 PHP_ADD_EXTENSION_DEP([http], $1, 0)
58 ])
59 $2
60 else
61 AC_MSG_RESULT([no])
62 $3
63 fi
64 ])
65
66 dnl
67 dnl HTTP_HAVE_PHP_EXT(name[, code-if-yes[, code-if-not]])
68 dnl
69 AC_DEFUN([HTTP_HAVE_PHP_EXT], [
70 extname=$1
71 haveext=$[PHP_]translit($1,a-z_-,A-Z__)
72 ishared=$[PHP_]translit($1,a-z_-,A-Z__)_SHARED
73
74 AC_MSG_CHECKING([for ext/$extname support])
75 if test -x "$PHP_EXECUTABLE"; then
76 if test "`$PHP_EXECUTABLE -m | $EGREP ^$extname\$`" = "$extname"; then
77 [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
78 AC_MSG_RESULT([yes])
79 $2
80 else
81 [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
82 AC_MSG_RESULT([no])
83 $3
84 fi
85 elif test "$haveext" != "no" && test "x$haveext" != "x"; then
86 [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=1
87 AC_MSG_RESULT([yes])
88 $2
89 else
90 [HTTP_HAVE_EXT_]translit($1,a-z_-,A-Z__)=
91 AC_MSG_RESULT([no])
92 $3
93 fi
94 ])
95
96 dnl -------
97 dnl HEADERS
98 dnl -------
99 AC_CHECK_HEADERS([netdb.h unistd.h])
100
101 dnl ----
102 dnl ZLIB
103 dnl ----
104 if test "$PHP_HTTP_ZLIB_COMPRESSION" != "no"; then
105 AC_MSG_CHECKING([for zlib.h])
106 ZLIB_DIR=
107 for i in "$PHP_HTTP_ZLIB_COMPRESSION" "$PHP_ZLIB_DIR" "$PHP_ZLIB" /usr/local /usr /opt; do
108 if test -f "$i/include/zlib.h"; then
109 ZLIB_DIR=$i
110 break;
111 fi
112 done
113 if test -z "$ZLIB_DIR"; then
114 AC_MSG_RESULT([not found])
115 AC_MSG_WARN([could not find zlib.h])
116 else
117 AC_MSG_RESULT([found in $ZLIB_DIR])
118 AC_MSG_CHECKING([for zlib version >= 1.2.0.4])
119 ZLIB_VERSION=`$EGREP "define ZLIB_VERSION" $ZLIB_DIR/include/zlib.h | $SED -e 's/[[^0-9\.]]//g'`
120 AC_MSG_RESULT([$ZLIB_VERSION])
121 if test `echo $ZLIB_VERSION | $SED -e 's/[[^0-9]]/ /g' | $AWK '{print $1*1000000 + $2*10000 + $3*100 + $4}'` -lt 1020004; then
122 AC_MSG_ERROR([libz version greater or equal to 1.2.0.4 required])
123 else
124 PHP_ADD_INCLUDE($ZLIB_DIR/include)
125 PHP_ADD_LIBRARY_WITH_PATH(z, $ZLIB_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
126 AC_DEFINE([HTTP_HAVE_ZLIB], [1], [Have zlib support])
127 fi
128 fi
129 fi
130
131 dnl ----
132 dnl CURL
133 dnl ----
134 if test "$PHP_HTTP_CURL_REQUESTS" != "no"; then
135 AC_MSG_CHECKING([for curl/curl.h])
136 CURL_DIR=
137 for i in "$PHP_HTTP_CURL_REQUESTS" /usr/local /usr /opt; do
138 if test -f "$i/include/curl/curl.h"; then
139 CURL_DIR=$i
140 break
141 fi
142 done
143 if test -z "$CURL_DIR"; then
144 AC_MSG_RESULT([not found])
145 AC_MSG_ERROR([could not find curl/curl.h])
146 else
147 AC_MSG_RESULT([found in $CURL_DIR])
148 fi
149
150 AC_MSG_CHECKING([for curl-config])
151 CURL_CONFIG=
152 for i in "$CURL_DIR/bin/curl-config" "$CURL_DIR/curl-config" `which curl-config`; do
153 if test -x "$i"; then
154 CURL_CONFIG=$i
155 break
156 fi
157 done
158 if test -z "$CURL_CONFIG"; then
159 AC_MSG_RESULT([not found])
160 AC_MSG_ERROR([could not find curl-config])
161 else
162 AC_MSG_RESULT([found: $CURL_CONFIG])
163 fi
164
165 dnl Debian stable has currently 7.13.2 (this is not a typo)
166 AC_MSG_CHECKING([for curl version >= 7.12.3])
167 CURL_VERSION=`$CURL_CONFIG --version | $SED -e 's/[[^0-9\.]]//g'`
168 AC_MSG_RESULT([$CURL_VERSION])
169 if test `echo $CURL_VERSION | $AWK '{print $1*10000 + $2*100 + $3}'` -lt 71203; then
170 AC_MSG_ERROR([libcurl version greater or equal to 7.12.3 required])
171 fi
172
173 CURL_LIBS=`$CURL_CONFIG --libs`
174
175 AC_MSG_CHECKING([for SSL support in libcurl])
176 CURL_SSL=`$CURL_CONFIG --features | $EGREP SSL`
177 if test "$CURL_SSL" = "SSL"; then
178 AC_MSG_RESULT([yes])
179 AC_DEFINE([HTTP_HAVE_SSL], [1], [ ])
180
181 AC_MSG_CHECKING([for SSL library used])
182 CURL_SSL_FLAVOUR=
183 for i in $CURL_LIBS; do
184 if test "$i" = "-lssl" -o "$i" = "-lssl_unversion"; then
185 CURL_SSL_FLAVOUR="openssl"
186 AC_MSG_RESULT([openssl])
187 AC_DEFINE([HTTP_HAVE_OPENSSL], [1], [ ])
188 AC_CHECK_HEADERS([openssl/crypto.h])
189 break
190 elif test "$i" = "-lgnutls"; then
191 CURL_SSL_FLAVOUR="gnutls"
192 AC_MSG_RESULT([gnutls])
193 AC_DEFINE([HTTP_HAVE_GNUTLS], [1], [ ])
194 AC_CHECK_HEADERS([gcrypt.h])
195 break
196 fi
197 done
198 if test -z "$CURL_SSL_FLAVOUR"; then
199 AC_MSG_RESULT([unknown!])
200 AC_MSG_WARN([Could not determine the type of SSL library used!])
201 AC_MSG_WARN([Building will fail in ZTS mode!])
202 fi
203 else
204 AC_MSG_RESULT([no])
205 fi
206
207 PHP_ADD_INCLUDE($CURL_DIR/include)
208 PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
209 PHP_EVAL_LIBLINE($CURL_LIBS, HTTP_SHARED_LIBADD)
210 AC_DEFINE([HTTP_HAVE_CURL], [1], [Have cURL support])
211
212 PHP_CHECK_LIBRARY(curl, curl_multi_strerror,
213 [AC_DEFINE([HAVE_CURL_MULTI_STRERROR], [1], [ ])], [ ],
214 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
215 )
216 PHP_CHECK_LIBRARY(curl, curl_easy_strerror,
217 [AC_DEFINE([HAVE_CURL_EASY_STRERROR], [1], [ ])], [ ],
218 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
219 )
220 PHP_CHECK_LIBRARY(curl, curl_easy_reset,
221 [AC_DEFINE([HAVE_CURL_EASY_RESET], [1], [ ])], [ ],
222 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
223 )
224 dnl Debian suddenly (>=7.14.1-2) hides all symbols not starting with "curl"
225 PHP_CHECK_LIBRARY(curl, Curl_getFormData,
226 [AC_DEFINE([HAVE_CURL_GETFORMDATA], [1], [ ])], [ ],
227 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
228 )
229 dnl New API function which obsoletes use of Curl_getFormData (>=7.15.5)
230 PHP_CHECK_LIBRARY(curl, curl_formget,
231 [AC_DEFINE([HAVE_CURL_FORMGET], [1], [ ])], [ ],
232 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
233 )
234 fi
235
236 dnl ----
237 dnl MAGIC
238 dnl ----
239 if test "$PHP_HTTP_MAGIC_MIME" != "no"; then
240 AC_MSG_CHECKING([for magic.h])
241 MAGIC_DIR=
242 for i in "$PHP_HTTP_MAGIC_MIME" /usr/local /usr /opt; do
243 if test -f "$i/include/magic.h"; then
244 MAGIC_DIR=$i
245 break
246 fi
247 done
248 if test -z "$MAGIC_DIR"; then
249 AC_MSG_RESULT([not found])
250 AC_MSG_ERROR([could not find magic.h])
251 else
252 AC_MSG_RESULT([found in $MAGIC_DIR])
253 fi
254
255 PHP_ADD_INCLUDE($MAGIC_DIR/include)
256 PHP_ADD_LIBRARY_WITH_PATH(magic, $MAGIC_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
257 AC_DEFINE([HTTP_HAVE_MAGIC], [1], [Have magic mime support])
258 fi
259
260 dnl ----
261 dnl HASH
262 dnl ----
263 HTTP_HAVE_PHP_EXT([hash], [
264 AC_MSG_CHECKING([for php_hash.h])
265 HTTP_EXT_HASH_INCDIR=
266 for i in `echo $INCLUDES | $SED -e's/-I//g'` $abs_srcdir ../hash; do
267 if test -d $i; then
268 if test -f $i/php_hash.h; then
269 HTTP_EXT_HASH_INCDIR=$i
270 break
271 elif test -f $i/ext/hash/php_hash.h; then
272 HTTP_EXT_HASH_INCDIR=$i/ext/hash
273 break
274 fi
275 fi
276 done
277 if test -z "$HTTP_EXT_HASH_INCDIR"; then
278 AC_MSG_RESULT([not found])
279 else
280 AC_MSG_RESULT([$HTTP_EXT_HASH_INCDIR])
281 AC_DEFINE([HTTP_HAVE_PHP_HASH_H], [1], [Have ext/hash support])
282 PHP_ADD_INCLUDE([$HTTP_EXT_HASH_INCDIR])
283 fi
284 ])
285
286 dnl ----
287 dnl ICONV
288 dnl ----
289 HTTP_HAVE_PHP_EXT([iconv])
290
291 dnl ----
292 dnl SESSION
293 dnl ----
294 HTTP_HAVE_PHP_EXT([session])
295
296 dnl ----
297 dnl DONE
298 dnl ----
299 PHP_HTTP_SOURCES="missing.c http.c http_functions.c phpstr/phpstr.c \
300 http_util_object.c http_message_object.c http_request_object.c http_request_pool_api.c \
301 http_response_object.c http_exception_object.c http_requestpool_object.c \
302 http_api.c http_cache_api.c http_request_api.c http_date_api.c \
303 http_headers_api.c http_message_api.c http_send_api.c http_url_api.c \
304 http_info_api.c http_request_method_api.c http_encoding_api.c \
305 http_filter_api.c http_request_body_api.c http_querystring_object.c \
306 http_deflatestream_object.c http_inflatestream_object.c http_cookie_api.c \
307 http_querystring_api.c"
308
309 PHP_NEW_EXTENSION([http], $PHP_HTTP_SOURCES, $ext_shared)
310
311 dnl shared extension deps
312 HTTP_SHARED_DEP([hash])
313 HTTP_SHARED_DEP([iconv])
314 HTTP_SHARED_DEP([session])
315
316 PHP_ADD_BUILD_DIR($ext_builddir/phpstr, 1)
317 PHP_SUBST([HTTP_SHARED_LIBADD])
318
319 PHP_HTTP_HEADERS="php_http_std_defs.h php_http.h php_http_api.h php_http_cache_api.h \
320 php_http_date_api.h php_http_headers_api.h php_http_info_api.h php_http_message_api.h \
321 php_http_request_api.h php_http_request_method_api.h php_http_send_api.h php_http_url_api.h \
322 php_http_encoding_api.h phpstr/phpstr.h missing.h php_http_request_body_api.h \
323 php_http_exception_object.h php_http_message_object.h php_http_request_object.h \
324 php_http_requestpool_object.h php_http_response_object.h php_http_util_object.h \
325 php_http_querystring_object.h php_http_deflatestream_object.h php_http_inflatestream_object.h \
326 php_http_cookie_api.h php_http_querystring_api.h"
327 ifdef([PHP_INSTALL_HEADERS], [
328 PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADERS)
329 ], [
330 PHP_SUBST([PHP_HTTP_HEADERS])
331 PHP_ADD_MAKEFILE_FRAGMENT
332 ])
333
334 AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support])
335 fi