Simon Josefsson <[EMAIL PROTECTED]> writes: > 1) Modify gethostname module to look for gethostname in winsock2.h and > -lws2_32, similar to what's in getaddrinfo.m4. This will make gethostname > depend on sys/socket.h, just like getaddrinfo does. > > 2) Modify unistd module to make sure it includes sys/socket.h when > @GNULIB_GETHOSTNAME@ is enabled. > > I think your patch mostly takes care of 2), so I'll see if I can propose > a better gethostname.m4 test that actually detects gethostname on MinGW.
Below is the patch for gethostname.m4. On debian x86: checking for unistd.h... yes checking sys/socket.h usability... yes checking sys/socket.h presence... yes checking for sys/socket.h... yes checking whether <sys/socket.h> is self-contained... yes checking for gethostname... yes checking whether <sys/socket.h> is self-contained... (cached) yes The gethostname replacement isn't built, and the self-test works. On mingw32: checking for unistd.h... yes checking sys/socket.h usability... no checking sys/socket.h presence... no checking for sys/socket.h... no checking whether <sys/socket.h> is self-contained... no checking winsock2.h usability... yes checking winsock2.h presence... yes checking for winsock2.h... yes checking ws2tcpip.h usability... yes checking ws2tcpip.h presence... yes checking for ws2tcpip.h... yes checking for gethostname... no checking for gethostname in winsock2.h and -lws2_32... yes checking whether <sys/socket.h> is self-contained... (cached) no The gethostname replacement isn't built. The self-test fails on mingw because unistd.h doesn't pull in winsock2.h, but that's issue 2) above. If I manually add #include <winsock2.h>, it works. Comments? /Simon 2008-01-17 Simon Josefsson <[EMAIL PROTECTED]> * m4/gethostname.m4: Look for gethostname in winsock2.h and -lws2_32 too, for mingw. * modules/gethostname (Depends-on): Add sys_socket, needed for proper mingw checks. diff --git a/m4/gethostname.m4 b/m4/gethostname.m4 index 1e9749d..359cdf1 100644 --- a/m4/gethostname.m4 +++ b/m4/gethostname.m4 @@ -1,13 +1,45 @@ -# gethostname.m4 serial 2 -dnl Copyright (C) 2002 Free Software Foundation, Inc. +# gethostname.m4 serial 3 +dnl Copyright (C) 2002, 2008 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. AC_DEFUN([gl_FUNC_GETHOSTNAME], [ - AC_REPLACE_FUNCS(gethostname) - if test $ac_cv_func_gethostname = no; then + AC_REQUIRE([gl_HEADER_SYS_SOCKET])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H + + AC_CACHE_CHECK([for gethostname], [gl_cv_func_gethostname], [ + AC_TRY_LINK([ +#include <sys/types.h> +#ifdef HAVE_SYS_SOCKET_H +#include <sys/socket.h> +#endif +#include <stddef.h> +], [gethostname("", 0);], + [gl_cv_func_gethostname=yes], + [gl_cv_func_gethostname=no])]) + if test $gl_cv_func_gethostname = no; then + AC_CACHE_CHECK(for gethostname in winsock2.h and -lws2_32, + gl_cv_w32_gethostname, [ + gl_cv_w32_gethostname=no + am_save_LIBS="$LIBS" + LIBS="$LIBS -lws2_32" + AC_TRY_LINK([ +#ifdef HAVE_WINSOCK2_H +#include <winsock2.h> +#endif +#include <stddef.h> +], [gethostname("", 0);], gl_cv_w32_gethostname=yes) + LIBS="$am_save_LIBS"]) + if test "$gl_cv_w32_gethostname" = "yes"; then + LIBS="$LIBS -lws2_32" + else + AC_LIBOBJ(gethostname) + fi + fi + + if test "$ac_cv_func_gethostname" = no && + test "$gl_cv_w32_gethostname" = no; then gl_PREREQ_GETHOSTNAME fi ]) diff --git a/modules/gethostname b/modules/gethostname index 7c13807..ec367b7 100644 --- a/modules/gethostname +++ b/modules/gethostname @@ -6,6 +6,7 @@ lib/gethostname.c m4/gethostname.m4 Depends-on: +sys_socket configure.ac: gl_FUNC_GETHOSTNAME