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