- check for egrep and sed
[m6w6/ext-http] / config.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 requests],
8 [ --with-http-curl-requests[=CURLDIR]
9 With cURL HTTP request support])
10 PHP_ARG_WITH([http-magic-mime], [whether to enable response content type guessing],
11 [ --with-http-magic-mime[=MAGICDIR]
12 With magic mime response content type guessing])
13 PHP_ARG_WITH([http-zlib-compression], [whether to enable support for gzencoded/deflated message bodies],
14 [ --with-http-zlib-compression[=ZLIBDIR]
15 With zlib gzdecode and inflate support])
16
17 if test "$PHP_HTTP" != "no"; then
18
19 AC_PROG_EGREP
20 ifdef([AC_PROG_SED], [
21 AC_PROG_SED
22 ], [
23 ifdef([LT_AC_PROG_SED], [
24 LT_AC_PROG_SED
25 ], [
26 AC_CHECK_PROG(SED, sed, sed)
27 ])
28 ])
29
30 dnl -------
31 dnl NETDB.H
32 dnl -------
33 AC_CHECK_HEADERS([netdb.h])
34
35 dnl ----
36 dnl ZLIB
37 dnl ----
38 AC_MSG_CHECKING([for zlib.h])
39 ZLIB_DIR=
40 for i in "$PHP_HTTP_ZLIB_COMPRESSION" "$PHP_ZLIB_DIR" "$PHP_ZLIB" /user/local /usr /opt; do
41 if test -f "$i/include/zlib.h"; then
42 ZLIB_DIR=$i
43 break;
44 fi
45 done
46 if test -z "$ZLIB_DIR"; then
47 AC_MSG_RESULT([not found])
48 AC_MSG_WARN([gzip support not enabled; zlib.h not found])
49 else
50 AC_MSG_RESULT([found in $ZLIB_DIR])
51 PHP_ADD_INCLUDE($ZLIB_DIR/include)
52 PHP_ADD_LIBRARY_WITH_PATH(z, $ZLIB_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
53 AC_DEFINE([HTTP_HAVE_ZLIB], [1], [Have zlib support])
54 fi
55
56 dnl ----
57 dnl CURL
58 dnl ----
59 if test "$PHP_HTTP_CURL_REQUESTS" != "no"; then
60
61 AC_MSG_CHECKING([for curl/curl.h])
62 CURL_DIR=
63 for i in "$PHP_HTTP_CURL_REQUESTS" /usr/local /usr /opt; do
64 if test -f "$i/include/curl/curl.h"; then
65 CURL_DIR=$i
66 break
67 fi
68 done
69 if test -z "$CURL_DIR"; then
70 AC_MSG_RESULT([not found])
71 AC_MSG_ERROR([could not find curl/curl.h])
72 else
73 AC_MSG_RESULT([found in $CURL_DIR])
74 fi
75
76 AC_MSG_CHECKING([for curl-config])
77 CURL_CONFIG=
78 for i in "$CURL_DIR/bin/curl-config" "$CURL_DIR/curl-config" `which curl-config`; do
79 if test -x "$i"; then
80 CURL_CONFIG=$i
81 break
82 fi
83 done
84 if test -z "$CURL_CONFIG"; then
85 AC_MSG_RESULT([not found])
86 AC_MSG_ERROR([could not find curl-config])
87 else
88 AC_MSG_RESULT([found: $CURL_CONFIG])
89 fi
90
91 dnl Debian stable has currently 7.13.2 (this is not a typo)
92 AC_MSG_CHECKING([for curl version >= 7.12.3])
93 CURL_VERSION=`$CURL_CONFIG --version | $SED -e 's/[[^0-9\.]]//g'`
94 AC_MSG_RESULT([$CURL_VERSION])
95 if test `echo $CURL_VERSION | $AWK '{print $1*10000 + $2*100 + $3}'` -lt 71203; then
96 AC_MSG_ERROR([libcurl version greater or equal to 7.12.3 required])
97 fi
98
99 CURL_LIBS=`$CURL_CONFIG --libs`
100
101 CURL_ZLIB=`$CURL_CONFIG --features | $EGREP libz`
102 if test "$CURL_ZLIB" = "libz"; then
103 AC_DEFINE([HTTP_HAVE_CURL_ZLIB], [1], [ ])
104 fi
105
106 AC_MSG_CHECKING([for SSL support in libcurl])
107 CURL_SSL=`$CURL_CONFIG --features | $EGREP SSL`
108 if test "$CURL_SSL" = "SSL"; then
109 AC_MSG_RESULT([yes])
110 AC_DEFINE([HTTP_HAVE_SSL], [1], [ ])
111
112 AC_MSG_CHECKING([for SSL library used])
113 CURL_SSL_FLAVOUR=
114 for i in $CURL_LIBS; do
115 if test "$i" = "-lssl"; then
116 CURL_SSL_FLAVOUR="openssl"
117 AC_MSG_RESULT([openssl])
118 AC_DEFINE([HTTP_HAVE_OPENSSL], [1], [ ])
119 AC_CHECK_HEADERS([openssl/crypto.h])
120 break
121 elif test "$i" = "-lgnutls"; then
122 CURL_SSL_FLAVOUR="gnutls"
123 AC_MSG_RESULT([gnutls])
124 AC_DEFINE([HTTP_HAVE_GNUTLS], [1], [ ])
125 AC_CHECK_HEADERS([gcrypt.h])
126 break
127 fi
128 done
129 if test -z "$CURL_SSL_FLAVOUR"; then
130 AC_MSG_RESULT([unknown!])
131 AC_MSG_WARN([Could not determine the type of SSL library used!])
132 AC_MSG_WARN([Building will fail in ZTS mode!])
133 fi
134 else
135 AC_MSG_RESULT([no])
136 fi
137
138 PHP_ADD_INCLUDE($CURL_DIR/include)
139 PHP_ADD_LIBRARY_WITH_PATH(curl, $CURL_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
140 PHP_EVAL_LIBLINE($CURL_LIBS, HTTP_SHARED_LIBADD)
141 AC_DEFINE([HTTP_HAVE_CURL], [1], [Have cURL support])
142
143 PHP_CHECK_LIBRARY(curl, curl_multi_strerror,
144 [AC_DEFINE([HAVE_CURL_MULTI_STRERROR], [1], [ ])], [ ],
145 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
146 )
147 PHP_CHECK_LIBRARY(curl, curl_easy_strerror,
148 [AC_DEFINE([HAVE_CURL_EASY_STRERROR], [1], [ ])], [ ],
149 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
150 )
151 PHP_CHECK_LIBRARY(curl, curl_easy_reset,
152 [AC_DEFINE([HAVE_CURL_EASY_RESET], [1], [ ])], [ ],
153 [$CURL_LIBS -L$CURL_DIR/$PHP_LIBDIR]
154 )
155 fi
156
157 dnl ----
158 dnl MAGIC
159 dnl ----
160 if test "$PHP_HTTP_MAGIC_MIME" != "no"; then
161
162 AC_MSG_CHECKING([for magic.h])
163 MAGIC_DIR=
164 for i in "$PHP_HTTP_MAGIC_MIME" /usr/local /usr /opt; do
165 if test -f "$i/include/magic.h"; then
166 MAGIC_DIR=$i
167 break
168 fi
169 done
170 if test -z "$MAGIC_DIR"; then
171 AC_MSG_RESULT([not found])
172 AC_MSG_ERROR([could not find magic.h])
173 else
174 AC_MSG_RESULT([found in $MAGIC_DIR])
175 fi
176
177 PHP_ADD_INCLUDE($MAGIC_DIR/include)
178 PHP_ADD_LIBRARY_WITH_PATH(magic, $MAGIC_DIR/$PHP_LIBDIR, HTTP_SHARED_LIBADD)
179 AC_DEFINE([HTTP_HAVE_MAGIC], [1], [Have magic mime support])
180 fi
181
182 dnl ----
183 dnl HASH
184 dnl ----
185
186 AC_MSG_CHECKING(for ext/hash support)
187 if test -x "$PHP_EXECUTABLE"; then
188 if test "`$PHP_EXECUTABLE -m | $EGREP '^hash$'`" = "hash"; then
189 if test -d ../hash; then
190 PHP_ADD_INCLUDE([../hash])
191 fi
192 old_CPPFLAGS=$CPPFLAGS
193 CPPFLAGS=$INCLUDES
194 AC_MSG_RESULT([looking for php_hash.h])
195 AC_CHECK_HEADER([ext/hash/php_hash.h], [
196 AC_DEFINE([HTTP_HAVE_EXT_HASH_EXT_HASH], [1], [Have ext/hash support])
197 ], [
198 AC_CHECK_HEADER([hash/php_hash.h], [
199 AC_DEFINE([HTTP_HAVE_HASH_EXT_HASH], [1], [Have ext/hash support])
200 ], [
201 AC_CHECK_HEADER([php_hash.h], [
202 AC_DEFINE([HTTP_HAVE_EXT_HASH], [1], [Have ext/hash support])
203 ])
204 ])
205 ])
206 CPPFLAGS=$old_CPPFLAGS;
207 else
208 AC_MSG_RESULT(disabled)
209 fi
210 elif test "$PHP_HASH" != "no" && test "x$PHP_HASH" != "x"; then
211 AC_MSG_RESULT(enabled)
212 ifdef([PHP_ADD_EXTENSION_DEP], [
213 PHP_ADD_EXTENSION_DEP([http], [hash], 0)
214 AC_DEFINE([HTTP_HAVE_EXT_HASH_EXT_HASH], [1], [Have ext/hash support])
215 ])
216 else
217 AC_MSG_RESULT(disabled)
218 fi
219
220 dnl ----
221 dnl DONE
222 dnl ----
223 PHP_HTTP_SOURCES="missing.c http.c http_functions.c phpstr/phpstr.c \
224 http_util_object.c http_message_object.c http_request_object.c http_request_pool_api.c \
225 http_response_object.c http_exception_object.c http_requestpool_object.c \
226 http_api.c http_cache_api.c http_request_api.c http_date_api.c \
227 http_headers_api.c http_message_api.c http_send_api.c http_url_api.c \
228 http_info_api.c http_request_method_api.c http_encoding_api.c \
229 http_filter_api.c http_request_body_api.c"
230 PHP_NEW_EXTENSION([http], $PHP_HTTP_SOURCES, $ext_shared)
231 PHP_ADD_BUILD_DIR($ext_builddir/phpstr, 1)
232 PHP_SUBST([HTTP_SHARED_LIBADD])
233
234 PHP_HTTP_HEADERS="php_http_std_defs.h php_http.h php_http_api.h php_http_cache_api.h \
235 php_http_date_api.h php_http_headers_api.h php_http_info_api.h php_http_message_api.h \
236 php_http_request_api.h php_http_request_method_api.h php_http_send_api.h php_http_url_api.h \
237 php_http_encoding_api.h phpstr/phpstr.h missing.h php_http_request_body_api.h \
238 php_http_exception_object.h php_http_message_object.h php_http_request_object.h \
239 php_http_requestpool_object.h php_http_response_object.h php_http_util_object.h"
240 ifdef([PHP_INSTALL_HEADERS], [
241 PHP_INSTALL_HEADERS(ext/http, $PHP_HTTP_HEADERS)
242 ], [
243 PHP_SUBST([PHP_HTTP_HEADERS])
244 PHP_ADD_MAKEFILE_FRAGMENT
245 ])
246
247 AC_DEFINE([HAVE_HTTP], [1], [Have extended HTTP support])
248 fi