poll: Avoid link errors on MSVC.
authorBruno Haible <bruno@clisp.org>
Tue, 4 Oct 2011 01:33:21 +0000 (03:33 +0200)
committerBruno Haible <bruno@clisp.org>
Tue, 4 Oct 2011 01:33:21 +0000 (03:33 +0200)
* m4/poll.m4 (gl_FUNC_POLL): Determine LIB_POLL.
* modules/poll (Depends-on): Add sockets.
(Link): New section.
* NEWS: Mention the change.
* modules/poll-tests (Makefile.am): Link test-poll against $(LIB_POLL).
* modules/poll-h-c++-tests (Makefile.am): Link test-poll-h-c++ against
$(LIB_POLL) instead of $(LIBSOCKET).

ChangeLog
NEWS
m4/poll.m4
modules/poll
modules/poll-h-c++-tests
modules/poll-tests

index 28a1811..7906531 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,16 @@
 2011-10-03  Bruno Haible  <bruno@clisp.org>
 
+       poll: Avoid link errors on MSVC.
+       * m4/poll.m4 (gl_FUNC_POLL): Determine LIB_POLL.
+       * modules/poll (Depends-on): Add sockets.
+       (Link): New section.
+       * NEWS: Mention the change.
+       * modules/poll-tests (Makefile.am): Link test-poll against $(LIB_POLL).
+       * modules/poll-h-c++-tests (Makefile.am): Link test-poll-h-c++ against
+       $(LIB_POLL) instead of $(LIBSOCKET).
+
+2011-10-03  Bruno Haible  <bruno@clisp.org>
+
        sys_select tests: Fix link error on MSVC 9.
        * modules/sys_select-c++-tests (Makefile.am): Link test-sys_select-c++
        with $(LIB_SELECT) instead of $(LIBSOCKET).
diff --git a/NEWS b/NEWS
index 85d3d43..2e98e61 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -12,6 +12,9 @@ User visible incompatible changes
 
 Date        Modules         Changes
 
+2011-10-03  poll            The link requirements of this module are changed
+                            from empty to $(LIB_POLL).
+
 2011-09-25  sys_stat        This module no longer provides the fstat()
                             function. If you need this function, you now need
                             to request the 'fstat' module.
index e489df7..0cf3183 100644 (file)
@@ -1,4 +1,4 @@
-# poll.m4 serial 14
+# poll.m4 serial 15
 dnl Copyright (c) 2003, 2005-2007, 2009-2011 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -7,6 +7,7 @@ dnl with or without modifications, as long as this notice is preserved.
 AC_DEFUN([gl_FUNC_POLL],
 [
   AC_REQUIRE([gl_POLL_H])
+  AC_REQUIRE([gl_SOCKETS])
   if test "$ac_cv_header_poll_h" = no; then
     ac_cv_func_poll=no
     gl_cv_func_poll=no
@@ -68,6 +69,31 @@ This is MacOSX or AIX
     AC_DEFINE([HAVE_POLL], [1],
       [Define to 1 if you have the 'poll' function and it works.])
   fi
+
+  dnl Determine the needed libraries.
+  LIB_POLL="$LIBSOCKET"
+  if test $HAVE_POLL = 0 || test $REPLACE_POLL = 1; then
+    case "$host_os" in
+      mingw*)
+        dnl On the MSVC platform, the function MsgWaitForMultipleObjects
+        dnl (used in lib/poll.c) requires linking with -luser32. On mingw,
+        dnl it is implicit.
+        AC_LINK_IFELSE(
+          [AC_LANG_SOURCE([[
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+int
+main ()
+{
+  MsgWaitForMultipleObjects (0, NULL, 0, 0, 0);
+  return 0;
+}]])],
+          [],
+          [LIB_POLL="$LIB_POLL -luser32"])
+        ;;
+    esac
+  fi
+  AC_SUBST([LIB_POLL])
 ])
 
 # Prerequisites of lib/poll.c.
index 3714332..8fa88fd 100644 (file)
@@ -9,6 +9,7 @@ Depends-on:
 poll-h
 alloca          [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 select          [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
+sockets         [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 sys_select      [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 sys_time        [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
 errno           [test $HAVE_POLL = 0 || test $REPLACE_POLL = 1]
@@ -27,6 +28,9 @@ Makefile.am:
 Include:
 <poll.h>
 
+Link:
+$(LIB_POLL)
+
 License:
 LGPLv2+
 
index 7ca908c..8dd6262 100644 (file)
@@ -15,5 +15,5 @@ if ANSICXX
 TESTS += test-poll-h-c++
 check_PROGRAMS += test-poll-h-c++
 test_poll_h_c___SOURCES = test-poll-h-c++.cc
-test_poll_h_c___LDADD = $(LDADD) @LIBSOCKET@
+test_poll_h_c___LDADD = $(LDADD) $(LIB_POLL)
 endif
index d34107e..ab291a0 100644 (file)
@@ -28,4 +28,4 @@ AC_CHECK_HEADERS_ONCE([unistd.h sys/wait.h])
 Makefile.am:
 TESTS += test-poll
 check_PROGRAMS += test-poll
-test_poll_LDADD = $(LDADD) @LIBSOCKET@ $(INET_PTON_LIB)
+test_poll_LDADD = $(LDADD) $(LIB_POLL) @LIBSOCKET@ $(INET_PTON_LIB)