Bruno Haible <[EMAIL PROTECTED]> writes: > + /* mingw fails to declare gethostname in <unistd.h>. */ > + #if @GNULIB_GETHOSTNAME@ && ((defined _WIN32 || defined __WIN32__) && ! > defined __CYGWIN__) > + # include <sys/socket.h> > + #endif > +
I tried your patch now, to take care of problem 1), but it doesn't work. For mingw, @GNULIB_GETHOSTNAME@ will be 0 since it has a gethostname (if sys/socket.h is pulled in). Also, the gethostname module needs the gnulib unistd.h to work around the problems on mingw. How about this? It is a complete patch against master, that works on debian-x86 and mingw. Thanks, /Simon diff --git a/ChangeLog b/ChangeLog index f52d4c2..070a15e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,4 +1,22 @@ 2008-01-17 Simon Josefsson <[EMAIL PROTECTED]> + Bruno Haible <[EMAIL PROTECTED]> + + * lib/unistd.in.h: Include <sys/socket.h> conditionally. + * modules/unistd (Makefile.am): Substitute GNULIB_GETHOSTNAME. + * modules/gethostname (Depends-on): Add sys_socket and unistd. + (configure.ac): Invoke gl_MODULE_INDICATOR. + (Include): Document <unistd.h>. + * m4/unistd_h.m4: Default GNULIB_GETHOSTNAME to 0. + +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. + +2008-01-17 Simon Josefsson <[EMAIL PROTECTED]> * modules/gethostname-tests: New file. diff --git a/lib/unistd.in.h b/lib/unistd.in.h index 5400c86..809c14a 100644 --- a/lib/unistd.in.h +++ b/lib/unistd.in.h @@ -1,5 +1,5 @@ /* Substitute for and wrapper around <unistd.h>. - Copyright (C) 2004-2007 Free Software Foundation, Inc. + Copyright (C) 2004-2008 Free Software Foundation, Inc. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -33,6 +33,11 @@ /* mingw fails to declare _exit in <unistd.h>. */ #include <stdlib.h> +/* mingw fails to declare gethostname in <unistd.h>. */ +#if [EMAIL PROTECTED]@ && ((defined _WIN32 || defined __WIN32__) && ! defined __CYGWIN__) +# include <sys/socket.h> +#endif + /* The definition of GL_LINK_WARNING is copied here. */ 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/m4/unistd_h.m4 b/m4/unistd_h.m4 index 4b8857c..1eca87c 100644 --- a/m4/unistd_h.m4 +++ b/m4/unistd_h.m4 @@ -1,5 +1,5 @@ # unistd_h.m4 serial 10 -dnl Copyright (C) 2006-2007 Free Software Foundation, Inc. +dnl Copyright (C) 2006-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. @@ -38,6 +38,7 @@ AC_DEFUN([gl_UNISTD_H_DEFAULTS], GNULIB_FTRUNCATE=0; AC_SUBST([GNULIB_FTRUNCATE]) GNULIB_GETCWD=0; AC_SUBST([GNULIB_GETCWD]) GNULIB_GETLOGIN_R=0; AC_SUBST([GNULIB_GETLOGIN_R]) + GNULIB_GETHOSTNAME=0; AC_SUBST([GNULIB_GETHOSTNAME]) GNULIB_GETPAGESIZE=0; AC_SUBST([GNULIB_GETPAGESIZE]) GNULIB_LCHOWN=0; AC_SUBST([GNULIB_LCHOWN]) GNULIB_LSEEK=0; AC_SUBST([GNULIB_LSEEK]) diff --git a/modules/gethostname b/modules/gethostname index 7c13807..b169701 100644 --- a/modules/gethostname +++ b/modules/gethostname @@ -6,13 +6,17 @@ lib/gethostname.c m4/gethostname.m4 Depends-on: +unistd +sys_socket configure.ac: gl_FUNC_GETHOSTNAME +gl_MODULE_INDICATOR([gethostname]) Makefile.am: Include: +<unistd.h> License: LGPL diff --git a/modules/unistd b/modules/unistd index 4d16cf3..6d1c1fb 100644 --- a/modules/unistd +++ b/modules/unistd @@ -29,6 +29,7 @@ unistd.h: unistd.in.h -e 's|@''GNULIB_FTRUNCATE''@|$(GNULIB_FTRUNCATE)|g' \ -e 's|@''GNULIB_GETCWD''@|$(GNULIB_GETCWD)|g' \ -e 's|@''GNULIB_GETLOGIN_R''@|$(GNULIB_GETLOGIN_R)|g' \ + -e 's|@''GNULIB_GETHOSTNAME''@|$(GNULIB_GETHOSTNAME)|g' \ -e 's|@''GNULIB_GETPAGESIZE''@|$(GNULIB_GETPAGESIZE)|g' \ -e 's|@''GNULIB_LCHOWN''@|$(GNULIB_LCHOWN)|g' \ -e 's|@''GNULIB_LSEEK''@|$(GNULIB_LSEEK)|g' \