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