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