autoconf: fix getaddrinfo checking errors on mingw

`AC_CHECK_FUNCS` can not properly check `getaddrinfo` because this
function requires some special headers on mingw.
Using `AC_CHECK_DECL` can effectively solve this issue.

Same for
- getnameinfo
- getprotobynumber
- getservbyname
- inet_ntop
- inet_pton

(cherry picked from commit 6d54be2cc078351b4ce1e469bedc4a976f4e3636)
This commit is contained in:
yuangongji 2020-03-14 11:13:38 +08:00 committed by Azat Khuzhin
parent e41a1969b0
commit b9bf7fa71d
2 changed files with 52 additions and 10 deletions

View File

@ -251,6 +251,7 @@ AC_CHECK_HEADERS([ \
sys/wait.h \
sys/random.h \
errno.h \
afunix.h \
])
case "${host_os}" in
@ -347,7 +348,7 @@ AM_CONDITIONAL(BUILD_MIDIPIX, test x$midipix = xtrue)
AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue || test x$midipix = xtrue)
if test x$bwin32 = xtrue; then
AC_SEARCH_LIBS([getservbyname],[ws2_32])
AC_HAVE_LIBRARY([ws2_32])
fi
dnl Checks for typedefs, structures, and compiler characteristics.
@ -367,11 +368,7 @@ AC_CHECK_FUNCS([ \
getegid \
geteuid \
getifaddrs \
getnameinfo \
getprotobynumber \
gettimeofday \
inet_ntop \
inet_pton \
issetugid \
mach_absolute_time \
mmap \
@ -395,17 +392,36 @@ AC_CHECK_FUNCS([ \
unsetenv \
usleep \
vasprintf \
getservbyname \
getrandom \
])
AC_CHECK_FUNCS(_gmtime64_s, [have__gmtime64_s=yes], )
if test "x$have__gmtime64_s" != "xyes"; then
AC_CHECK_FUNCS(_gmtime64)
fi
AS_IF([test x$bwin32 = xtrue],
AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)])
)
AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno])
m4_define([funcstochk],
[getnameinfo
getprotobynumber
getservbyname
inet_ntop
inet_pton]
)
AS_IF([test x$bwin32 = xtrue],
[AX_CHECK_DECLS_EX([funcstochk getaddrinfo],
[#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#endif])],
[AC_CHECK_FUNCS(m4_normalize(funcstochk))]
)
m4_undefine([funcstochk])
dnl check getaddrinfo and gethostbyname_r for non-windows
AS_IF([test x$bwin32 = xfalse], [
AC_CACHE_CHECK(
[for getaddrinfo],
[libevent_cv_getaddrinfo],
@ -485,6 +501,7 @@ AC_CHECK_FUNC(gethostbyname_r, [
])
fi
]) dnl end of checking getaddrinfo and gethostbyname_r
AC_MSG_CHECKING(for F_SETFD in fcntl.h)
AC_EGREP_CPP(yes,
@ -738,6 +755,9 @@ AC_CHECK_TYPES([struct linger],,,
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef _WIN32
#include <winsock2.h>
#endif
])
AC_MSG_CHECKING([for socklen_t])

22
m4/ax_check_funcs_ex.m4 Normal file
View File

@ -0,0 +1,22 @@
# Check if the function is available.
# HAVE_XXX will be defined if yes.
# $1: the name of function
# $2: the headers in where the function declared
AC_DEFUN([AX_CHECK_DECL_EX], [dnl
AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])])
AS_VAR_PUSHDEF([have_func_var], [HAVE_[]m4_toupper($1)])
AC_CHECK_DECL([$1],dnl
[AC_DEFINE([have_func_var], [1], [Define to 1 if you have the `$1' function.])],,dnl
[$2]dnl
)
AS_VAR_POPDEF([have_func_var])dnl
])
AC_DEFUN([AX_CHECK_DECLS_EX], [dnl
AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])])
m4_foreach([decl],dnl
m4_split(m4_normalize($1)),dnl
[AX_CHECK_DECL_EX([decl], [$2])]dnl
)
])