Skip to content

Commit b9bf7fa

Browse files
ygj6azat
authored andcommitted
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 6d54be2)
1 parent e41a196 commit b9bf7fa

File tree

2 files changed

+52
-10
lines changed

2 files changed

+52
-10
lines changed

configure.ac

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,7 @@ AC_CHECK_HEADERS([ \
251251
sys/wait.h \
252252
sys/random.h \
253253
errno.h \
254+
afunix.h \
254255
])
255256

256257
case "${host_os}" in
@@ -347,7 +348,7 @@ AM_CONDITIONAL(BUILD_MIDIPIX, test x$midipix = xtrue)
347348
AM_CONDITIONAL(BUILD_WITH_NO_UNDEFINED, test x$bwin32 = xtrue || test x$cygwin = xtrue || test x$midipix = xtrue)
348349

349350
if test x$bwin32 = xtrue; then
350-
AC_SEARCH_LIBS([getservbyname],[ws2_32])
351+
AC_HAVE_LIBRARY([ws2_32])
351352
fi
352353

353354
dnl Checks for typedefs, structures, and compiler characteristics.
@@ -367,11 +368,7 @@ AC_CHECK_FUNCS([ \
367368
getegid \
368369
geteuid \
369370
getifaddrs \
370-
getnameinfo \
371-
getprotobynumber \
372371
gettimeofday \
373-
inet_ntop \
374-
inet_pton \
375372
issetugid \
376373
mach_absolute_time \
377374
mmap \
@@ -395,17 +392,36 @@ AC_CHECK_FUNCS([ \
395392
unsetenv \
396393
usleep \
397394
vasprintf \
398-
getservbyname \
399395
getrandom \
400396
])
401397

402-
AC_CHECK_FUNCS(_gmtime64_s, [have__gmtime64_s=yes], )
403-
if test "x$have__gmtime64_s" != "xyes"; then
404-
AC_CHECK_FUNCS(_gmtime64)
405-
fi
398+
AS_IF([test x$bwin32 = xtrue],
399+
AC_CHECK_FUNCS(_gmtime64_s, , [AC_CHECK_FUNCS(_gmtime64)])
400+
)
406401

407402
AM_CONDITIONAL(STRLCPY_IMPL, [test x"$ac_cv_func_strlcpy" = xno])
408403

404+
m4_define([funcstochk],
405+
[getnameinfo
406+
getprotobynumber
407+
getservbyname
408+
inet_ntop
409+
inet_pton]
410+
)
411+
412+
AS_IF([test x$bwin32 = xtrue],
413+
[AX_CHECK_DECLS_EX([funcstochk getaddrinfo],
414+
[#ifdef _WIN32
415+
#include <winsock2.h>
416+
#include <ws2tcpip.h>
417+
#endif])],
418+
[AC_CHECK_FUNCS(m4_normalize(funcstochk))]
419+
)
420+
421+
m4_undefine([funcstochk])
422+
423+
dnl check getaddrinfo and gethostbyname_r for non-windows
424+
AS_IF([test x$bwin32 = xfalse], [
409425
AC_CACHE_CHECK(
410426
[for getaddrinfo],
411427
[libevent_cv_getaddrinfo],
@@ -485,6 +501,7 @@ AC_CHECK_FUNC(gethostbyname_r, [
485501
])
486502
487503
fi
504+
]) dnl end of checking getaddrinfo and gethostbyname_r
488505

489506
AC_MSG_CHECKING(for F_SETFD in fcntl.h)
490507
AC_EGREP_CPP(yes,
@@ -738,6 +755,9 @@ AC_CHECK_TYPES([struct linger],,,
738755
#ifdef HAVE_SYS_SOCKET_H
739756
#include <sys/socket.h>
740757
#endif
758+
#ifdef _WIN32
759+
#include <winsock2.h>
760+
#endif
741761
])
742762

743763
AC_MSG_CHECKING([for socklen_t])

m4/ax_check_funcs_ex.m4

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Check if the function is available.
2+
# HAVE_XXX will be defined if yes.
3+
4+
# $1: the name of function
5+
# $2: the headers in where the function declared
6+
AC_DEFUN([AX_CHECK_DECL_EX], [dnl
7+
AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])])
8+
AS_VAR_PUSHDEF([have_func_var], [HAVE_[]m4_toupper($1)])
9+
AC_CHECK_DECL([$1],dnl
10+
[AC_DEFINE([have_func_var], [1], [Define to 1 if you have the `$1' function.])],,dnl
11+
[$2]dnl
12+
)
13+
AS_VAR_POPDEF([have_func_var])dnl
14+
])
15+
16+
AC_DEFUN([AX_CHECK_DECLS_EX], [dnl
17+
AS_IF([test "x$2" = "x"], [AC_MSG_ERROR([header not privided])])
18+
m4_foreach([decl],dnl
19+
m4_split(m4_normalize($1)),dnl
20+
[AX_CHECK_DECL_EX([decl], [$2])]dnl
21+
)
22+
])

0 commit comments

Comments
 (0)