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