Refactor configure script detection of functions used to set sockets into
[platform/upstream/c-ares.git] / configure.ac
1 AC_PREREQ(2.57)
2
3 dnl Version not hardcoded here. Fetched later from ares_version.h
4 AC_INIT([c-ares], [-],
5   [c-ares mailing list => http://cool.haxx.se/mailman/listinfo/c-ares])
6
7 AC_CONFIG_SRCDIR([ares_ipv6.h])
8 AM_CONFIG_HEADER([config.h])
9 AM_MAINTAINER_MODE
10
11 CARES_CHECK_OPTION_DEBUG
12 CARES_CHECK_OPTION_OPTIMIZE
13 CARES_CHECK_OPTION_WARNINGS
14
15 dnl SED is mandatory for configure process and libtool.
16 dnl Set it now, allowing it to be changed later.
17 AC_PATH_PROG([SED], [sed], [not_found],
18   [$PATH:/usr/bin:/usr/local/bin])
19 if test -z "$SED" || test "$SED" = "not_found"; then
20   AC_MSG_ERROR([sed not found in PATH. Cannot continue without sed.])
21 fi
22 AC_SUBST([SED])
23
24 dnl GREP is mandatory for configure process and libtool.
25 dnl Set it now, allowing it to be changed later.
26 AC_PATH_PROG([GREP], [grep], [not_found],
27   [$PATH:/usr/bin:/usr/local/bin])
28 if test -z "$GREP" || test "$GREP" = "not_found"; then
29   AC_MSG_ERROR([grep not found in PATH. Cannot continue without grep.])
30 fi
31 AC_SUBST([GREP])
32
33 dnl EGREP is mandatory for configure process and libtool.
34 dnl Set it now, allowing it to be changed later.
35 if echo a | ($GREP -E '(a|b)') >/dev/null 2>&1; then
36   AC_MSG_CHECKING([for egrep])
37   EGREP="$GREP -E"
38   AC_MSG_RESULT([$EGREP])
39 else
40   AC_PATH_PROG([EGREP], [egrep], [not_found],
41     [$PATH:/usr/bin:/usr/local/bin])
42 fi
43 if test -z "$EGREP" || test "$EGREP" = "not_found"; then
44   AC_MSG_ERROR([egrep not found in PATH. Cannot continue without egrep.])
45 fi
46 AC_SUBST([EGREP])
47
48 dnl AR is mandatory for configure process and libtool.
49 dnl This is target dependant, so check it as a tool.
50 AC_PATH_TOOL([AR], [ar], [not_found],
51   [$PATH:/usr/bin:/usr/local/bin])
52 if test -z "$AR" || test "$AR" = "not_found"; then
53   AC_MSG_ERROR([ar not found in PATH. Cannot continue without ar.])
54 fi
55 AC_SUBST([AR])
56
57 dnl Fetch c-ares version from ares_version.h
58 VERSION=`$SED -ne 's/^#define ARES_VERSION_STR "\(.*\)"/\1/p' ${srcdir}/ares_version.h`
59 AM_INIT_AUTOMAKE([c-ares], [$VERSION])
60 AC_MSG_CHECKING([c-ares version])
61 AC_MSG_RESULT([$VERSION])
62
63 dnl
64 dnl Detect the canonical host and target build environment
65 dnl
66
67 AC_CANONICAL_HOST
68 dnl Get system canonical name
69 AC_DEFINE_UNQUOTED(OS, "${host}", [cpu-machine-OS])
70
71 CARES_CHECK_PROG_CC
72 AM_PROG_CC_C_O
73 AC_PROG_INSTALL
74
75 dnl This defines _ALL_SOURCE for AIX
76 CARES_CHECK_AIX_ALL_SOURCE
77
78 dnl Our configure and build reentrant settings
79 CARES_CONFIGURE_REENTRANT
80
81 dnl check for how to do large files
82 AC_SYS_LARGEFILE
83
84 case $host_os in
85   solaris*)
86     AC_DEFINE(ETC_INET, 1, [if a /etc/inet dir is being used])
87     ;;
88 esac
89
90 dnl support building of Windows DLLs
91 AC_LIBTOOL_WIN32_DLL
92
93 CARES_PROCESS_DEBUG_BUILD_OPTS
94
95 AM_CONDITIONAL(DEBUGBUILD, test x$want_debug = xyes)
96 AM_CONDITIONAL(CURLDEBUG, test x$want_debug = xyes)
97
98 dnl skip libtool C++ and Fortran compiler checks
99 m4_ifdef([AC_PROG_CXX], [m4_undefine([AC_PROG_CXX])])
100 m4_defun([AC_PROG_CXX],[])
101 m4_ifdef([AC_PROG_CXXCPP], [m4_undefine([AC_PROG_CXXCPP])])
102 m4_defun([AC_PROG_CXXCPP],[true])
103 m4_ifdef([AC_PROG_F77], [m4_undefine([AC_PROG_F77])])
104 m4_defun([AC_PROG_F77],[])
105
106 dnl skip libtool C++ and Fortran linker checks
107 m4_ifdef([AC_LIBTOOL_CXX], [m4_undefine([AC_LIBTOOL_CXX])])
108 m4_defun([AC_LIBTOOL_CXX],[])
109 m4_ifdef([AC_LIBTOOL_CXXCPP], [m4_undefine([AC_LIBTOOL_CXXCPP])])
110 m4_defun([AC_LIBTOOL_CXXCPP],[true])
111 m4_ifdef([AC_LIBTOOL_F77], [m4_undefine([AC_LIBTOOL_F77])])
112 m4_defun([AC_LIBTOOL_F77],[])
113
114 dnl force libtool to build static libraries with PIC on AMD64-Linux & FreeBSD
115 AC_MSG_CHECKING([if arch-OS host is AMD64-Linux/FreeBSD (to build static libraries with PIC)])
116 case $host in
117   x86_64*linux*|amd64*freebsd*|ia64*freebsd*)
118     AC_MSG_RESULT([yes])
119     with_pic=yes
120     ;;
121   *)
122     AC_MSG_RESULT([no])
123     ;;
124 esac
125
126 dnl libtool setup
127 AC_PROG_LIBTOOL
128
129 AC_MSG_CHECKING([if we need -no-undefined])
130 case $host in
131   *-*-cygwin* | *-*-mingw* | *-*-pw32* | *-*-cegcc*)
132     need_no_undefined=yes
133     ;;
134   *)
135     need_no_undefined=no
136     ;;
137 esac
138 AC_MSG_RESULT($need_no_undefined)
139 AM_CONDITIONAL(NO_UNDEFINED, test x$need_no_undefined = xyes)
140
141 dnl **********************************************************************
142 dnl platform/compiler/architecture specific checks/flags
143 dnl **********************************************************************
144
145 CARES_CHECK_COMPILER
146 CARES_SET_COMPILER_BASIC_OPTS
147 CARES_SET_COMPILER_DEBUG_OPTS
148 CARES_SET_COMPILER_OPTIMIZE_OPTS
149 CARES_SET_COMPILER_WARNING_OPTS
150
151 case $host in
152   #
153   x86_64*linux*|amd64*freebsd*|ia64*freebsd*)
154     #
155     if test "$compiler_id" = "INTEL_UNIX_C"; then
156       #
157       if test "$compiler_num" -ge "900" &&
158         test "$compiler_num" -lt "1000"; then
159         dnl icc 9.X specific
160         CFLAGS="$CFLAGS -i-dynamic"
161       fi
162       #
163       if test "$compiler_num" -ge "1000"; then
164         dnl icc 10.X or later
165         CFLAGS="$CFLAGS -shared-intel"
166       fi
167       #
168     fi
169     ;;
170   #
171 esac
172
173 CURL_CHECK_COMPILER_HALT_ON_ERROR
174 CURL_CHECK_COMPILER_ARRAY_SIZE_NEGATIVE
175
176 dnl **********************************************************************
177 dnl Compilation based checks should not be done before this point.
178 dnl **********************************************************************
179
180 dnl **********************************************************************
181 dnl Make sure that our checks for headers windows.h winsock.h winsock2.h 
182 dnl and ws2tcpip.h take precedence over any other further checks which 
183 dnl could be done later using AC_CHECK_HEADER or AC_CHECK_HEADERS for
184 dnl this specific header files. And do them before its results are used.
185 dnl **********************************************************************
186
187 CURL_CHECK_HEADER_WINDOWS
188 CURL_CHECK_NATIVE_WINDOWS
189 case X-"$ac_cv_native_windows" in
190   X-yes)
191     CURL_CHECK_HEADER_WINSOCK
192     CURL_CHECK_HEADER_WINSOCK2
193     CURL_CHECK_HEADER_WS2TCPIP
194     ;;
195   *)
196     ac_cv_header_winsock_h="no"
197     ac_cv_header_winsock2_h="no"
198     ac_cv_header_ws2tcpip_h="no"
199     ;;
200 esac
201
202 dnl **********************************************************************
203 dnl Checks for libraries.
204 dnl **********************************************************************
205
206 dnl gethostbyname without lib or in the nsl lib?
207 AC_CHECK_FUNC(gethostbyname,
208               [HAVE_GETHOSTBYNAME="1"
209               ],
210               [ AC_CHECK_LIB(nsl, gethostbyname,
211                              [HAVE_GETHOSTBYNAME="1"
212                              LIBS="$LIBS -lnsl"
213                              ])
214               ])
215
216 if test "$HAVE_GETHOSTBYNAME" != "1"
217 then
218   dnl gethostbyname in the socket lib?
219   AC_CHECK_LIB(socket, gethostbyname,
220                [HAVE_GETHOSTBYNAME="1"
221                LIBS="$LIBS -lsocket"
222                ])
223 fi
224
225 dnl At least one system has been identified to require BOTH nsl and socket
226 dnl libs at the same time to link properly.
227 if test "$HAVE_GETHOSTBYNAME" != "1"
228 then
229   AC_MSG_CHECKING([for gethostbyname with both nsl and socket libs])
230   my_ac_save_LIBS=$LIBS
231   LIBS="-lnsl -lsocket $LIBS"
232   AC_LINK_IFELSE([
233     AC_LANG_PROGRAM([[
234     ]],[[
235       gethostbyname();
236     ]])
237   ],[
238     AC_MSG_RESULT([yes])
239     HAVE_GETHOSTBYNAME="1"
240   ],[
241     AC_MSG_RESULT([no])
242     LIBS=$my_ac_save_LIBS
243   ])
244 fi
245
246 if test "$HAVE_GETHOSTBYNAME" != "1"
247 then
248   dnl This is for winsock systems
249   if test "$ac_cv_header_windows_h" = "yes"; then
250     if test "$ac_cv_header_winsock_h" = "yes"; then
251       case $host in
252         *-*-mingw32ce*)
253           winsock_LIB="-lwinsock"
254           ;;
255         *)
256           winsock_LIB="-lwsock32"
257           ;;
258       esac
259     fi
260     if test "$ac_cv_header_winsock2_h" = "yes"; then
261       winsock_LIB="-lws2_32"
262     fi
263     if test ! -z "$winsock_LIB"; then
264       my_ac_save_LIBS=$LIBS
265       LIBS="$winsock_LIB $LIBS"
266       AC_MSG_CHECKING([for gethostbyname in $winsock_LIB])
267       AC_LINK_IFELSE([
268         AC_LANG_PROGRAM([[
269 #ifdef HAVE_WINDOWS_H
270 #ifndef WIN32_LEAN_AND_MEAN
271 #define WIN32_LEAN_AND_MEAN
272 #endif
273 #include <windows.h>
274 #ifdef HAVE_WINSOCK2_H
275 #include <winsock2.h>
276 #else
277 #ifdef HAVE_WINSOCK_H
278 #include <winsock.h>
279 #endif
280 #endif
281 #endif
282         ]],[[
283           gethostbyname("www.dummysite.com");
284         ]])
285       ],[
286         AC_MSG_RESULT([yes])
287         HAVE_GETHOSTBYNAME="1"
288       ],[
289         AC_MSG_RESULT([no])
290         winsock_LIB=""
291         LIBS=$my_ac_save_LIBS
292       ])
293     fi
294   fi
295 fi
296
297 if test "$HAVE_GETHOSTBYNAME" != "1"
298 then
299   dnl This is for Minix 3.1
300   AC_MSG_CHECKING([for gethostbyname for Minix 3])
301   AC_LINK_IFELSE([
302     AC_LANG_PROGRAM([[
303 /* Older Minix versions may need <net/gen/netdb.h> here instead */
304 #include <netdb.h>
305     ]],[[
306       gethostbyname("www.dummysite.com");
307     ]])
308   ],[
309     AC_MSG_RESULT([yes])
310     HAVE_GETHOSTBYNAME="1"
311   ],[
312     AC_MSG_RESULT([no])
313   ])
314 fi
315
316 if test "$HAVE_GETHOSTBYNAME" != "1"
317 then
318   dnl This is for eCos with a stubbed DNS implementation
319   AC_MSG_CHECKING([for gethostbyname for eCos])
320   AC_LINK_IFELSE([
321     AC_LANG_PROGRAM([[
322 #include <stdio.h>
323 #include <netdb.h>
324     ]],[[
325       gethostbyname("www.dummysite.com");
326     ]])
327   ],[
328     AC_MSG_RESULT([yes])
329     HAVE_GETHOSTBYNAME="1"
330   ],[
331     AC_MSG_RESULT([no])
332   ])
333 fi
334
335 if test "$HAVE_GETHOSTBYNAME" != "1"
336 then
337   dnl gethostbyname in the net lib - for BeOS
338   AC_CHECK_LIB(net, gethostbyname,
339                [HAVE_GETHOSTBYNAME="1"
340                LIBS="$LIBS -lnet"
341                ])
342 fi
343
344
345 if test "$HAVE_GETHOSTBYNAME" = "1"; then
346   AC_DEFINE(HAVE_GETHOSTBYNAME, 1, [If you have gethostbyname])
347 else
348   AC_MSG_ERROR([couldn't find libraries for gethostbyname()])
349 fi
350
351 dnl resolve lib?
352 AC_CHECK_FUNC(strcasecmp, , [ AC_CHECK_LIB(resolve, strcasecmp) ])
353
354 if test "$ac_cv_lib_resolve_strcasecmp" = "$ac_cv_func_strcasecmp"; then
355   AC_CHECK_LIB(resolve, strcasecmp,
356               [LIBS="-lresolve $LIBS"],
357                ,
358                -lnsl)
359 fi
360 ac_cv_func_strcasecmp="no"
361
362 dnl socket lib?
363 AC_CHECK_FUNC(connect, , [ AC_CHECK_LIB(socket, connect) ])
364
365 dnl **********************************************************************
366 dnl In case that function clock_gettime with monotonic timer is available,
367 dnl check for additional required libraries.
368 dnl **********************************************************************
369 CURL_CHECK_LIBS_CLOCK_GETTIME_MONOTONIC
370
371 AC_MSG_CHECKING([whether to use libgcc])
372 AC_ARG_ENABLE(libgcc,
373 AC_HELP_STRING([--enable-libgcc],[use libgcc when linking]),
374 [ case "$enableval" in
375   yes)
376         LIBS="$LIBS -lgcc"
377        AC_MSG_RESULT(yes)
378        ;;
379   *)   AC_MSG_RESULT(no)
380        ;;
381   esac ],
382        AC_MSG_RESULT(no)
383 )
384
385
386 dnl Default is to try the thread-safe versions of a few functions
387 OPT_THREAD=on
388
389 dnl detect AIX 4.3 or later
390 AC_MSG_CHECKING([AIX 4.3 or later])
391 AC_PREPROC_IFELSE([
392 #if defined(_AIX) && defined(_AIX43)
393 printf("just fine");
394 #else
395 #error "this is not AIX 4.3 or later"
396 #endif
397 ],
398  [ AC_MSG_RESULT([yes])
399    RECENTAIX=yes
400    OPT_THREAD=off ],
401  [ AC_MSG_RESULT([no]) ]
402 )
403
404 AC_ARG_ENABLE(thread,dnl
405 AC_HELP_STRING([--disable-thread],[don't look for thread-safe functions])
406 AC_HELP_STRING([--enable-thread],[look for thread-safe functions]),
407 [ case "$enableval" in
408   no)
409     OPT_THREAD=off
410     AC_MSG_WARN(c-ares will not get built using thread-safe functions)
411     ;;
412   *)
413     ;;
414   esac
415 ]
416 )
417
418 if test X"$OPT_THREAD" = Xoff
419 then
420   AC_DEFINE(DISABLED_THREADSAFE, 1,
421     [Set to explicitly specify we don't want to use thread-safe functions])
422 fi
423
424 dnl for recent AIX versions, we skip all the thread-safe checks above since
425 dnl they claim a thread-safe libc using the standard API. But there are
426 dnl some functions still not thread-safe. Check for these!
427
428 dnl Let's hope this split URL remains working:
429 dnl http://publibn.boulder.ibm.com/doc_link/en_US/a_doc_lib/aixprggd/ \
430 dnl genprogc/thread_quick_ref.htm
431
432 if test "x$RECENTAIX" = "xyes"; then
433
434   AC_DEFINE(_THREAD_SAFE, 1, [define this if you need it to compile thread-safe code])
435
436 fi
437
438
439 dnl **********************************************************************
440 dnl Back to "normal" configuring
441 dnl **********************************************************************
442
443 dnl Checks for header files.
444 AC_HEADER_STDC
445
446 CURL_CHECK_HEADER_MALLOC
447
448 dnl check for a few basic system headers we need
449 AC_CHECK_HEADERS(
450        sys/types.h \
451        sys/time.h \
452        sys/select.h \
453        sys/socket.h \
454        sys/ioctl.h \
455        sys/param.h \
456        sys/uio.h \
457        netdb.h \
458        netinet/in.h \
459        netinet/tcp.h \
460        net/if.h \
461        errno.h \
462        strings.h \
463        stdbool.h \
464        time.h \
465        arpa/nameser.h \
466        arpa/nameser_compat.h \
467        arpa/inet.h,
468 dnl to do if not found
469 [],
470 dnl to do if found
471 [],
472 dnl default includes
473 [
474 #ifdef HAVE_SYS_TYPES_H
475 #include <sys/types.h>
476 #endif
477 #ifdef HAVE_SYS_TIME_H
478 #include <sys/time.h>
479 #endif
480 dnl We do this default-include simply to make sure that the nameser_compat.h
481 dnl header *REALLY* can be include after the new nameser.h. It seems AIX 5.1
482 dnl (and others?) is not designed to allow this.
483 #ifdef HAVE_ARPA_NAMESER_H
484 #include <arpa/nameser.h>
485 #endif
486
487 dnl *Sigh* these are needed in order for net/if.h to get properly detected.
488 #ifdef HAVE_SYS_SOCKET_H
489 #include <sys/socket.h>
490 #endif
491 #ifdef HAVE_NETINET_IN_H
492 #include <netinet/in.h>
493 #endif
494 ]
495 )
496
497 dnl Checks for typedefs, structures, and compiler characteristics.
498 AC_C_CONST
499 AC_TYPE_SIZE_T
500 AC_HEADER_TIME
501 CURL_CHECK_STRUCT_TIMEVAL
502
503 AC_CHECK_SIZEOF(size_t)
504 AC_CHECK_SIZEOF(long)
505 AC_CHECK_SIZEOF(time_t)
506
507 AC_CHECK_TYPE(long long,
508    [AC_DEFINE(HAVE_LONGLONG, 1,
509      [Define to 1 if the compiler supports the 'long long' data type.])]
510    longlong="yes"  
511 )
512
513 if test "xyes" = "x$longlong"; then
514   AC_MSG_CHECKING([if numberLL works])
515   AC_COMPILE_IFELSE([long long val = 1000LL;],
516    [AC_DEFINE(HAVE_LL, 1, [if your compiler supports LL])]
517    AC_MSG_RESULT(yes),
518    AC_MSG_RESULT(no)
519   )
520 fi
521
522
523 # check for ssize_t
524 AC_CHECK_TYPE(ssize_t, ,
525    AC_DEFINE(ssize_t, int, [the signed version of size_t]))
526
527 # check for bool type
528 AC_CHECK_TYPE([bool],[
529   AC_DEFINE(HAVE_BOOL_T, 1,
530     [Define to 1 if bool is an available type.])
531 ], ,[
532 #ifdef HAVE_SYS_TYPES_H
533 #include <sys/types.h>
534 #endif
535 #ifdef HAVE_STDBOOL_H
536 #include <stdbool.h>
537 #endif
538 ])
539
540 # Check for socklen_t or equivalent
541 CURL_CHECK_TYPE_SOCKLEN_T
542
543 TYPE_IN_ADDR_T
544
545 TYPE_SOCKADDR_STORAGE
546
547 TYPE_SIG_ATOMIC_T
548
549 AC_TYPE_SIGNAL
550
551 CURL_CHECK_FUNC_RECV
552 CURL_CHECK_FUNC_RECVFROM
553 CURL_CHECK_FUNC_SEND
554 CURL_CHECK_MSG_NOSIGNAL
555
556 CARES_CHECK_FUNC_FCNTL
557 CARES_CHECK_FUNC_FREEADDRINFO
558 CARES_CHECK_FUNC_GETADDRINFO
559 CARES_CHECK_FUNC_GETHOSTNAME
560 CARES_CHECK_FUNC_GETSERVBYPORT_R
561 CARES_CHECK_FUNC_INET_NTOP
562 CARES_CHECK_FUNC_INET_PTON
563 CARES_CHECK_FUNC_IOCTL
564 CARES_CHECK_FUNC_IOCTLSOCKET
565 CARES_CHECK_FUNC_IOCTLSOCKET_CAMEL
566 CARES_CHECK_FUNC_SETSOCKOPT
567 CARES_CHECK_FUNC_STRCASECMP
568 CARES_CHECK_FUNC_STRCMPI
569 CARES_CHECK_FUNC_STRDUP
570 CARES_CHECK_FUNC_STRICMP
571 CARES_CHECK_FUNC_STRNCASECMP
572 CARES_CHECK_FUNC_STRNCMPI
573 CARES_CHECK_FUNC_STRNICMP
574 CARES_CHECK_FUNC_WRITEV
575
576
577 dnl check for AF_INET6
578 CARES_CHECK_CONSTANT(
579   [
580 #undef inline
581 #ifdef HAVE_WINDOWS_H
582 #ifndef WIN32_LEAN_AND_MEAN
583 #define WIN32_LEAN_AND_MEAN
584 #endif
585 #include <windows.h>
586 #ifdef HAVE_WINSOCK2_H
587 #include <winsock2.h>
588 #endif
589 #else
590 #ifdef HAVE_SYS_TYPES_H
591 #include <sys/types.h>
592 #endif
593 #ifdef HAVE_SYS_SOCKET_H
594 #include <sys/socket.h>
595 #endif
596 #endif
597   ], [PF_INET6], 
598      AC_DEFINE_UNQUOTED(HAVE_PF_INET6,1,[Define to 1 if you have PF_INET6.])
599 )
600
601 dnl check for PF_INET6
602 CARES_CHECK_CONSTANT(
603   [
604 #undef inline
605 #ifdef HAVE_WINDOWS_H
606 #ifndef WIN32_LEAN_AND_MEAN
607 #define WIN32_LEAN_AND_MEAN
608 #endif
609 #include <windows.h>
610 #ifdef HAVE_WINSOCK2_H
611 #include <winsock2.h>
612 #endif
613 #else
614 #ifdef HAVE_SYS_TYPES_H
615 #include <sys/types.h>
616 #endif
617 #ifdef HAVE_SYS_SOCKET_H
618 #include <sys/socket.h>
619 #endif
620 #endif
621   ], [AF_INET6], 
622      AC_DEFINE_UNQUOTED(HAVE_AF_INET6,1,[Define to 1 if you have AF_INET6.])
623 )
624
625
626 dnl check for the in6_addr structure
627 CARES_CHECK_STRUCT(
628   [
629 #undef inline
630 #ifdef HAVE_WINDOWS_H
631 #ifndef WIN32_LEAN_AND_MEAN
632 #define WIN32_LEAN_AND_MEAN
633 #endif
634 #include <windows.h>
635 #ifdef HAVE_WINSOCK2_H
636 #include <winsock2.h>
637 #ifdef HAVE_WS2TCPIP_H
638 #include <ws2tcpip.h>
639 #endif
640 #endif
641 #else
642 #ifdef HAVE_SYS_TYPES_H
643 #include <sys/types.h>
644 #endif
645 #ifdef HAVE_NETINET_IN_H
646 #include <netinet/in.h>
647 #endif
648 #endif
649   ], [in6_addr], 
650      AC_DEFINE_UNQUOTED(HAVE_STRUCT_IN6_ADDR,1,[Define to 1 if you have struct in6_addr.])
651 )
652
653 dnl check for the sockaddr_in6 structure
654 CARES_CHECK_STRUCT(
655   [
656 #undef inline
657 #ifdef HAVE_WINDOWS_H
658 #ifndef WIN32_LEAN_AND_MEAN
659 #define WIN32_LEAN_AND_MEAN
660 #endif
661 #include <windows.h>
662 #ifdef HAVE_WINSOCK2_H
663 #include <winsock2.h>
664 #ifdef HAVE_WS2TCPIP_H
665 #include <ws2tcpip.h>
666 #endif
667 #endif
668 #else
669 #ifdef HAVE_SYS_TYPES_H
670 #include <sys/types.h>
671 #endif
672 #ifdef HAVE_NETINET_IN_H
673 #include <netinet/in.h>
674 #endif
675 #endif
676   ], [sockaddr_in6], 
677      AC_DEFINE_UNQUOTED(HAVE_STRUCT_SOCKADDR_IN6,1,
678        [Define to 1 if you have struct sockaddr_in6.]) ac_have_sockaddr_in6=yes
679 )
680
681 AC_CHECK_MEMBER(struct sockaddr_in6.sin6_scope_id,
682     AC_DEFINE_UNQUOTED(HAVE_SOCKADDR_IN6_SIN6_SCOPE_ID,1,
683       [Define to 1 if your struct sockaddr_in6 has sin6_scope_id.])
684    , ,
685   [
686 #undef inline
687 #ifdef HAVE_WINDOWS_H
688 #ifndef WIN32_LEAN_AND_MEAN
689 #define WIN32_LEAN_AND_MEAN
690 #endif
691 #include <windows.h>
692 #ifdef HAVE_WINSOCK2_H
693 #include <winsock2.h>
694 #ifdef HAVE_WS2TCPIP_H
695 #include <ws2tcpip.h>
696 #endif
697 #endif
698 #else
699 #ifdef HAVE_SYS_TYPES_H
700 #include <sys/types.h>
701 #endif
702 #ifdef HAVE_NETINET_IN_H
703 #include <netinet/in.h>
704 #endif
705 #endif
706   ])
707
708 dnl check for the addrinfo structure
709 AC_CHECK_MEMBER(struct addrinfo.ai_flags,
710      AC_DEFINE_UNQUOTED(HAVE_STRUCT_ADDRINFO,1,
711        [Define to 1 if you have struct addrinfo.]),,
712   [
713 #undef inline
714 #ifdef HAVE_WINDOWS_H
715 #ifndef WIN32_LEAN_AND_MEAN
716 #define WIN32_LEAN_AND_MEAN
717 #endif
718 #include <windows.h>
719 #ifdef HAVE_WINSOCK2_H
720 #include <winsock2.h>
721 #ifdef HAVE_WS2TCPIP_H
722 #include <ws2tcpip.h>
723 #endif
724 #endif
725 #else
726 #ifdef HAVE_SYS_TYPES_H
727 #include <sys/types.h>
728 #endif
729 #ifdef HAVE_NETINET_IN_H
730 #include <netinet/in.h>
731 #endif
732 #ifdef HAVE_SYS_SOCKET_H
733 #include <sys/socket.h>
734 #endif
735 #ifdef HAVE_NETDB_H
736 #include <netdb.h>
737 #endif
738 #endif
739   ]
740 )
741
742
743 AC_CHECK_FUNCS([bitncmp \
744   gettimeofday \
745   if_indextoname
746 ],[
747 ],[
748   func="$ac_func"
749   AC_MSG_CHECKING([deeper for $func])
750   AC_LINK_IFELSE([
751     AC_LANG_PROGRAM([[
752     ]],[[
753       $func ();
754     ]])
755   ],[
756     AC_MSG_RESULT([yes])
757     eval "ac_cv_func_$func=yes"
758     AC_DEFINE_UNQUOTED([AS_TR_CPP([HAVE_$func])], [1],
759       [Define to 1 if you have the $func function.])
760   ],[
761     AC_MSG_RESULT([but still no])
762   ])
763 ])
764
765
766 dnl Check for inet_net_pton
767 AC_CHECK_FUNCS(inet_net_pton)
768 dnl Again, some systems have it, but not IPv6
769 if test "$ac_cv_func_inet_net_pton" = "yes" ; then
770 AC_MSG_CHECKING(if inet_net_pton supports IPv6)
771 AC_TRY_RUN(
772   [
773 #ifdef HAVE_SYS_TYPES_H
774 #include <sys/types.h>
775 #endif
776 #ifdef HAVE_SYS_SOCKET_H
777 #include <sys/socket.h>
778 #endif
779 #ifdef HAVE_NETINET_IN_H
780 #include <netinet/in.h>
781 #endif
782 int main()
783   {
784     struct in6_addr addr6;
785     if (inet_net_pton(AF_INET6, "::1", &addr6, sizeof(addr6)) < 1)
786       exit(1);
787     else
788       exit(0);
789   }
790   ], [
791        AC_MSG_RESULT(yes)
792        AC_DEFINE_UNQUOTED(HAVE_INET_NET_PTON_IPV6,1,[Define to 1 if inet_net_pton supports IPv6.])
793      ], AC_MSG_RESULT(no),AC_MSG_RESULT(no))
794 fi
795
796
797 AC_CHECK_SIZEOF(struct in6_addr, ,
798 [
799 #undef inline
800 #ifdef HAVE_WINDOWS_H
801 #ifndef WIN32_LEAN_AND_MEAN
802 #define WIN32_LEAN_AND_MEAN
803 #endif
804 #include <windows.h>
805 #ifdef HAVE_WINSOCK2_H
806 #include <winsock2.h>
807 #ifdef HAVE_WS2TCPIP_H
808 #include <ws2tcpip.h>
809 #endif
810 #endif
811 #else
812 #ifdef HAVE_SYS_TYPES_H
813 #include <sys/types.h>
814 #endif
815 #ifdef HAVE_SYS_SOCKET_H
816 #include <sys/socket.h>
817 #endif
818 #ifdef HAVE_NETINET_IN_H
819 #include <netinet/in.h>
820 #endif
821 #endif
822 ]
823 )
824
825 AC_CHECK_SIZEOF(struct in_addr, ,
826 [
827 #undef inline
828 #ifdef HAVE_WINDOWS_H
829 #ifndef WIN32_LEAN_AND_MEAN
830 #define WIN32_LEAN_AND_MEAN
831 #endif
832 #include <windows.h>
833 #ifdef HAVE_WINSOCK2_H
834 #include <winsock2.h>
835 #ifdef HAVE_WS2TCPIP_H
836 #include <ws2tcpip.h>
837 #endif
838 #endif
839 #else
840 #ifdef HAVE_SYS_TYPES_H
841 #include <sys/types.h>
842 #endif
843 #ifdef HAVE_SYS_SOCKET_H
844 #include <sys/socket.h>
845 #endif
846 #ifdef HAVE_NETINET_IN_H
847 #include <netinet/in.h>
848 #endif
849 #endif
850 ]
851 )
852
853
854 dnl Check if the getnameinfo function is available
855 dnl and get the types of five of its arguments.
856 CURL_CHECK_FUNC_GETNAMEINFO
857
858
859 AC_C_BIGENDIAN(
860     [AC_DEFINE(ARES_BIG_ENDIAN, 1,
861       [define this if ares is built for a big endian system])],
862     ,
863     [AC_MSG_WARN([couldn't figure out endianess, assuming little endian!])]
864 )
865
866 dnl Check for user-specified random device
867 AC_ARG_WITH(random,
868 AC_HELP_STRING([--with-random=FILE],
869                [read randomness from FILE (default=/dev/urandom)]),
870     [ RANDOM_FILE="$withval" ],
871     [
872         dnl Check for random device.  If we're cross compiling, we can't
873         dnl check, and it's better to assume it doesn't exist than it is
874         dnl to fail on AC_CHECK_FILE or later.
875         if test "$cross_compiling" = "no"; then
876           AC_CHECK_FILE("/dev/urandom", [ RANDOM_FILE="/dev/urandom"] )
877         else
878           AC_MSG_WARN([cannot check for /dev/urandom while cross compiling; assuming none])
879         fi
880         
881     ]
882 )
883 if test -n "$RANDOM_FILE" && test X"$RANDOM_FILE" != Xno ; then
884         AC_SUBST(RANDOM_FILE)
885         AC_DEFINE_UNQUOTED(RANDOM_FILE, "$RANDOM_FILE",
886         [a suitable file/device to read random data from])
887 fi
888
889 CARES_CHECK_OPTION_NONBLOCKING
890 CARES_CHECK_NONBLOCKING_SOCKET
891
892 CARES_PRIVATE_LIBS="$LIBS"
893 AC_SUBST(CARES_PRIVATE_LIBS)
894
895 dnl squeeze whitespace out of some variables
896
897 squeeze CFLAGS
898 squeeze CPPFLAGS
899 squeeze DEFS
900 squeeze LDFLAGS
901 squeeze LIBS
902
903 squeeze CARES_PRIVATE_LIBS
904
905 AC_CONFIG_FILES([Makefile libcares.pc])
906 AC_OUTPUT