• 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.34.5],
6  [c-ares mailing list: http://lists.haxx.se/listinfo/c-ares])
7
8CARES_VERSION_INFO="21:4:19"
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
156AC_SYS_LARGEFILE
157
158case $host_os in
159  solaris*)
160    AC_DEFINE(ETC_INET, 1, [if a /etc/inet dir is being used])
161    ;;
162esac
163
164dnl solaris needed flag
165case $host_os in
166  solaris2*)
167    if test "x$GCC" = 'xyes'; then
168      AX_APPEND_LINK_FLAGS([-mimpure-text])
169    fi
170    ;;
171  *)
172    ;;
173esac
174
175dnl -no-undefined libtool (not linker) flag for windows
176cares_use_no_undefined=no
177case $host_os in
178  cygwin* | mingw* | pw32* | cegcc* | os2* | aix*)
179    cares_use_no_undefined=yes
180    ;;
181  *)
182    ;;
183esac
184AM_CONDITIONAL([CARES_USE_NO_UNDEFINED], [test "$cares_use_no_undefined" = 'yes'])
185
186
187if test "$ac_cv_native_windows" = "yes" ; then
188  AM_CPPFLAGS="$AM_CPPFLAGS -D_WIN32_WINNT=0x0602 -DWIN32_LEAN_AND_MEAN"
189fi
190
191dnl Windows can only build shared or static, not both at the same time
192if test "$ac_cv_native_windows" = "yes" -a "x$enable_shared" = "xyes" -a "x$enable_static" = "xyes" ; then
193  AC_MSG_ERROR([Windows cannot build both static and shared simultaneously, specify --disable-shared or --disable-static])
194fi
195
196dnl Only windows requires CARES_STATICLIB definition
197if test "x$enable_shared" = "xno" -a "x$enable_static" = "xyes" ; then
198  AC_MSG_CHECKING([whether we need CARES_STATICLIB definition])
199  if test "$ac_cv_native_windows" = "yes" ; then
200    AX_APPEND_FLAG([-DCARES_STATICLIB], [AM_CPPFLAGS])
201    PKGCONFIG_CFLAGS="-DCARES_STATICLIB"
202    AC_MSG_RESULT([yes])
203  else
204    AC_MSG_RESULT([no])
205  fi
206fi
207
208dnl Test for symbol hiding
209CARES_SYMBOL_HIDING_CFLAG=""
210if test "$symbol_hiding" != "no" ; then
211  compiler_supports_symbol_hiding="no"
212  if test "$ac_cv_windows" = "yes" ; then
213    compiler_supports_symbol_hiding="yes"
214  else
215    case "$ax_cv_c_compiler_vendor" in
216      clang|gnu|intel)
217        AX_APPEND_COMPILE_FLAGS([-fvisibility=hidden], [CARES_SYMBOL_HIDING_CFLAG])
218        if test "x$CARES_SYMBOL_HIDING_CFLAG" != "x" ; then
219          compiler_supports_symbol_hiding="yes"
220        fi
221        ;;
222      sun)
223        AX_APPEND_COMPILE_FLAGS([-xldscope=hidden], [CARES_SYMBOL_HIDING_CFLAG])
224        if test "x$CARES_SYMBOL_HIDING_CFLAG" != "x" ; then
225          compiler_supports_symbol_hiding="yes"
226        fi
227        ;;
228    esac
229  fi
230  if test "$compiler_supports_symbol_hiding" = "no" ; then
231    if test "$symbol_hiding" = "yes" ; then
232      AC_MSG_ERROR([Compiler does not support symbol hiding])
233    else
234      symbol_hiding="no"
235    fi
236  else
237    AC_DEFINE([CARES_SYMBOL_HIDING], [ 1 ], [Set to 1 if non-pubilc shared library symbols are hidden])
238    symbol_hiding="yes"
239  fi
240fi
241AM_CONDITIONAL(CARES_SYMBOL_HIDING, test "x$symbol_hiding" = "xyes")
242AC_SUBST(CARES_SYMBOL_HIDING_CFLAG)
243
244
245if test "$enable_warnings" = "yes"; then
246  AX_APPEND_COMPILE_FLAGS([-Wall -Wextra -Waggregate-return -Wcast-align -Wcast-qual -Wconversion -Wdeclaration-after-statement -Wdouble-promotion -Wfloat-equal -Wformat-security -Winit-self -Wjump-misses-init -Wlogical-op -Wmissing-braces -Wmissing-declarations -Wmissing-format-attribute -Wmissing-include-dirs -Wmissing-prototypes -Wnested-externs -Wno-coverage-mismatch -Wold-style-definition -Wpacked -Wpedantic -Wpointer-arith -Wredundant-decls -Wshadow -Wsign-conversion -Wstrict-overflow -Wstrict-prototypes -Wtrampolines -Wundef -Wunreachable-code -Wunused -Wvariadic-macros -Wvla -Wwrite-strings -Werror=implicit-int -Werror=implicit-function-declaration -Werror=partial-availability -Wno-long-long ],
247    [AM_CFLAGS], [-Werror])
248fi
249
250dnl Android and QNX require c99, all others should use c90
251case $host_os in
252  *qnx*|*android*)
253    AX_APPEND_COMPILE_FLAGS([-std=c99], [AM_CFLAGS], [-Werror])
254    ;;
255  *)
256    AX_APPEND_COMPILE_FLAGS([-std=c90], [AM_CFLAGS], [-Werror])
257    ;;
258esac
259
260dnl QNX needs -D_QNX_SOURCE
261case $host_os in
262  *qnx*)
263    AX_APPEND_COMPILE_FLAGS([-D_QNX_SOURCE], [AM_CPPFLAGS], [-Werror])
264  ;;
265esac
266
267if test "$ax_cv_c_compiler_vendor" = "intel"; then
268  AX_APPEND_COMPILE_FLAGS([-shared-intel], [AM_CFLAGS])
269fi
270
271if test "$ac_cv_native_windows" = "yes" ; then
272  dnl we use [ - ] in the 4th argument to tell AC_CHECK_HEADERS to simply
273  dnl check for existence of the headers, not usability.  This is because
274  dnl on windows, header order matters, and you need to include headers *after*
275  dnl other headers, AC_CHECK_HEADERS only allows you to specify headers that
276  dnl must be included *before* the header being checked.
277
278  AC_CHECK_HEADERS([windows.h winsock2.h ws2tcpip.h iphlpapi.h netioapi.h ws2ipdef.h winternl.h ntdef.h ntstatus.h mswsock.h ],
279    [], [], [-])
280
281  dnl Windows builds require linking to iphlpapi
282  if test "$ac_cv_header_winsock2_h" = "yes"; then
283    LIBS="$LIBS -lws2_32 -liphlpapi"
284  fi
285fi
286
287dnl **********************************************************************
288dnl Checks for libraries.
289dnl **********************************************************************
290
291dnl see if libnsl or libsocket are required
292AC_SEARCH_LIBS([getservbyport], [nsl socket resolv])
293
294AC_MSG_CHECKING([if libxnet is required])
295need_xnet=no
296case $host_os in
297  hpux*)
298    XNET_LIBS=""
299    AX_APPEND_LINK_FLAGS([-lxnet], [XNET_LIBS])
300    if test "x$XNET_LIBS" != "x" ; then
301      LIBS="$LIBS $XNET_LIBS"
302      need_xnet=yes
303    fi
304    ;;
305esac
306AC_MSG_RESULT($need_xnet)
307
308dnl resolv lib for z/OS
309AS_IF([test "x$host_vendor" = "xibm" -a "x$host_os" = "xopenedition" ], [
310  AC_SEARCH_LIBS([res_init], [resolv], [
311    AC_DEFINE([CARES_USE_LIBRESOLV], [1], [Use resolver library to configure cares])
312  ], [
313    AC_MSG_ERROR([Unable to find libresolv which is required for z/OS])
314  ])
315])
316
317
318dnl iOS 10?
319AS_IF([test "x$host_vendor" = "xapple"], [
320  AC_MSG_CHECKING([for iOS minimum version 10 or later])
321  AC_COMPILE_IFELSE([
322    AC_LANG_PROGRAM([[
323#include <stdio.h>
324#include <AvailabilityMacros.h>
325#include <TargetConditionals.h>
326    ]], [[
327#if TARGET_OS_IPHONE == 0 || __IPHONE_OS_VERSION_MIN_REQUIRED < 100000
328#error Not iOS 10 or later
329#endif
330return 0;
331   ]])
332  ],[
333    AC_MSG_RESULT([yes])
334    ac_cv_ios_10="yes"
335  ],[
336    AC_MSG_RESULT([no])
337  ])
338])
339
340dnl macOS 10.12?
341AS_IF([test "x$host_vendor" = "xapple"], [
342  AC_MSG_CHECKING([for macOS minimum version 10.12 or later])
343  AC_COMPILE_IFELSE([
344    AC_LANG_PROGRAM([[
345#include <stdio.h>
346#include <AvailabilityMacros.h>
347#include <TargetConditionals.h>
348    ]], [[
349#ifndef MAC_OS_X_VERSION_10_12
350#  define MAC_OS_X_VERSION_10_12 101200
351#endif
352#if MAC_OS_X_VERSION_MIN_REQUIRED < MAC_OS_X_VERSION_10_12
353#error Not macOS 10.12 or later
354#endif
355return 0;
356   ]])
357  ],[
358    AC_MSG_RESULT([yes])
359    ac_cv_macos_10_12="yes"
360  ],[
361    AC_MSG_RESULT([no])
362  ])
363])
364
365AC_MSG_CHECKING([whether to use libgcc])
366AC_ARG_ENABLE(libgcc,
367AS_HELP_STRING([--enable-libgcc],[use libgcc when linking]),
368[ case "$enableval" in
369  yes)
370    LIBS="$LIBS -lgcc"
371    AC_MSG_RESULT(yes)
372    ;;
373  *)
374    AC_MSG_RESULT(no)
375    ;;
376  esac ],
377       AC_MSG_RESULT(no)
378)
379
380dnl check for a few basic system headers we need.  It would be nice if we could
381dnl split these on separate lines, but for some reason autotools on Windows doesn't
382dnl allow this, even tried ending lines with a backslash.
383AC_CHECK_HEADERS([malloc.h memory.h AvailabilityMacros.h sys/types.h sys/time.h sys/select.h sys/socket.h sys/filio.h sys/ioctl.h sys/param.h sys/uio.h sys/random.h sys/event.h sys/epoll.h assert.h iphlpapi.h netioapi.h netdb.h netinet/in.h netinet6/in6.h netinet/tcp.h net/if.h ifaddrs.h fcntl.h errno.h socket.h strings.h stdbool.h time.h poll.h limits.h arpa/nameser.h arpa/nameser_compat.h arpa/inet.h sys/system_properties.h ],
384dnl to do if not found
385[],
386dnl to do if found
387[],
388dnl default includes
389[
390#ifdef HAVE_SYS_TYPES_H
391#include <sys/types.h>
392#endif
393#ifdef HAVE_SYS_TIME_H
394#include <sys/time.h>
395#endif
396dnl We do this default-include simply to make sure that the nameser_compat.h
397dnl header *REALLY* can be include after the new nameser.h. It seems AIX 5.1
398dnl (and others?) is not designed to allow this.
399#ifdef HAVE_ARPA_NAMESER_H
400#include <arpa/nameser.h>
401#endif
402
403dnl *Sigh* these are needed in order for net/if.h to get properly detected.
404#ifdef HAVE_SYS_SOCKET_H
405#include <sys/socket.h>
406#endif
407#ifdef HAVE_NETINET_IN_H
408#include <netinet/in.h>
409#endif
410]
411)
412
413
414cares_all_includes="
415#include <stdio.h>
416#include <stdlib.h>
417#ifdef HAVE_AVAILABILITYMACROS_H
418#  include <AvailabilityMacros.h>
419#endif
420#ifdef HAVE_SYS_UIO_H
421#  include <sys/uio.h>
422#endif
423#ifdef HAVE_NETINET_IN_H
424#  include <netinet/in.h>
425#endif
426#ifdef HAVE_TCP_H
427#  include <tcp.h>
428#endif
429#ifdef HAVE_SYS_FILIO_H
430#  include <sys/filio.h>
431#endif
432#ifdef HAVE_SYS_IOCTL_H
433#  include <sys/ioctl.h>
434#endif
435#ifdef HAVE_UNISTD_H
436#  include <unistd.h>
437#endif
438#ifdef HAVE_STRING_H
439#  include <string.h>
440#endif
441#ifdef HAVE_STRINGS_H
442#  include <strings.h>
443#endif
444#ifdef HAVE_TIME_H
445#  include <time.h>
446#endif
447#ifdef HAVE_SYS_TIME_H
448#  include <sys/time.h>
449#endif
450#ifdef HAVE_SYS_TYPES_H
451#  include <sys/types.h>
452#endif
453#ifdef HAVE_SYS_STAT_H
454#  include <sys/stat.h>
455#endif
456#ifdef HAVE_SYS_RANDOM_H
457#  include <sys/random.h>
458#endif
459#ifdef HAVE_SYS_EVENT_H
460#  include <sys/event.h>
461#endif
462#ifdef HAVE_SYS_EPOLL_H
463#  include <sys/epoll.h>
464#endif
465#ifdef HAVE_SYS_SOCKET_H
466#  include <sys/socket.h>
467#endif
468#ifdef HAVE_SYS_PARAM_H
469#  include <sys/param.h>
470#endif
471#ifdef HAVE_FCNTL_H
472#  include <fcntl.h>
473#endif
474#ifdef HAVE_POLL_H
475#  include <poll.h>
476#endif
477#ifdef HAVE_NET_IF_H
478#  include <net/if.h>
479#endif
480#ifdef HAVE_IFADDRS_H
481#  include <ifaddrs.h>
482#endif
483#ifdef HAVE_NETINET_IN_H
484#  include <netinet/in.h>
485#endif
486#ifdef HAVE_NETINET_TCP_H
487#  include <netinet/tcp.h>
488#endif
489#ifdef HAVE_NETDB_H
490#  include <netdb.h>
491#endif
492#ifdef HAVE_ARPA_INET_H
493#  include <arpa/inet.h>
494#endif
495#ifdef HAVE_RESOLV_H
496#  include <resolv.h>
497#endif
498#ifdef HAVE_SYS_SYSTEM_PROPERTIES_H
499#  include <sys/system_properties.h>
500#endif
501#ifdef HAVE_IPHLPAPI_H
502#  include <iphlpapi.h>
503#endif
504#ifdef HAVE_NETIOAPI_H
505#  include <netioapi.h>
506#endif
507#ifdef HAVE_WINSOCK2_H
508#  include <winsock2.h>
509#endif
510#ifdef HAVE_WS2IPDEF_H
511#  include <ws2ipdef.h>
512#endif
513#ifdef HAVE_WS2TCPIP_H
514#  include <ws2tcpip.h>
515#endif
516#ifdef HAVE_WINDOWS_H
517#  include <windows.h>
518#endif
519"
520
521AC_CHECK_DECL([HAVE_ARPA_NAMESER_H],[CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_H])], [])
522AC_CHECK_DECL([HAVE_ARPA_NAMESER_COMPAT_H],[CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_COMPAT_H])],[])
523AC_CHECK_TYPE(long long, [AC_DEFINE(HAVE_LONGLONG, 1, [Define to 1 if the compiler supports the 'long long' data type.])])
524AC_CHECK_TYPE(ssize_t, [ CARES_TYPEOF_ARES_SSIZE_T=ssize_t ], [ CARES_TYPEOF_ARES_SSIZE_T=int ])
525AC_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SSIZE_T], ${CARES_TYPEOF_ARES_SSIZE_T}, [the signed version of size_t])
526
527AC_CHECK_TYPE(socklen_t,
528  [
529    AC_DEFINE(HAVE_SOCKLEN_T, [], [socklen_t])
530    CARES_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SOCKLEN_T], [socklen_t])
531  ],
532  [ CARES_DEFINE_UNQUOTED([CARES_TYPEOF_ARES_SOCKLEN_T], [int]) ],
533  $cares_all_includes
534 )
535
536AC_CHECK_TYPE(SOCKET, [], [], $cares_all_includes)
537
538dnl ###############################################################################
539
540dnl clock_gettime might require an external library
541AC_SEARCH_LIBS([clock_gettime], [rt posix4])
542
543dnl Use AC_CHECK_DECL not AC_CHECK_FUNCS, while this doesn't do a linkage test,
544dnl it just makes sure the headers define it, this is the only thing without
545dnl a complex workaround on Windows that will do what we need. See:
546dnl https://github.com/msys2/msys2/wiki/Porting/f87a222118b1008ebc166ad237f04edb759c8f4c#calling-conventions-stdcall-and-autotools
547dnl https://lists.gnu.org/archive/html/autoconf/2013-05/msg00085.html
548dnl and for a more complex workaround, we'd need to use AC_LINK_IFELSE like:
549dnl https://mailman.videolan.org/pipermail/vlc-devel/2015-March/101802.html
550dnl which would require we check each individually and provide function arguments
551dnl for the test.
552
553AC_CHECK_DECL(strnlen,         [AC_DEFINE([HAVE_STRNLEN],           1, [Define to 1 if you have `strnlen`]        )], [], $cares_all_includes)
554AC_CHECK_DECL(memmem,          [AC_DEFINE([HAVE_MEMMEM],            1, [Define to 1 if you have `memmem`]         )], [], $cares_all_includes)
555AC_CHECK_DECL(recv,            [AC_DEFINE([HAVE_RECV],              1, [Define to 1 if you have `recv`]           )], [], $cares_all_includes)
556AC_CHECK_DECL(recvfrom,        [AC_DEFINE([HAVE_RECVFROM],          1, [Define to 1 if you have `recvfrom`]       )], [], $cares_all_includes)
557AC_CHECK_DECL(send,            [AC_DEFINE([HAVE_SEND],              1, [Define to 1 if you have `send`]           )], [], $cares_all_includes)
558AC_CHECK_DECL(sendto,          [AC_DEFINE([HAVE_SENDTO],            1, [Define to 1 if you have `sendto`]         )], [], $cares_all_includes)
559AC_CHECK_DECL(getnameinfo,     [AC_DEFINE([HAVE_GETNAMEINFO],       1, [Define to 1 if you have `getnameinfo`]    )], [], $cares_all_includes)
560AC_CHECK_DECL(gethostname,     [AC_DEFINE([HAVE_GETHOSTNAME],       1, [Define to 1 if you have `gethostname`]    )], [], $cares_all_includes)
561AC_CHECK_DECL(connect,         [AC_DEFINE([HAVE_CONNECT],           1, [Define to 1 if you have `connect`]        )], [], $cares_all_includes)
562AC_CHECK_DECL(connectx,        [AC_DEFINE([HAVE_CONNECTX],          1, [Define to 1 if you have `connectx`]       )], [], $cares_all_includes)
563AC_CHECK_DECL(closesocket,     [AC_DEFINE([HAVE_CLOSESOCKET],       1, [Define to 1 if you have `closesocket`]    )], [], $cares_all_includes)
564AC_CHECK_DECL(CloseSocket,     [AC_DEFINE([HAVE_CLOSESOCKET_CAMEL], 1, [Define to 1 if you have `CloseSocket`]    )], [], $cares_all_includes)
565AC_CHECK_DECL(fcntl,           [AC_DEFINE([HAVE_FCNTL],             1, [Define to 1 if you have `fcntl`]          )], [], $cares_all_includes)
566AC_CHECK_DECL(getenv,          [AC_DEFINE([HAVE_GETENV],            1, [Define to 1 if you have `getenv`]         )], [], $cares_all_includes)
567AC_CHECK_DECL(gethostname,     [AC_DEFINE([HAVE_GETHOSTNAME],       1, [Define to 1 if you have `gethostname`]    )], [], $cares_all_includes)
568AC_CHECK_DECL(getrandom,       [AC_DEFINE([HAVE_GETRANDOM],         1, [Define to 1 if you have `getrandom`]      )], [], $cares_all_includes)
569AC_CHECK_DECL(getservbyport_r, [AC_DEFINE([HAVE_GETSERVBYPORT_R],   1, [Define to 1 if you have `getservbyport_r`])], [], $cares_all_includes)
570AC_CHECK_DECL(inet_net_pton,   [AC_DEFINE([HAVE_INET_NET_PTON],     1, [Define to 1 if you have `inet_net_pton`]  )], [], $cares_all_includes)
571AC_CHECK_DECL(inet_ntop,       [AC_DEFINE([HAVE_INET_NTOP],         1, [Define to 1 if you have `inet_ntop`]      )], [], $cares_all_includes)
572AC_CHECK_DECL(inet_pton,       [AC_DEFINE([HAVE_INET_PTON],         1, [Define to 1 if you have `inet_pton`]      )], [], $cares_all_includes)
573AC_CHECK_DECL(ioctl,           [AC_DEFINE([HAVE_IOCTL],             1, [Define to 1 if you have `ioctl`]          )], [], $cares_all_includes)
574AC_CHECK_DECL(ioctlsocket,     [AC_DEFINE([HAVE_IOCTLSOCKET],       1, [Define to 1 if you have `ioctlsocket`]    )], [], $cares_all_includes)
575AC_CHECK_DECL(IoctlSocket,     [AC_DEFINE([HAVE_IOCTLSOCKET_CAMEL], 1, [Define to 1 if you have `IoctlSocket`]    )], [], $cares_all_includes)
576AC_CHECK_DECL(setsockopt,      [AC_DEFINE([HAVE_SETSOCKOPT],        1, [Define to 1 if you have `setsockopt`]     )], [], $cares_all_includes)
577AC_CHECK_DECL(socket,          [AC_DEFINE([HAVE_SOCKET],            1, [Define to 1 if you have `socket`]         )], [], $cares_all_includes)
578AC_CHECK_DECL(strcasecmp,      [AC_DEFINE([HAVE_STRCASECMP],        1, [Define to 1 if you have `strcasecmp`]     )], [], $cares_all_includes)
579AC_CHECK_DECL(strdup,          [AC_DEFINE([HAVE_STRDUP],            1, [Define to 1 if you have `strdup`]         )], [], $cares_all_includes)
580AC_CHECK_DECL(stricmp,         [AC_DEFINE([HAVE_STRICMP],           1, [Define to 1 if you have `stricmp`]        )], [], $cares_all_includes)
581AC_CHECK_DECL(strncasecmp,     [AC_DEFINE([HAVE_STRNCASECMP],       1, [Define to 1 if you have `strncasecmp`]    )], [], $cares_all_includes)
582AC_CHECK_DECL(strncmpi,        [AC_DEFINE([HAVE_STRNCMPI],          1, [Define to 1 if you have `strncmpi`]       )], [], $cares_all_includes)
583AC_CHECK_DECL(strnicmp,        [AC_DEFINE([HAVE_STRNICMP],          1, [Define to 1 if you have `strnicmp`]       )], [], $cares_all_includes)
584AC_CHECK_DECL(writev,          [AC_DEFINE([HAVE_WRITEV],            1, [Define to 1 if you have `writev`]         )], [], $cares_all_includes)
585AC_CHECK_DECL(arc4random_buf,  [AC_DEFINE([HAVE_ARC4RANDOM_BUF],    1, [Define to 1 if you have `arc4random_buf`] )], [], $cares_all_includes)
586AC_CHECK_DECL(stat,            [AC_DEFINE([HAVE_STAT],              1, [Define to 1 if you have `stat`]           )], [], $cares_all_includes)
587AC_CHECK_DECL(gettimeofday,    [AC_DEFINE([HAVE_GETTIMEOFDAY],      1, [Define to 1 if you have `gettimeofday`]   )], [], $cares_all_includes)
588AC_CHECK_DECL(clock_gettime,   [AC_DEFINE([HAVE_CLOCK_GETTIME],     1, [Define to 1 if you have `clock_gettime`]  )], [], $cares_all_includes)
589AC_CHECK_DECL(if_indextoname,  [AC_DEFINE([HAVE_IF_INDEXTONAME],    1, [Define to 1 if you have `if_indextoname`] )], [], $cares_all_includes)
590AC_CHECK_DECL(if_nametoindex,  [AC_DEFINE([HAVE_IF_NAMETOINDEX],    1, [Define to 1 if you have `if_nametoindex`] )], [], $cares_all_includes)
591AC_CHECK_DECL(getifaddrs,      [AC_DEFINE([HAVE_GETIFADDRS],        1, [Define to 1 if you have `getifaddrs`]     )], [], $cares_all_includes)
592AC_CHECK_DECL(poll,            [AC_DEFINE([HAVE_POLL],              1, [Define to 1 if you have `poll`]           )], [], $cares_all_includes)
593AC_CHECK_DECL(pipe,            [AC_DEFINE([HAVE_PIPE],              1, [Define to 1 if you have `pipe`]           )], [], $cares_all_includes)
594AC_CHECK_DECL(pipe2,           [AC_DEFINE([HAVE_PIPE2],             1, [Define to 1 if you have `pipe2`]          )], [], $cares_all_includes)
595AC_CHECK_DECL(kqueue,          [AC_DEFINE([HAVE_KQUEUE],            1, [Define to 1 if you have `kqueue`]         )], [], $cares_all_includes)
596AC_CHECK_DECL(epoll_create1,   [AC_DEFINE([HAVE_EPOLL],             1, [Define to 1 if you have `epoll_{create1,ctl,wait}`])], [], $cares_all_includes)
597AC_CHECK_DECL(GetBestRoute2,   [AC_DEFINE([HAVE_GETBESTROUTE2],     1, [Define to 1 if you have `GetBestRoute2`]  )], [], $cares_all_includes)
598AC_CHECK_DECL(ConvertInterfaceIndexToLuid, [AC_DEFINE([HAVE_CONVERTINTERFACEINDEXTOLUID], 1, [Define to 1 if you have `ConvertInterfaceIndexToLuid`])], [], $cares_all_includes)
599AC_CHECK_DECL(ConvertInterfaceLuidToNameA, [AC_DEFINE([HAVE_CONVERTINTERFACELUIDTONAMEA], 1, [Define to 1 if you have `ConvertInterfaceLuidToNameA`])], [], $cares_all_includes)
600AC_CHECK_DECL(NotifyIpInterfaceChange,     [AC_DEFINE([HAVE_NOTIFYIPINTERFACECHANGE],     1, [Define to 1 if you have `NotifyIpInterfaceChange`]    )], [], $cares_all_includes)
601AC_CHECK_DECL(RegisterWaitForSingleObject, [AC_DEFINE([HAVE_REGISTERWAITFORSINGLEOBJECT], 1, [Define to 1 if you have `RegisterWaitForSingleObject`])], [], $cares_all_includes)
602AC_CHECK_DECL(__system_property_get,       [AC_DEFINE([HAVE___SYSTEM_PROPERTY_GET],       1, [Define to 1 if you have `__system_property_get`]      )], [], $cares_all_includes)
603
604
605dnl ###############################################################################
606dnl recv, recvfrom, send, getnameinfo, gethostname
607dnl ARGUMENTS AND RETURN VALUES
608
609if test "x$ac_cv_type_ssize_t" = "xyes" -a "x$ac_cv_type_socklen_t" = "xyes" -a "x$ac_cv_native_windows" != "xyes" ; then
610  recvfrom_type_retv="ssize_t"
611  recvfrom_type_arg3="size_t"
612else
613  recvfrom_type_retv="int"
614  recvfrom_type_arg3="int"
615fi
616
617if test "x$ac_cv_type_SOCKET" = "xyes" ; then
618  dnl If the SOCKET type is defined, it uses socket ... should be windows only
619  recvfrom_type_arg1="SOCKET"
620else
621  recvfrom_type_arg1="int"
622fi
623
624if test "x$ac_cv_type_socklen_t" = "xyes" ; then
625  recvfrom_type_arg6="socklen_t *"
626  getnameinfo_type_arg2="socklen_t"
627  getnameinfo_type_arg46="socklen_t"
628else
629  recvfrom_type_arg6="int *"
630  getnameinfo_type_arg2="int"
631  getnameinfo_type_arg46="int"
632fi
633
634if test "x$ac_cv_native_windows" = "xyes" ; then
635  recv_type_arg2="char *"
636else
637  recv_type_arg2="void *"
638fi
639
640dnl Functions are typically consistent so the equivalent fields map ... equivalently
641recv_type_retv=${recvfrom_type_retv}
642send_type_retv=${recvfrom_type_retv}
643recv_type_arg1=${recvfrom_type_arg1}
644recvfrom_type_arg2=${recv_type_arg2}
645send_type_arg1=${recvfrom_type_arg1}
646recv_type_arg3=${recvfrom_type_arg3}
647send_type_arg3=${recvfrom_type_arg3}
648gethostname_type_arg2=${recvfrom_type_arg3}
649
650dnl These should always be "sane" values to use always
651recvfrom_qual_arg5=
652recvfrom_type_arg4=int
653recvfrom_type_arg5="struct sockaddr *"
654recv_type_arg4=int
655getnameinfo_type_arg1="struct sockaddr *"
656getnameinfo_type_arg7=int
657send_type_arg2="const void *"
658send_type_arg4=int
659
660AC_DEFINE_UNQUOTED([RECVFROM_TYPE_RETV],     [ ${recvfrom_type_retv} ],     [ recvfrom() return value ])
661AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG1],     [ ${recvfrom_type_arg1} ],     [ recvfrom() arg1 type ])
662AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG2],     [ ${recvfrom_type_arg2} ],     [ recvfrom() arg2 type ])
663AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG3],     [ ${recvfrom_type_arg3} ],     [ recvfrom() arg3 type ])
664AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG4],     [ ${recvfrom_type_arg4} ],     [ recvfrom() arg4 type ])
665AC_DEFINE_UNQUOTED([RECVFROM_TYPE_ARG5],     [ ${recvfrom_type_arg5} ],     [ recvfrom() arg5 type ])
666AC_DEFINE_UNQUOTED([RECVFROM_QUAL_ARG5],     [ ${recvfrom_qual_arg5}],      [ recvfrom() arg5 qualifier])
667
668AC_DEFINE_UNQUOTED([RECV_TYPE_RETV],         [ ${recv_type_retv} ],         [ recv() return value ])
669AC_DEFINE_UNQUOTED([RECV_TYPE_ARG1],         [ ${recv_type_arg1} ],         [ recv() arg1 type ])
670AC_DEFINE_UNQUOTED([RECV_TYPE_ARG2],         [ ${recv_type_arg2} ],         [ recv() arg2 type ])
671AC_DEFINE_UNQUOTED([RECV_TYPE_ARG3],         [ ${recv_type_arg3} ],         [ recv() arg3 type ])
672AC_DEFINE_UNQUOTED([RECV_TYPE_ARG4],         [ ${recv_type_arg4} ],         [ recv() arg4 type ])
673
674AC_DEFINE_UNQUOTED([SEND_TYPE_RETV],         [ ${send_type_retv} ],         [ send() return value ])
675AC_DEFINE_UNQUOTED([SEND_TYPE_ARG1],         [ ${send_type_arg1} ],         [ send() arg1 type ])
676AC_DEFINE_UNQUOTED([SEND_TYPE_ARG2],         [ ${send_type_arg2} ],         [ send() arg2 type ])
677AC_DEFINE_UNQUOTED([SEND_TYPE_ARG3],         [ ${send_type_arg3} ],         [ send() arg3 type ])
678AC_DEFINE_UNQUOTED([SEND_TYPE_ARG4],         [ ${send_type_arg4} ],         [ send() arg4 type ])
679
680AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG1],  [ ${getnameinfo_type_arg1} ],  [ getnameinfo() arg1 type ])
681AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG2],  [ ${getnameinfo_type_arg2} ],  [ getnameinfo() arg2 type ])
682AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG7],  [ ${getnameinfo_type_arg7} ],  [ getnameinfo() arg7 type ])
683AC_DEFINE_UNQUOTED([GETNAMEINFO_TYPE_ARG46], [ ${getnameinfo_type_arg46} ], [ getnameinfo() arg4 and 6 type ])
684
685AC_DEFINE_UNQUOTED([GETHOSTNAME_TYPE_ARG2],  [ ${gethostname_type_arg2} ],  [ gethostname() arg2 type ])
686dnl ###############################################################################
687
688
689if test "$ac_cv_have_decl_getservbyport_r" = "yes" ; then
690  AC_MSG_CHECKING([number of arguments for getservbyport_r()])
691  getservbyport_r_args=6
692  case $host_os in
693    solaris*)
694      getservbyport_r_args=5
695    ;;
696    aix*|openbsd*)
697      getservbyport_r_args=4
698    ;;
699  esac
700  AC_MSG_RESULT([$getservbyport_r_args])
701  AC_DEFINE_UNQUOTED([GETSERVBYPORT_R_ARGS], [ $getservbyport_r_args ], [ number of arguments for getservbyport_r() ])
702fi
703
704if test "$ac_cv_have_decl_getservbyname_r" = "yes" ; then
705  AC_MSG_CHECKING([number of arguments for getservbyname_r()])
706  getservbyname_r_args=6
707  case $host_os in
708    solaris*)
709      getservbyname_r_args=5
710    ;;
711    aix*|openbsd*)
712      getservbyname_r_args=4
713    ;;
714  esac
715  AC_DEFINE_UNQUOTED([GETSERVBYNAME_R_ARGS], [ $getservbyname_r_args ], [ number of arguments for getservbyname_r() ])
716  AC_MSG_RESULT([$getservbyname_r_args])
717fi
718
719AC_TYPE_SIZE_T
720AC_CHECK_DECL(AF_INET6, [AC_DEFINE([HAVE_AF_INET6],1,[Define to 1 if you have AF_INET6])], [], $cares_all_includes)
721AC_CHECK_DECL(PF_INET6, [AC_DEFINE([HAVE_PF_INET6],1,[Define to 1 if you have PF_INET6])], [], $cares_all_includes)
722AC_CHECK_TYPES(struct in6_addr, [], [], $cares_all_includes)
723AC_CHECK_TYPES(struct sockaddr_in6, [], [], $cares_all_includes)
724AC_CHECK_TYPES(struct sockaddr_storage, [], [], $cares_all_includes)
725AC_CHECK_TYPES(struct addrinfo, [], [], $cares_all_includes)
726AC_CHECK_TYPES(struct timeval, [], [], $cares_all_includes)
727AC_CHECK_MEMBERS(struct sockaddr_in6.sin6_scope_id, [], [], $cares_all_includes)
728AC_CHECK_MEMBERS(struct addrinfo.ai_flags, [], [], $cares_all_includes)
729AC_CHECK_DECL(FIONBIO, [], [], $cares_all_includes)
730AC_CHECK_DECL(O_NONBLOCK, [], [], $cares_all_includes)
731AC_CHECK_DECL(SO_NONBLOCK, [], [], $cares_all_includes)
732AC_CHECK_DECL(MSG_NOSIGNAL, [], [], $cares_all_includes)
733AC_CHECK_DECL(CLOCK_MONOTONIC, [], [], $cares_all_includes)
734
735if test "$ac_cv_have_decl_CLOCK_MONOTONIC" = "yes" -a "$ac_cv_have_decl_clock_gettime" = "yes" ; then
736  AC_DEFINE([HAVE_CLOCK_GETTIME_MONOTONIC], [ 1 ], [ clock_gettime() with CLOCK_MONOTONIC support ])
737fi
738
739if test "$ac_cv_have_decl_FIONBIO" = "yes" -a "$ac_cv_have_decl_ioctl" = "yes" ; then
740  AC_DEFINE([HAVE_IOCTL_FIONBIO], [ 1 ], [ ioctl() with FIONBIO support ])
741fi
742if test "$ac_cv_have_decl_FIONBIO" = "yes" -a "$ac_cv_have_decl_ioctlsocket" = "yes" ; then
743  AC_DEFINE([HAVE_IOCTLSOCKET_FIONBIO], [ 1 ], [ ioctlsocket() with FIONBIO support ])
744fi
745if test "$ac_cv_have_decl_SO_NONBLOCK" = "yes" -a "$ac_cv_have_decl_setsockopt" = "yes" ; then
746  AC_DEFINE([HAVE_SETSOCKOPT_SO_NONBLOCK], [ 1 ], [ setsockopt() with SO_NONBLOCK support ])
747fi
748if test "$ac_cv_have_decl_O_NONBLOCK" = "yes" -a "$ac_cv_have_decl_fcntl" = "yes" ; then
749  AC_DEFINE([HAVE_FCNTL_O_NONBLOCK], [ 1 ], [ fcntl() with O_NONBLOCK support ])
750fi
751
752dnl ares_build.h.in specific defines
753if test "x$ac_cv_header_sys_types_h" = "xyes" ; then
754  CARES_DEFINE_UNQUOTED([CARES_HAVE_SYS_TYPES_H],[1])
755fi
756if test "x$ac_cv_header_sys_socket_h" = "xyes" ; then
757  CARES_DEFINE_UNQUOTED([CARES_HAVE_SYS_SOCKET_H],[1])
758fi
759if test "x$ac_cv_header_sys_select_h" = "xyes" ; then
760  CARES_DEFINE_UNQUOTED([CARES_HAVE_SYS_SELECT_H],[1])
761fi
762if test "x$ac_cv_header_ws2tcpip_h" = "xyes" ; then
763  CARES_DEFINE_UNQUOTED([CARES_HAVE_WS2TCPIP_H],[1])
764fi
765if test "x$ac_cv_header_winsock2_h" = "xyes" ; then
766  CARES_DEFINE_UNQUOTED([CARES_HAVE_WINSOCK2_H],[1])
767fi
768if test "x$ac_cv_header_windows_h" = "xyes" ; then
769  CARES_DEFINE_UNQUOTED([CARES_HAVE_WINDOWS_H],[1])
770fi
771if test "x$ac_cv_header_arpa_nameser_h" = "xyes" ; then
772  CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_H],[1])
773fi
774if test "x$ac_cv_header_arpa_nameser_compa_h" = "xyes" ; then
775  CARES_DEFINE_UNQUOTED([CARES_HAVE_ARPA_NAMESER_COMPA_H],[1])
776fi
777
778
779dnl ------------ THREADING --------------
780
781dnl windows always supports threads, only check non-windows systems.
782if test "${CARES_THREADS}" = "yes" -a "x${ac_cv_native_windows}" != "xyes" ; then
783  AX_PTHREAD([ ], [
784    AC_MSG_WARN([threads requested but not supported])
785    CARES_THREADS=no
786  ])
787
788  if test "${CARES_THREADS}" = "yes" ; then
789    AC_CHECK_HEADERS([pthread.h pthread_np.h])
790    LIBS="$PTHREAD_LIBS $LIBS"
791    AM_CFLAGS="$AM_CFLAGS $PTHREAD_CFLAGS"
792    CC="$PTHREAD_CC"
793    CXX="$PTHREAD_CXX"
794  fi
795fi
796
797if test "${CARES_THREADS}" = "yes" ; then
798  AC_DEFINE([CARES_THREADS], [ 1 ], [Threading enabled])
799fi
800
801CARES_PRIVATE_LIBS="$LIBS"
802AC_SUBST(CARES_PRIVATE_LIBS)
803
804BUILD_SUBDIRS="include src docs"
805
806
807dnl ******** TESTS *******
808
809if test "x$build_tests" != "xno" -a "x$HAVE_CXX14" = "0" ; then
810  if test "x$build_tests" = "xmaybe" ; then
811    AC_MSG_WARN([cannot build tests without a CXX14 compiler])
812    build_tests=no
813  else
814    AC_MSG_ERROR([*** Building tests requires a CXX14 compiler])
815  fi
816fi
817if test "x$build_tests" != "xno" -a "x$cross_compiling" = "xyes" ; then
818  if test "x$build_tests" = "xmaybe" ; then
819    AC_MSG_WARN([cannot build tests when cross compiling])
820    build_tests=no
821  else
822    AC_MSG_ERROR([*** Tests not supported when cross compiling])
823  fi
824fi
825
826dnl Forces compiling of tests even when cross-compiling.
827AC_ARG_ENABLE(tests-crossbuild,
828  AS_HELP_STRING([--enable-tests-crossbuild], [Enable test building even when cross building]),
829  [build_tests="$enableval"]
830)
831
832if test "x$build_tests" != "xno" ; then
833  PKG_CHECK_MODULES([GMOCK], [gmock], [ have_gmock=yes ], [ have_gmock=no ])
834  if test "x$have_gmock" = "xno" ; then
835    if test "x$build_tests" = "xmaybe" ; then
836      AC_MSG_WARN([gmock could not be found, not building tests])
837      build_tests=no
838    else
839      AC_MSG_ERROR([tests require gmock])
840    fi
841  else
842    PKG_CHECK_MODULES([GMOCK112], [gmock >= 1.12.0], [ have_gmock_v112=yes ], [ have_gmock_v112=no ])
843    if test "x$have_gmock_v112" = "xyes" ; then
844      ARES_CHECK_USER_NAMESPACE
845      ARES_CHECK_UTS_NAMESPACE
846    fi
847  fi
848fi
849if test "x$build_tests" != "xno" ; then
850  build_tests=yes
851
852  AX_CXX_COMPILE_STDCXX_14([noext],[mandatory])
853  if test "$ac_cv_native_windows" != "yes" ; then
854    AX_PTHREAD([ CARES_TEST_PTHREADS="yes" ], [ AC_MSG_ERROR([threading required for tests]) ])
855  fi
856
857  BUILD_SUBDIRS="${BUILD_SUBDIRS} test"
858fi
859AC_MSG_CHECKING([whether to build tests])
860AC_MSG_RESULT([$build_tests])
861
862AM_CONDITIONAL(BUILD_TESTS, test "x$build_tests" = "xyes")
863
864AC_SUBST(AM_CFLAGS)
865AC_SUBST(AM_CPPFLAGS)
866AC_SUBST(PKGCONFIG_CFLAGS)
867AC_SUBST(BUILD_SUBDIRS)
868
869AC_CONFIG_FILES([Makefile
870                 include/Makefile
871                 src/Makefile
872                 src/lib/Makefile
873                 src/tools/Makefile
874                 docs/Makefile
875                 libcares.pc ])
876AM_COND_IF([BUILD_TESTS],
877           [AC_CONFIG_FILES([test/Makefile])])
878
879AC_OUTPUT
880