this should finally do it
[m6w6/ext-ares] / config.m4
1 dnl $Id$
2 dnl config.m4 for extension ares
3
4 PHP_ARG_WITH(ares, for asynchronous resolver support,
5 [ --with-ares Include asynchronous resolver support])
6
7 if test "$PHP_ARES" != "no"; then
8 PHP_ARES_DIR=
9 AC_MSG_CHECKING(for ares.h)
10 for i in "$PHP_ARES" /usr/local /usr; do
11 if test -r "$i/include/ares.h"; then
12 PHP_ARES_DIR=$i
13 AC_MSG_RESULT(found in $i)
14 break;
15 fi
16 done
17 if test -z "$PHP_ARES_DIR"; then
18 AC_MSG_ERROR(could not find ares.h)
19 fi
20
21 dnl ##########
22 dnl newer versions of libcares need -lrt
23 dnl ##########
24 PHP_ADD_LIBRARY(rt, 1, ARES_SHARED_LIBADD)
25
26 PHP_ARES_LIB=
27 PHP_CHECK_LIBRARY(cares, ares_init, [
28 PHP_ARES_LIB=cares
29 echo $LDFLAGS
30 ], [
31 echo $LDFLAGS
32 PHP_CHECK_LIBRARY(ares, ares_init, [
33 PHP_ARES_LIB=ares
34 ], [
35 PHP_ARES_LIB=unknown
36 ], [
37 -lrt -L$PHP_ARES_DIR/$PHP_LIBDIR
38 ]
39 )
40 ], [
41 -lrt -L$PHP_ARES_DIR/$PHP_LIBDIR
42 ]
43 )
44 AC_MSG_CHECKING(for libares/libcares)
45 AC_MSG_RESULT($PHP_ARES_LIB)
46
47 if test $PHP_ARES_LIB = "unknown"; then
48 AC_MSG_ERROR(could neither find libares nor libcares)
49 elif test $PHP_ARES_LIB = "cares"; then
50 AC_DEFINE_UNQUOTED([PHP_ARES_LIBNAME], "c-ares (CURL)", [ ])
51 AC_DEFINE([PHP_ARES_EXPAND_LEN_TYPE], [long], [ ])
52 else
53 AC_DEFINE_UNQUOTED([PHP_ARES_LIBNAME], "ares (MIT)", [ ])
54 AC_DEFINE([PHP_ARES_EXPAND_LEN_TYPE], [int], [ ])
55 AC_DEFINE([HAVE_OLD_ARES_STRERROR], [1], [ ])
56 fi
57
58 PHP_CHECK_LIBRARY($PHP_ARES_LIB, ares_cancel,
59 [AC_DEFINE([HAVE_ARES_CANCEL], [1], [ ])], [ ],
60 [-lrt -L$PHP_ARES_DIR/$PHP_LIBDIR]
61 )
62 PHP_CHECK_LIBRARY($PHP_ARES_LIB, ares_getnameinfo,
63 [AC_DEFINE([HAVE_ARES_GETNAMEINFO], [1], [ ])], [ ],
64 [-lrt -L$PHP_ARES_DIR/$PHP_LIBDIR]
65 )
66 PHP_CHECK_LIBRARY($PHP_ARES_LIB, ares_getsock,
67 [AC_DEFINE([HAVE_ARES_GETSOCK], [1], [ ])], [ ],
68 [-lrt -L$PHP_ARES_DIR/$PHP_LIBDIR]
69 )
70 PHP_CHECK_LIBRARY($PHP_ARES_LIB, ares_version,
71 [AC_DEFINE([HAVE_ARES_VERSION], [1], [ ])], [ ],
72 [-lrt -L$PHP_ARES_DIR/$PHP_LIBDIR]
73 )
74
75 dnl ##########
76 dnl check new c-ares callback API
77 dnl ##########
78 save_LIBS=$LIBS
79 save_CFLAGS=$CFLAGS
80 LDFLIBS="-L$PHP_ARES_DIR/$PHP_LIBDIR -l$PHP_ARES_LIB -lrt"
81 CFLAGS="-I$PHP_ARES_DIR/include -Werror"
82
83 AC_MSG_CHECKING(for new c-ares callback API)
84 AC_TRY_COMPILE(
85 [#include <ares.h>
86 ], [
87 ares_search(0, 0, 0, 0, (void (*)(void *, int, int, unsigned char *, int)) 0, 0);
88 ], [
89 AC_MSG_RESULT(yes)
90 AC_DEFINE([PHP_ARES_NEW_CALLBACK_API], [1], [ ])
91 ], [
92 AC_MSG_RESULT(no)
93 AC_DEFINE([PHP_ARES_NEW_CALLBACK_API], [0], [ ])
94 ]
95 )
96
97 LIBS=$save_LIBS
98 CFLAGS=$save_CFLAGS
99
100 AC_CHECK_HEADERS([netdb.h unistd.h arpa/inet.h arpa/nameser.h])
101
102 PHP_ADD_INCLUDE($PHP_ARES_DIR/include)
103 PHP_ADD_LIBRARY_WITH_PATH($PHP_ARES_LIB, $PHP_ARES_DIR/$PHP_LIBDIR, ARES_SHARED_LIBADD)
104
105 PHP_SUBST(ARES_SHARED_LIBADD)
106 PHP_NEW_EXTENSION(ares, ares.c, $ext_shared)
107 fi