Hi Simon, > - AC_REPLACE_FUNCS(gai_strerror) > + # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an > + # inline function declared in ws2tcpip.h, so we need to get that > + # header included somehow. > + AC_MSG_CHECKING([for gai_strerror (possibly via ws2tcpip.h)]) > + AC_TRY_LINK([ > +#ifdef HAVE_WS2TCPIP_H > +#include <ws2tcpip.h> > +#endif > +], [gai_strerror (0);], > + AC_MSG_RESULT([yes]), > + [AC_MSG_RESULT([no]) > + AC_LIBOBJ(gai_strerror)]) > + > gl_PREREQ_GETADDRINFO > ])
The following can be improved: - You're testing HAVE_WS2TCPIP_H without making sure that an AC_CHECK_HEADER([ws2tcpip.h]) has been executed before. - The test will fail on most Unix platforms when a C++ compiler is being used, because in C++ it's a compilatione error to call a function when its declaration has not been included. In other words, you need to include also <sys/types.h>, <sys/socket.h>, <netdb.h>, to get the declaration. - Every AC_TRY_LINK or AC_TRY_COMPILE should normally be wrapped in an AC_CACHE_CHECK - for speed of reconfiguring. How about this? 2007-06-27 Simon Josefsson <[EMAIL PROTECTED]> Bruno Haible <[EMAIL PROTECTED]> * m4/getaddrinfo.m4 (gl_GETADDRINFO): Check for ws2tcpip.h before using HAVE_WS2TCPIP_H. Check for gai_strerror through an explicit link test, rather than AC_REPLACE_FUNCS - for mingw. (gl_PREREQ_GETADDRINFO): Check for sys/socket.h and ws2tcpip.h before using HAVE_SYS_SOCKET_H and HAVE_WS2TCPIP_H. --- m4/getaddrinfo.m4 9 Aug 2006 22:52:40 -0000 1.18 +++ m4/getaddrinfo.m4 27 Jun 2007 20:59:54 -0000 @@ -1,5 +1,5 @@ -# getaddrinfo.m4 serial 11 -dnl Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. +# getaddrinfo.m4 serial 12 +dnl Copyright (C) 2004, 2005, 2006, 2007 Free Software Foundation, Inc. dnl This file is free software; the Free Software Foundation dnl gives unlimited permission to copy and/or distribute it, dnl with or without modifications, as long as this notice is preserved. @@ -8,6 +8,7 @@ [ AC_MSG_NOTICE([checking how to do getaddrinfo, freeaddrinfo and getnameinfo]) + AC_CHECK_HEADERS_ONCE(ws2tcpip.h) AC_SEARCH_LIBS(getaddrinfo, [nsl socket]) AC_CHECK_FUNCS(getaddrinfo,, [ AC_CACHE_CHECK(for getaddrinfo in ws2tcpip.h and -lws2_32, @@ -28,7 +29,30 @@ fi ]) - AC_REPLACE_FUNCS(gai_strerror) + # We can't use AC_REPLACE_FUNCS here because gai_strerror may be an + # inline function declared in ws2tcpip.h, so we need to get that + # header included somehow. + AC_CHECK_HEADERS_ONCE(sys/socket.h netdb.h ws2tcpip.h) + AC_CACHE_CHECK([for gai_strerror (possibly via ws2tcpip.h)], + gl_cv_func_gai_strerror, [ + AC_TRY_LINK([ +#include <sys/types.h> +#ifdef HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif +#ifdef HAVE_NETDB_H +#include <netdb.h> +#endif +#ifdef HAVE_WS2TCPIP_H +#include <ws2tcpip.h> +#endif +], [gai_strerror (0);], + [gl_cv_func_gai_strerror=yes], + [gl_cv_func_gai_strerror=no])]) + if test $gl_cv_func_gai_strerror = no; then + AC_LIBOBJ(gai_strerror) + fi + gl_PREREQ_GETADDRINFO ]) @@ -57,7 +81,7 @@ AC_REQUIRE([gl_HEADER_SYS_SOCKET]) AC_REQUIRE([AC_C_INLINE]) AC_REQUIRE([AC_GNU_SOURCE]) - AC_CHECK_HEADERS_ONCE(netinet/in.h netdb.h) + AC_CHECK_HEADERS_ONCE(netinet/in.h sys/socket.h netdb.h ws2tcpip.h) AC_CHECK_DECLS([getaddrinfo, freeaddrinfo, gai_strerror, getnameinfo],,,[ /* sys/types.h is not needed according to POSIX, but the sys/socket.h in i386-unknown-freebsd4.10 and