• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1dnl Copyright (C) The c-ares project and its contributors
2dnl SPDX-License-Identifier: MIT
3AC_PREREQ([2.69])
4
5AC_INIT([c-ares], [1.27.0],
6  [c-ares mailing list: http://lists.haxx.se/listinfo/c-ares])
7
8CARES_VERSION_INFO="14:0:12"
9dnl This flag accepts an argument of the form current[:revision[:age]]. So,
10dnl passing -version-info 3:12:1 sets current to 3, revision to 12, and age to
11dnl 1.
12dnl
13dnl If either revision or age are omitted, they default to 0. Also note that age
14dnl must be less than or equal to the current interface number.
15dnl
16dnl Here are a set of rules to help you update your library version information:
17dnl
18dnl 1.Start with version information of 0:0:0 for each libtool library.
19dnl
20dnl 2.Update the version information only immediately before a public release of
21dnl your software. More frequent updates are unnecessary, and only guarantee
22dnl that the current interface number gets larger faster.
23dnl
24dnl 3.If the library source code has changed at all since the last update, then
25dnl increment revision (c:r+1:a)
26dnl
27dnl 4.If any interfaces have been added, removed, or changed since the last
28dnl update, increment current, and set revision to 0. (c+1:r=0:a)
29dnl
30dnl 5.If any interfaces have been added since the last public release, then
31dnl increment age. (c:r:a+1)
32dnl
33dnl 6.If any interfaces have been removed since the last public release, then
34dnl set age to 0. (c:r:a=0)
35dnl
36AC_SUBST([CARES_VERSION_INFO])
37
38AC_CONFIG_SRCDIR([src/lib/ares_ipv6.h])
39AC_CONFIG_HEADERS([src/lib/ares_config.h include/ares_build.h])
40AC_CONFIG_AUX_DIR(config)
41AC_CONFIG_MACRO_DIR([m4])
42AC_USE_SYSTEM_EXTENSIONS
43AX_CXX_COMPILE_STDCXX_14([noext],[optional])
44AM_INIT_AUTOMAKE([foreign subdir-objects 1.9.6])
45LT_INIT([win32-dll,pic,disable-fast-install,aix-soname=svr4])
46AC_LANG([C])
47AC_PROG_CC
48AM_PROG_CC_C_O
49AC_PROG_EGREP
50AC_PROG_INSTALL
51AC_CANONICAL_HOST
52AX_COMPILER_VENDOR
53
54AC_MSG_CHECKING([whether this is native windows])
55ac_cv_native_windows=no
56ac_cv_windows=no
57case $host_os in
58  mingw*)
59    ac_cv_native_windows=yes
60    ac_cv_windows=yes
61    ;;
62  cygwin*)
63    ac_cv_windows=yes
64    ;;
65esac
66if test "$ax_cv_c_compiler_vendor" = "microsoft" ; then
67  ac_cv_native_windows=yes
68  ac_cv_windows=yes
69fi
70AC_MSG_RESULT($ac_cv_native_windows)
71
72
73AC_ENABLE_SHARED
74
75dnl Disable static builds by default on Windows unless overwritten since Windows
76dnl can't simultaneously build shared and static with autotools.
77AS_IF([test "x$ac_cv_windows" = "xyes"], [AC_DISABLE_STATIC], [AC_ENABLE_STATIC])
78
79AC_ARG_ENABLE(warnings,
80  AS_HELP_STRING([--disable-warnings],[Disable strict compiler warnings]),
81  [ enable_warnings=${enableval} ],
82  [ enable_warnings=yes ])
83
84AC_ARG_ENABLE(symbol-hiding,
85  AS_HELP_STRING([--disable-symbol-hiding], [Disable symbol hiding. Enabled by default if the compiler supports it.]),
86  [
87    symbol_hiding="$enableval"
88    if test "$symbol_hiding" = "no" -a "x$enable_shared" = "xyes" ; then
89      case $host_os in
90        cygwin* | mingw* | pw32* | cegcc*)
91          AC_MSG_ERROR([Cannot disable symbol hiding on windows])
92        ;;
93      esac
94    fi
95  ],
96  [
97    if test "x$enable_shared" = "xyes" ; then
98      symbol_hiding="maybe"
99    else
100      symbol_hiding="no"
101    fi
102  ]
103)
104
105AC_ARG_ENABLE(tests,
106  AS_HELP_STRING([--disable-tests], [disable building of test suite. Built by default if GoogleTest is found.]),
107  [ build_tests="$enableval" ],
108  [ if test "x$HAVE_CXX14" = "x1" && test "x$cross_compiling" = "xno" ; then
109      build_tests="maybe"
110    else
111      build_tests="no"
112    fi
113  ]
114)
115
116AC_ARG_ENABLE(cares-threads,
117  AS_HELP_STRING([--disable-cares-threads], [Disable building of thread safety support]),
118  [ CARES_THREADS=${enableval} ],
119  [ CARES_THREADS=yes ])
120
121AC_ARG_WITH(random,
122  AS_HELP_STRING([--with-random=FILE],
123                 [read randomness from FILE (default=/dev/urandom)]),
124  [ CARES_RANDOM_FILE="$withval" ],
125  [ CARES_RANDOM_FILE="/dev/urandom" ]
126)
127if test -n "$CARES_RANDOM_FILE" && test X"$CARES_RANDOM_FILE" != Xno ; then
128  AC_SUBST(CARES_RANDOM_FILE)
129  AC_DEFINE_UNQUOTED(CARES_RANDOM_FILE, "$CARES_RANDOM_FILE", [a suitable file/device to read random data from])
130fi
131
132AM_MAINTAINER_MODE
133m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])
134
135
136dnl CARES_DEFINE_UNQUOTED (VARIABLE, [VALUE])
137dnl -------------------------------------------------
138dnl Like AC_DEFINE_UNQUOTED this macro will define a C preprocessor
139dnl symbol that can be further used in custom template configuration
140dnl files. This macro, unlike AC_DEFINE_UNQUOTED, does not use a third
141dnl argument for the description. Symbol definitions done with this
142dnl macro are intended to be exclusively used in handcrafted *.h.in
143dnl template files. Contrary to what AC_DEFINE_UNQUOTED does, this one
144dnl prevents autoheader generation and insertion of symbol template
145dnl stub and definition into the first configuration header file. Do
146dnl not use this macro as a replacement for AC_DEFINE_UNQUOTED, each
147dnl one serves different functional needs.
148
149AC_DEFUN([CARES_DEFINE_UNQUOTED], [
150cat >>confdefs.h <<_EOF
151[@%:@define] $1 ifelse($#, 2, [$2], 1)
152_EOF
153])
154
155AX_CODE_COVERAGE
156AX_CHECK_USER_NAMESPACE
157AX_CHECK_UTS_NAMESPACE
158AC_SYS_LARGEFILE
159
160case $host_os in
161  solaris*)
162    AC_DEFINE(ETC_INET, 1, [if a /etc/inet dir is being used])
163    ;;
164esac
165
166dnl solaris needed flag
167case $host_os in
168  solaris2*)
169    if test "x$GCC" = 'xyes'; then
170      AX_APPEND_LINK_FLAGS([-mimpure-text])
171    fi
172    ;;
173  *)
174    ;;
175esac
176
177dnl -no-undefined libtool (not linker) flag for windows
178cares_use_no_undefined=no
179case $host_os in
180  cygwin* | mingw* | pw32* | cegcc* | os2* | aix*)
181    cares_use_no_undefined=yes
182    ;;
183  *)
184    ;;
185esac
186AM_CONDITIONAL([CARES_USE_NO_UNDEFINED], [test "$cares_use_no_undefined" = 'yes'])
187
188
189if test "$ac_cv_native_windows" = "yes" ; then
190  AM_CPPFLAGS="$AM_CPPFLAGS -D_WIN32_WINNT=0x0602 -DWIN32_LEAN_AND_MEAN"
191fi
192
193dnl Windows can only build shared or static, not both at the same time
194if test "$ac_cv_native_windows" = "yes" -a "x$enable_shared" = "xyes" -a "x$enable_static" = "xyes" ; then
195  AC_MSG_ERROR([Windows cannot build both static and shared simultaneously, specify --disable-shared or --disable-static])
196fi
197
198dnl Only windows requires CARES_STATICLIB definition
199if test "x$enable_shared" = "xno" -a "x$enable_static" = "xyes" ; then
200  AC_MSG_CHECKING([whether we need CARES_STATICLIB definition])
201  if test "$ac_cv_native_windows" = "yes" ; then
202    AX_APPEND_FLAG([-DCARES_STATICLIB], [AM_CPPFLAGS])
203    PKGCONFIG_CFLAGS="-DCARES_STATICLIB"
204    AC_MSG_RESULT([yes])
205  else
206    AC_MSG_RESULT([no])
207  fi
208fi
209
210dnl Test for symbol hiding
211CARES_SYMBOL_HIDING_CFLAG=""
212if test "$symbol_hiding" != "no" ; then
213  compiler_supports_symbol_hiding="no"
214  if test "$ac_cv_windows" = "yes" ; then
215    compiler_supports_symbol_hiding="yes"
216  else
217    case "$ax_cv_c_compiler_vendor" in
218      clang|gnu|intel)
219        AX_APPEND_COMPILE_FLAGS([-fvisibility=hidden], [CARES_SYMBOL_HIDING_CFLAG])
220        if test "x$CARES_SYMBOL_HIDING_CFLAG" != "x" ; then
221          compiler_supports_symbol_hiding="yes"
222        fi
223        ;;
224      sun)
225        AX_APPEND_COMPILE_FLAGS([-xldscope=hidden], [CARES_SYMBOL_HIDING_CFLAG])
226        if test "x$CARES_SYMBOL_HIDING_CFLAG" != "x" ; then
227          compiler_supports_symbol_hiding="yes"
228        fi
229        ;;
230    esac
231  fi
232  if test "$compiler_supports_symbol_hiding" = "no" ; then
233    if test "$symbol_hiding" = "yes" ; then
234      AC_MSG_ERROR([Compiler does not support symbol hiding])
235    else
236      symbol_hiding="no"
237    fi
238  else
239    AC_DEFINE([CARES_SYMBOL_HIDING], [ 1 ], [Set to 1 if non-pubilc shared library symbols are hidden])
240    symbol_hiding="yes"
241  fi
242fi
243AM_CONDITIONAL(CARES_SYMBOL_HIDING, test "x$symbol_hiding" = "xyes")
244AC_SUBST(CARES_SYMBOL_HIDING_CFLAG)
245
246
247if test "$enable_warnings" = "yes"; then
248  AX_APPEND_COMPILE_FLAGS([-Wall \
249    -Wextra \
250    -Wcast-align \
251    -Wconversion \
252    -Wdeclaration-after-statement \
253    -Wdouble-promotion \
254    -Wfloat-equal \
255    -Wformat-security \
256    -Winit-self \
257    -Wjump-misses-init \
258    -Wlogical-op \
259    -Wmissing-braces \
260    -Wmissing-declarations \
261    -Wmissing-format-attribute \
262    -Wmissing-include-dirs \
263    -Wmissing-prototypes \
264    -Wnested-externs \
265    -Wno-coverage-mismatch \
266    -Wold-style-definition \
267    -Wpacked \
268    -Wpointer-arith \
269    -Wredundant-decls \
270    -Wshadow \
271    -Wsign-conversion \
272    -Wstrict-overflow \
273    -Wstrict-prototypes \
274    -Wtrampolines \
275    -Wundef \
276    -Wunused \
277    -Wvariadic-macros \
278    -Wvla \
279    -Wwrite-strings \
280    -Werror=implicit-int \
281    -Werror=implicit-function-declaration \
282    -Werror=partial-availability \
283  ], [AM_CFLAGS], [-Werror])
284fi
285
286if test "$ax_cv_c_compiler_vendor" = "intel"; then
287  AX_APPEND_COMPILE_FLAGS([-shared-intel], [AM_CFLAGS])
288fi
289
290if test "$ac_cv_native_windows" = "yes" ; then
291  dnl we use [ - ] in the 4th argument to tell AC_CHECK_HEADERS to simply
292  dnl check for existence of the headers, not usability.  This is because
293  dnl on windows, header order matters, and you need to include headers *after*
294  dnl other headers, AC_CHECK_HEADERS only allows you to specify headers that
295  dnl must be included *before* the header being checked.
296
297  AC_CHECK_HEADERS(
298    windows.h  \
299    winsock2.h \
300    ws2tcpip.h \
301    iphlpapi.h \
302    netioapi.h \
303    ws2ipdef.h \
304    winternl.h \
305    ntdef.h    \
306    ntstatus.h \
307    mswsock.h,
308    [], [], [-])
309
310  dnl Windows builds require linking to iphlpapi
311  if test "$ac_cv_header_winsock2_h" = "yes"; then
312    LIBS="$LIBS -lws2_32 -liphlpapi"
313  fi
314fi
315
316dnl **********************************************************************
317dnl Checks for libraries.
318dnl **********************************************************************
319
320dnl see if libnsl or libsocket are required
321AC_SEARCH_LIBS([getservbyport], [nsl socket resolv])
322
323AC_MSG_CHECKING([if libxnet is required])
324need_xnet=no
325case $host_os in
326  hpux*)
327    XNET_LIBS=""
328    AX_APPEND_LINK_FLAGS([-lxnet], [XNET_LIBS])
329    if test "x$XNET_LIBS" != "x" ; then
330      LIBS="$LIBS $XNET_LIBS"
331      need_xnet=yes
332    fi
333    ;;
334esac
335AC_MSG_RESULT($need_xnet)
336
337dnl resolv lib for Apple (MacOS and iOS)
338AS_IF([test "x$host_vendor" = "xapple"], [
339  AC_SEARCH_LIBS([res_servicename], [resolv], [
340    AC_DEFINE([CARES_USE_LIBRESOLV], [1], [Use resolver library to configure cares])
341  ], [
342    AC_MSG_ERROR([Unable to find libresolv which is required for iPhone targets])
343  ])
344])
345
346dnl resolv lib for z/OS
347AS_IF([test "x$host_vendor" = "xibm" -a "x$host_os" = "xopenedition" ], [
348  AC_SEARCH_LIBS([res_init], [resolv], [
349    AC_DEFINE([CARES_USE_LIBRESOLV], [1], [Use resolver library to configure cares])
350  ], [
351    AC_MSG_ERROR([Unable to find libresolv which is required for z/OS])
352  ])
353])
354
355
356dnl iOS 10?
357AS_IF([test "x$host_vendor" = "xapple"], [
358  AC_MSG_CHECKING([for iOS minimum version 10 or later])
359  AC_COMPILE_IFELSE([
360    AC_LANG_PROGRAM([[
361#include <stdio.h>
362#include <AvailabilityMacros.h>
363#include <TargetConditionals.h>
364    ]], [[
365#if TARGET_OS_IPHONE == 0 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
366#error Not iOS 10 or later
367#endif
368return 0;
369   ]])
370  ],[
371    AC_MSG_RESULT([yes])
372    ac_cv_ios_10="yes"
373  ],[
374    AC_MSG_RESULT([no])
375  ])
376])
377
378dnl macOS 10.12?
379AS_IF([test "x$host_vendor" = "xapple"], [
380  AC_MSG_CHECKING([for macOS minimum version 10.12 or later])
381  AC_COMPILE_IFELSE([
382    AC_LANG_PROGRAM([[
383#include <stdio.h>
384#include <AvailabilityMacros.h>
385#include <TargetConditionals.h>
386    ]], [[
387#ifndef MAC_OS_X_VERSION_10_12
388#  define MAC_OS_X_VERSION_10_12 101200
389#endif
390#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
391#error Not macOS 10.12 or later
392#endif
393return 0;
394   ]])
395  ],[
396    AC_MSG_RESULT([yes])
397    ac_cv_macos_10_12="yes"
398  ],[
399    AC_MSG_RESULT([no])
400  ])
401])
402
403AC_MSG_CHECKING([whether to use libgcc])
404AC_ARG_ENABLE(libgcc,
405AS_HELP_STRING([--enable-libgcc],[use libgcc when linking]),
406[ case "$enableval" in
407  yes)
408    LIBS="$LIBS -lgcc"
409    AC_MSG_RESULT(yes)
410    ;;
411  *)
412    AC_MSG_RESULT(no)
413    ;;
414  esac ],
415       AC_MSG_RESULT(no)
416)
417
418dnl check for a few basic system headers we need
419AC_CHECK_HEADERS(
420       malloc.h \
421       memory.h \
422       AvailabilityMacros.h \
423       sys/types.h \
424       sys/time.h \
425       sys/select.h \
426       sys/socket.h \
427       sys/filio.h \
428       sys/ioctl.h \
429       sys/param.h \
430       sys/uio.h \
431       sys/random.h \
432       sys/event.h \
433       sys/epoll.h \
434       assert.h \
435       iphlpapi.h \
436       netioapi.h \
437       netdb.h \
438       netinet/in.h \
439       netinet/tcp.h \
440       net/if.h \
441       ifaddrs.h \
442       fcntl.h \
443       errno.h \
444       socket.h \
445       strings.h \
446       stdbool.h \
447       time.h \
448       poll.h \
449       limits.h \
450       arpa/nameser.h \
451       arpa/nameser_compat.h \
452       arpa/inet.h,
453dnl to do if not found
454[],
455dnl to do if found
456[],
457dnl default includes
458[
459#ifdef HAVE_SYS_TYPES_H
460#include <sys/types.h>
461#endif
462#ifdef HAVE_SYS_TIME_H
463#include <sys/time.h>
464#endif
465dnl We do this default-include simply to make sure that the nameser_compat.h
466dnl header *REALLY* can be include after the new nameser.h. It seems AIX 5.1
467dnl (and others?) is not designed to allow this.
468#ifdef HAVE_ARPA_NAMESER_H
469#include <arpa/nameser.h>
470#endif
471
472dnl *Sigh* these are needed in order for net/if.h to get properly detected.
473#ifdef HAVE_SYS_SOCKET_H
474#include <sys/socket.h>
475#endif
476#ifdef HAVE_NETINET_IN_H
477#include <netinet/in.h>
478#endif
479]
480)
481
482
483cares_all_includes="
484#include <stdio.h>
485#include <stdlib.h>
486#ifdef HAVE_AVAILABILITYMACROS_H
487#  include <AvailabilityMacros.h>
488#endif
489#ifdef HAVE_SYS_UIO_H
490#  include <sys/uio.h>
491#endif
492#ifdef HAVE_NETINET_IN_H
493#  include <netinet/in.h>
494#endif
495#ifdef HAVE_TCP_H
496#  include <tcp.h>
497#endif
498#ifdef HAVE_SYS_FILIO_H
499#  include <sys/filio.h>
500#endif
501#ifdef HAVE_SYS_IOCTL_H
502#  include <sys/ioctl.h>
503#endif
504#ifdef HAVE_UNISTD_H
505#  include <unistd.h>
506#endif
507#ifdef HAVE_STRING_H
508#  include <string.h>
509#endif
510#ifdef HAVE_STRINGS_H
511#  include <strings.h>
512#endif
513#ifdef HAVE_TIME_H
514#  include <time.h>
515#endif
516#ifdef HAVE_SYS_TIME_H
517#  include <sys/time.h>
518#endif
519#ifdef HAVE_SYS_TYPES_H
520#  include <sys/types.h>
521#endif
522#ifdef HAVE_SYS_STAT_H
523#  include <sys/stat.h>
524#endif
525#ifdef HAVE_SYS_RANDOM_H
526#  include <sys/random.h>
527#endif
528#ifdef HAVE_SYS_EVENT_H
529#  include <sys/event.h>
530#endif
531#ifdef HAVE_SYS_EPOLL_H
532#  include <sys/epoll.h>
533#endif
534#ifdef HAVE_SYS_SOCKET_H
535#  include <sys/socket.h>
536#endif
537#ifdef HAVE_SYS_PARAM_H
538#  include <sys/param.h>
539#endif
540#ifdef HAVE_FCNTL_H
541#  include <fcntl.h>
542#endif
543#ifdef HAVE_POLL_H
544#  include <poll.h>
545#endif
546#ifdef HAVE_NET_IF_H
547#  include <net/if.h>
548#endif
549#ifdef HAVE_IFADDRS_H
550#  include <ifaddrs.h>
551#endif
552#ifdef HAVE_NETINET_IN_H
553#  include <netinet/in.h>
554#endif
555#ifdef HAVE_NETINET_TCP_H
556#  include <netinet/tcp.h>
557#endif
558#ifdef HAVE_NETDB_H
559#  include <netdb.h>
560#endif
561#ifdef HAVE_ARPA_INET_H
562#  include <arpa/inet.h>
563#endif
564#ifdef HAVE_RESOLV_H
565#  include <resolv.h>
566#endif
567#ifdef HAVE_IPHLPAPI_H
568#  include <iphlpapi.h>
569#endif
570#ifdef HAVE_NETIOAPI_H
571#  include <netioapi.h>
572#endif
573#ifdef HAVE_WINSOCK2_H
574#  include <winsock2.h>
575#endif
576#ifdef HAVE_WS2IPDEF_H
577#  include <ws2ipdef.h>
578#endif
579#ifdef HAVE_WS2TCPIP_H
580#  include <ws2tcpip.h>
581#endif
582#ifdef HAVE_WINDOWS_H
583#  include <windows.h>
584#endif
585"
586
587AC_CHECK_DECL([HAVE_ARPA_NAMESER_H],[CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_H])], [])
588AC_CHECK_DECL([HAVE_ARPA_NAMESER_COMPAT_H],[CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_COMPAT_H])],[])
589AC_CHECK_TYPE(long long, [AC_DEFINE(HAVE_LONGLONG, 1, [Define to 1 if the compiler supports the 'long long' data type.])])
590AC_CHECK_TYPE(ssize_t, [ CARES_TYPEOF_ARES_SSIZE_T=ssize_t ], [ CARES_TYPEOF_ARES_SSIZE_T=int ])
591AC_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SSIZE_T], ${CARES_TYPEOF_ARES_SSIZE_T}, [the signed version of size_t])
592
593AC_CHECK_TYPE(socklen_t,
594  [
595    AC_DEFINE(HAVE_SOCKLEN_T, [], [socklen_t])
596    CARES_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SOCKLEN_T], [socklen_t])
597  ],
598  [ CARES_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SOCKLEN_T], [int]) ],
599  $cares_all_includes
600 )
601
602AC_CHECK_TYPE(SOCKET, [], [], $cares_all_includes)
603
604dnl ###############################################################################
605
606dnl clock_gettime might require an external library
607AC_SEARCH_LIBS([clock_gettime], [rt posix4])
608
609dnl Use AC_CHECK_DECL not AC_CHECK_FUNCS, while this doesn't do a linkage test,
610dnl it just makes sure the headers define it, this is the only thing without
611dnl a complex workaround on Windows that will do what we need. See:
612dnl https://github.com/msys2/msys2/wiki/Porting/f87a222118b1008ebc166ad237f04edb759c8f4c#calling-conventions-stdcall-and-autotools
613dnl https://lists.gnu.org/archive/html/autoconf/2013-05/msg00085.html
614dnl and for a more complex workaround, we'd need to use AC_LINK_IFELSE like:
615dnl https://mailman.videolan.org/pipermail/vlc-devel/2015-March/101802.html
616dnl which would require we check each individually and provide function arguments
617dnl for the test.
618
619AC_CHECK_DECL(recv,            [AC_DEFINE([HAVE_RECV],              1, [Define to 1 if you have `recv`]           )], [], $cares_all_includes)
620AC_CHECK_DECL(recvfrom,        [AC_DEFINE([HAVE_RECVFROM],          1, [Define to 1 if you have `recvfrom`]       )], [], $cares_all_includes)
621AC_CHECK_DECL(send,            [AC_DEFINE([HAVE_SEND],              1, [Define to 1 if you have `send`]           )], [], $cares_all_includes)
622AC_CHECK_DECL(getnameinfo,     [AC_DEFINE([HAVE_GETNAMEINFO],       1, [Define to 1 if you have `getnameinfo`]    )], [], $cares_all_includes)
623AC_CHECK_DECL(gethostname,     [AC_DEFINE([HAVE_GETHOSTNAME],       1, [Define to 1 if you have `gethostname`]    )], [], $cares_all_includes)
624AC_CHECK_DECL(connect,         [AC_DEFINE([HAVE_CONNECT],           1, [Define to 1 if you have `connect`]        )], [], $cares_all_includes)
625AC_CHECK_DECL(closesocket,     [AC_DEFINE([HAVE_CLOSESOCKET],       1, [Define to 1 if you have `closesocket`]    )], [], $cares_all_includes)
626AC_CHECK_DECL(CloseSocket,     [AC_DEFINE([HAVE_CLOSESOCKET_CAMEL], 1, [Define to 1 if you have `CloseSocket`]    )], [], $cares_all_includes)
627AC_CHECK_DECL(fcntl,           [AC_DEFINE([HAVE_FCNTL],             1, [Define to 1 if you have `fcntl`]          )], [], $cares_all_includes)
628AC_CHECK_DECL(getenv,          [AC_DEFINE([HAVE_GETENV],            1, [Define to 1 if you have `getenv`]         )], [], $cares_all_includes)
629AC_CHECK_DECL(gethostname,     [AC_DEFINE([HAVE_GETHOSTNAME],       1, [Define to 1 if you have `gethostname`]    )], [], $cares_all_includes)
630AC_CHECK_DECL(getrandom,       [AC_DEFINE([HAVE_GETRANDOM],         1, [Define to 1 if you have `getrandom`]      )], [], $cares_all_includes)
631AC_CHECK_DECL(getservbyport_r, [AC_DEFINE([HAVE_GETSERVBYPORT_R],   1, [Define to 1 if you have `getservbyport_r`])], [], $cares_all_includes)
632AC_CHECK_DECL(inet_net_pton,   [AC_DEFINE([HAVE_INET_NET_PTON],     1, [Define to 1 if you have `inet_net_pton`]  )], [], $cares_all_includes)
633AC_CHECK_DECL(inet_ntop,       [AC_DEFINE([HAVE_INET_NTOP],         1, [Define to 1 if you have `inet_ntop`]      )], [], $cares_all_includes)
634AC_CHECK_DECL(inet_pton,       [AC_DEFINE([HAVE_INET_PTON],         1, [Define to 1 if you have `inet_pton`]      )], [], $cares_all_includes)
635AC_CHECK_DECL(ioctl,           [AC_DEFINE([HAVE_IOCTL],             1, [Define to 1 if you have `ioctl`]          )], [], $cares_all_includes)
636AC_CHECK_DECL(ioctlsocket,     [AC_DEFINE([HAVE_IOCTLSOCKET],       1, [Define to 1 if you have `ioctlsocket`]    )], [], $cares_all_includes)
637AC_CHECK_DECL(IoctlSocket,     [AC_DEFINE([HAVE_IOCTLSOCKET_CAMEL], 1, [Define to 1 if you have `IoctlSocket`]    )], [], $cares_all_includes)
638AC_CHECK_DECL(setsockopt,      [AC_DEFINE([HAVE_SETSOCKOPT],        1, [Define to 1 if you have `setsockopt`]     )], [], $cares_all_includes)
639AC_CHECK_DECL(socket,          [AC_DEFINE([HAVE_SOCKET],            1, [Define to 1 if you have `socket`]         )], [], $cares_all_includes)
640AC_CHECK_DECL(strcasecmp,      [AC_DEFINE([HAVE_STRCASECMP],        1, [Define to 1 if you have `strcasecmp`]     )], [], $cares_all_includes)
641AC_CHECK_DECL(strdup,          [AC_DEFINE([HAVE_STRDUP],            1, [Define to 1 if you have `strdup`]         )], [], $cares_all_includes)
642AC_CHECK_DECL(stricmp,         [AC_DEFINE([HAVE_STRICMP],           1, [Define to 1 if you have `stricmp`]        )], [], $cares_all_includes)
643AC_CHECK_DECL(strncasecmp,     [AC_DEFINE([HAVE_STRNCASECMP],       1, [Define to 1 if you have `strncasecmp`]    )], [], $cares_all_includes)
644AC_CHECK_DECL(strncmpi,        [AC_DEFINE([HAVE_STRNCMPI],          1, [Define to 1 if you have `strncmpi`]       )], [], $cares_all_includes)
645AC_CHECK_DECL(strnicmp,        [AC_DEFINE([HAVE_STRNICMP],          1, [Define to 1 if you have `strnicmp`]       )], [], $cares_all_includes)
646AC_CHECK_DECL(writev,          [AC_DEFINE([HAVE_WRITEV],            1, [Define to 1 if you have `writev`]         )], [], $cares_all_includes)
647AC_CHECK_DECL(arc4random_buf,  [AC_DEFINE([HAVE_ARC4RANDOM_BUF],    1, [Define to 1 if you have `arc4random_buf`] )], [], $cares_all_includes)
648AC_CHECK_DECL(stat,            [AC_DEFINE([HAVE_STAT],              1, [Define to 1 if you have `stat`]           )], [], $cares_all_includes)
649AC_CHECK_DECL(gettimeofday,    [AC_DEFINE([HAVE_GETTIMEOFDAY],      1, [Define to 1 if you have `gettimeofday`]   )], [], $cares_all_includes)
650AC_CHECK_DECL(clock_gettime,   [AC_DEFINE([HAVE_CLOCK_GETTIME],     1, [Define to 1 if you have `clock_gettime`]  )], [], $cares_all_includes)
651AC_CHECK_DECL(if_indextoname,  [AC_DEFINE([HAVE_IF_INDEXTONAME],    1, [Define to 1 if you have `if_indextoname`] )], [], $cares_all_includes)
652AC_CHECK_DECL(if_nametoindex,  [AC_DEFINE([HAVE_IF_NAMETOINDEX],    1, [Define to 1 if you have `if_nametoindex`] )], [], $cares_all_includes)
653AC_CHECK_DECL(getifaddrs,      [AC_DEFINE([HAVE_GETIFADDRS],        1, [Define to 1 if you have `getifaddrs`]     )], [], $cares_all_includes)
654AC_CHECK_DECL(poll,            [AC_DEFINE([HAVE_POLL],              1, [Define to 1 if you have `poll`]           )], [], $cares_all_includes)
655AC_CHECK_DECL(pipe,            [AC_DEFINE([HAVE_PIPE],              1, [Define to 1 if you have `pipe`]           )], [], $cares_all_includes)
656AC_CHECK_DECL(pipe2,           [AC_DEFINE([HAVE_PIPE2],             1, [Define to 1 if you have `pipe2`]          )], [], $cares_all_includes)
657AC_CHECK_DECL(kqueue,          [AC_DEFINE([HAVE_KQUEUE],            1, [Define to 1 if you have `kqueue`]         )], [], $cares_all_includes)
658AC_CHECK_DECL(epoll_create1,   [AC_DEFINE([HAVE_EPOLL],             1, [Define to 1 if you have `epoll_{create1,ctl,wait}`])], [], $cares_all_includes)
659AC_CHECK_DECL(ConvertInterfaceIndexToLuid, [AC_DEFINE([HAVE_CONVERTINTERFACEINDEXTOLUID], 1, [Define to 1 if you have `ConvertInterfaceIndexToLuid`])], [], $cares_all_includes)
660AC_CHECK_DECL(ConvertInterfaceLuidToNameA, [AC_DEFINE([HAVE_CONVERTINTERFACELUIDTONAMEA], 1, [Define to 1 if you have `ConvertInterfaceLuidToNameA`])], [], $cares_all_includes)
661AC_CHECK_DECL(__system_property_get,       [AC_DEFINE([HAVE___SYSTEM_PROPERTY_GET],       1, [Define to 1 if you have `__system_property_get`]      )], [], $cares_all_includes)
662
663
664dnl ###############################################################################
665dnl recv, recvfrom, send, getnameinfo, gethostname
666dnl ARGUMENTS AND RETURN VALUES
667
668if test "x$ac_cv_type_ssize_t" = "xyes" -a "x$ac_cv_type_socklen_t" = "xyes" -a "x$ac_cv_native_windows" != "xyes" ; then
669  recvfrom_type_retv="ssize_t"
670  recvfrom_type_arg3="size_t"
671else
672  recvfrom_type_retv="int"
673  recvfrom_type_arg3="int"
674fi
675
676if test "x$ac_cv_type_SOCKET" = "xyes" ; then
677  dnl If the SOCKET type is defined, it uses socket ... should be windows only
678  recvfrom_type_arg1="SOCKET"
679else
680  recvfrom_type_arg1="int"
681fi
682
683if test "x$ac_cv_type_socklen_t" = "xyes" ; then
684  recvfrom_type_arg6="socklen_t *"
685  getnameinfo_type_arg2="socklen_t"
686  getnameinfo_type_arg46="socklen_t"
687else
688  recvfrom_type_arg6="int *"
689  getnameinfo_type_arg2="int"
690  getnameinfo_type_arg46="int"
691fi
692
693if test "x$ac_cv_native_windows" = "xyes" ; then
694  recv_type_arg2="char *"
695else
696  recv_type_arg2="void *"
697fi
698
699dnl Functions are typically consistent so the equivalent fields map ... equivalently
700recv_type_retv=${recvfrom_type_retv}
701send_type_retv=${recvfrom_type_retv}
702recv_type_arg1=${recvfrom_type_arg1}
703recvfrom_type_arg2=${recv_type_arg2}
704send_type_arg1=${recvfrom_type_arg1}
705recv_type_arg3=${recvfrom_type_arg3}
706send_type_arg3=${recvfrom_type_arg3}
707gethostname_type_arg2=${recvfrom_type_arg3}
708
709dnl These should always be "sane" values to use always
710recvfrom_qual_arg5=
711recvfrom_type_arg4=int
712recvfrom_type_arg5="struct sockaddr *"
713recv_type_arg4=int
714getnameinfo_type_arg1="struct sockaddr *"
715getnameinfo_type_arg7=int
716send_type_arg2="void *"
717send_type_arg4=int
718
719AC_DEFINE_UNQUOTED([RECVFROM_TYPE_RETV],     [ ${recvfrom_type_retv} ],     [ recvfrom() return value ])
720AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG1],     [ ${recvfrom_type_arg1} ],     [ recvfrom() arg1 type ])
721AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG2],     [ ${recvfrom_type_arg2} ],     [ recvfrom() arg2 type ])
722AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG3],     [ ${recvfrom_type_arg3} ],     [ recvfrom() arg3 type ])
723AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG4],     [ ${recvfrom_type_arg4} ],     [ recvfrom() arg4 type ])
724AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG5],     [ ${recvfrom_type_arg5} ],     [ recvfrom() arg5 type ])
725AC_DEFINE_UNQUOTED([RECVFROM_QUAL_ARG5],     [ ${recvfrom_qual_arg5}],      [ recvfrom() arg5 qualifier])
726
727AC_DEFINE_UNQUOTED([RECV_TYPE_RETV],         [ ${recv_type_retv} ],         [ recv() return value ])
728AC_DEFINE_UNQUOTED([RECV_TYPE_ARG1],         [ ${recv_type_arg1} ],         [ recv() arg1 type ])
729AC_DEFINE_UNQUOTED([RECV_TYPE_ARG2],         [ ${recv_type_arg2} ],         [ recv() arg2 type ])
730AC_DEFINE_UNQUOTED([RECV_TYPE_ARG3],         [ ${recv_type_arg3} ],         [ recv() arg3 type ])
731AC_DEFINE_UNQUOTED([RECV_TYPE_ARG4],         [ ${recv_type_arg4} ],         [ recv() arg4 type ])
732
733AC_DEFINE_UNQUOTED([SEND_TYPE_RETV],         [ ${send_type_retv} ],         [ send() return value ])
734AC_DEFINE_UNQUOTED([SEND_TYPE_ARG1],         [ ${send_type_arg1} ],         [ send() arg1 type ])
735AC_DEFINE_UNQUOTED([SEND_TYPE_ARG2],         [ ${send_type_arg2} ],         [ send() arg2 type ])
736AC_DEFINE_UNQUOTED([SEND_QUAL_ARG2],         [ ],                           [ send() arg2 qualifier ])
737AC_DEFINE_UNQUOTED([SEND_TYPE_ARG3],         [ ${send_type_arg3} ],         [ send() arg3 type ])
738AC_DEFINE_UNQUOTED([SEND_TYPE_ARG4],         [ ${send_type_arg4} ],         [ send() arg4 type ])
739
740AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG1],  [ ${getnameinfo_type_arg1} ],  [ getnameinfo() arg1 type ])
741AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG2],  [ ${getnameinfo_type_arg2} ],  [ getnameinfo() arg2 type ])
742AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG7],  [ ${getnameinfo_type_arg7} ],  [ getnameinfo() arg7 type ])
743AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG46], [ ${getnameinfo_type_arg46} ], [ getnameinfo() arg4 and 6 type ])
744
745AC_DEFINE_UNQUOTED([GETHOSTNAME_TYPE_ARG2],  [ ${gethostname_type_arg2} ],  [ gethostname() arg2 type ])
746dnl ###############################################################################
747
748
749if test "$ac_cv_have_decl_getservbyport_r" = "yes" ; then
750  AC_MSG_CHECKING([number of arguments for getservbyport_r()])
751  getservbyport_r_args=6
752  case $host_os in
753    solaris*)
754      getservbyport_r_args=5
755    ;;
756    aix*|openbsd*)
757      getservbyport_r_args=4
758    ;;
759  esac
760  AC_MSG_RESULT([$getservbyport_r_args])
761  AC_DEFINE_UNQUOTED([GETSERVBYPORT_R_ARGS], [ $getservbyport_r_args ], [ number of arguments for getservbyport_r() ])
762fi
763
764if test "$ac_cv_have_decl_getservbyname_r" = "yes" ; then
765  AC_MSG_CHECKING([number of arguments for getservbyname_r()])
766  getservbyname_r_args=6
767  case $host_os in
768    solaris*)
769      getservbyname_r_args=5
770    ;;
771    aix*|openbsd*)
772      getservbyname_r_args=4
773    ;;
774  esac
775  AC_DEFINE_UNQUOTED([GETSERVBYNAME_R_ARGS], [ $getservbyname_r_args ], [ number of arguments for getservbyname_r() ])
776  AC_MSG_RESULT([$getservbyname_r_args])
777fi
778
779AC_TYPE_SIZE_T
780AC_CHECK_DECL(AF_INET6, [AC_DEFINE([HAVE_AF_INET6],1,[Define to 1 if you have AF_INET6])], [], $cares_all_includes)
781AC_CHECK_DECL(PF_INET6, [AC_DEFINE([HAVE_PF_INET6],1,[Define to 1 if you have PF_INET6])], [], $cares_all_includes)
782AC_CHECK_TYPES(struct in6_addr, [], [], $cares_all_includes)
783AC_CHECK_TYPES(struct sockaddr_in6, [], [], $cares_all_includes)
784AC_CHECK_TYPES(struct sockaddr_storage, [], [], $cares_all_includes)
785AC_CHECK_TYPES(struct addrinfo, [], [], $cares_all_includes)
786AC_CHECK_TYPES(struct timeval, [], [], $cares_all_includes)
787AC_CHECK_MEMBERS(struct sockaddr_in6.sin6_scope_id, [], [], $cares_all_includes)
788AC_CHECK_MEMBERS(struct addrinfo.ai_flags, [], [], $cares_all_includes)
789AC_CHECK_DECL(FIONBIO, [], [], $cares_all_includes)
790AC_CHECK_DECL(O_NONBLOCK, [], [], $cares_all_includes)
791AC_CHECK_DECL(SO_NONBLOCK, [], [], $cares_all_includes)
792AC_CHECK_DECL(MSG_NOSIGNAL, [], [], $cares_all_includes)
793AC_CHECK_DECL(CLOCK_MONOTONIC, [], [], $cares_all_includes)
794
795if test "$ac_cv_have_decl_CLOCK_MONOTONIC" = "yes" -a "$ac_cv_have_decl_clock_gettime" = "yes" ; then
796  AC_DEFINE([HAVE_CLOCK_GETTIME_MONOTONIC], [ 1 ], [ clock_gettime() with CLOCK_MONOTONIC support ])
797fi
798
799if test "$ac_cv_have_decl_FIONBIO" = "yes" -a "$ac_cv_have_decl_ioctl" = "yes" ; then
800  AC_DEFINE([HAVE_IOCTL_FIONBIO], [ 1 ], [ ioctl() with FIONBIO support ])
801fi
802if test "$ac_cv_have_decl_FIONBIO" = "yes" -a "$ac_cv_have_decl_ioctlsocket" = "yes" ; then
803  AC_DEFINE([HAVE_IOCTLSOCKET_FIONBIO], [ 1 ], [ ioctlsocket() with FIONBIO support ])
804fi
805if test "$ac_cv_have_decl_SO_NONBLOCK" = "yes" -a "$ac_cv_have_decl_setsockopt" = "yes" ; then
806  AC_DEFINE([HAVE_SETSOCKOPT_SO_NONBLOCK], [ 1 ], [ setsockopt() with SO_NONBLOCK support ])
807fi
808if test "$ac_cv_have_decl_O_NONBLOCK" = "yes" -a "$ac_cv_have_decl_fcntl" = "yes" ; then
809  AC_DEFINE([HAVE_FCNTL_O_NONBLOCK], [ 1 ], [ fcntl() with O_NONBLOCK support ])
810fi
811
812dnl ares_build.h.in specific defines
813if test "x$ac_cv_header_sys_types_h" = "xyes" ; then
814  CARES_DEFINE_UNQUOTED([CARES_HAVE_SYS_TYPES_H],[1])
815fi
816if test "x$ac_cv_header_sys_socket_h" = "xyes" ; then
817  CARES_DEFINE_UNQUOTED([CARES_HAVE_SYS_SOCKET_H],[1])
818fi
819if test "x$ac_cv_header_ws2tcpip_h" = "xyes" ; then
820  CARES_DEFINE_UNQUOTED([CARES_HAVE_WS2TCPIP_H],[1])
821fi
822if test "x$ac_cv_header_winsock2_h" = "xyes" ; then
823  CARES_DEFINE_UNQUOTED([CARES_HAVE_WINSOCK2_H],[1])
824fi
825if test "x$ac_cv_header_windows_h" = "xyes" ; then
826  CARES_DEFINE_UNQUOTED([CARES_HAVE_WINDOWS_H],[1])
827fi
828if test "x$ac_cv_header_arpa_nameser_h" = "xyes" ; then
829  CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_H],[1])
830fi
831if test "x$ac_cv_header_arpa_nameser_compa_h" = "xyes" ; then
832  CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_COMPA_H],[1])
833fi
834
835
836dnl ------------ THREADING --------------
837
838dnl windows always supports threads, only check non-windows systems.
839if test "${CARES_THREADS}" = "yes" -a "x${ac_cv_native_windows}" != "xyes" ; then
840  AX_PTHREAD([ ], [
841    AC_MSG_WARN([threads requested but not supported])
842    CARES_THREADS=no
843  ])
844
845  if test "${CARES_THREADS}" = "yes" ; then
846    AC_CHECK_HEADERS([pthread.h pthread_np.h])
847    LIBS="$PTHREAD_LIBS $LIBS"
848    AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS"
849    CC="$PTHREAD_CC"
850    CXX="$PTHREAD_CXX"
851  fi
852fi
853
854if test "${CARES_THREADS}" = "yes" ; then
855  AC_DEFINE([CARES_THREADS], [ 1 ], [Threading enabled])
856fi
857
858CARES_PRIVATE_LIBS="$LIBS"
859AC_SUBST(CARES_PRIVATE_LIBS)
860
861BUILD_SUBDIRS="include src docs"
862
863
864dnl ******** TESTS *******
865
866if test "x$build_tests" != "xno" -a "x$HAVE_CXX14" = "0" ; then
867  if test "x$build_tests" = "xmaybe" ; then
868    AC_MSG_WARN([cannot build tests without a CXX14 compiler])
869    build_tests=no
870  else
871    AC_MSG_ERROR([*** Building tests requires a CXX14 compiler])
872  fi
873fi
874if test "x$build_tests" != "xno" -a "x$cross_compiling" = "xyes" ; then
875  if test "x$build_tests" = "xmaybe" ; then
876    AC_MSG_WARN([cannot build tests when cross compiling])
877    build_tests=no
878  else
879    AC_MSG_ERROR([*** Tests not supported when cross compiling])
880  fi
881fi
882if test "x$build_tests" != "xno" ; then
883  PKG_CHECK_MODULES([GMOCK], [gmock], [ have_gmock=yes ], [ have_gmock=no ])
884  if test "x$have_gmock" = "xno" ; then
885    if test "x$build_tests" = "xmaybe" ; then
886      AC_MSG_WARN([gmock could not be found, not building tests])
887      build_tests=no
888    else
889      AC_MSG_ERROR([tests require gmock])
890    fi
891  fi
892fi
893if test "x$build_tests" != "xno" ; then
894  build_tests=yes
895
896  AX_CXX_COMPILE_STDCXX_14([noext],[mandatory])
897  if test "$ac_cv_native_windows" != "yes" ; then
898    AX_PTHREAD([ CARES_TEST_PTHREADS="yes" ], [ AC_MSG_ERROR([threading required for tests]) ])
899  fi
900
901  BUILD_SUBDIRS="${BUILD_SUBDIRS} test"
902fi
903AC_MSG_CHECKING([whether to build tests])
904AC_MSG_RESULT([$build_tests])
905
906AM_CONDITIONAL(BUILD_TESTS, test "x$build_tests" = "xyes")
907
908AC_SUBST(AM_CFLAGS)
909AC_SUBST(AM_CPPFLAGS)
910AC_SUBST(PKGCONFIG_CFLAGS)
911AC_SUBST(BUILD_SUBDIRS)
912
913AC_CONFIG_FILES([Makefile           \
914                 include/Makefile   \
915                 src/Makefile       \
916                 src/lib/Makefile   \
917                 src/tools/Makefile \
918                 docs/Makefile      \
919                 libcares.pc ])
920AM_COND_IF([BUILD_TESTS],
921           [AC_CONFIG_FILES([test/Makefile])])
922
923AC_OUTPUT
924