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