bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: bug-gnulib@gnu.org
Subject: [PATCH] configmake: Avoid namespace pollution issue on mingw.
Date: Thu,  8 Aug 2019 07:04:24 -0500	[thread overview]
Message-ID: <20190808120424.2750-1-eblake@redhat.com> (raw)

Mingw includes a header that declares a struct typedef named DATADIR,
pulled in when including <winsock2.h>; compilation fails if DATADIR
has already been defined as a macro expanding to a string prior to
that inclusion.  Although the configmake module documents that it
should generally be included only after system headers, it is just as
easy to make configmake.h robust to this particular issue by including
the system header first if it exists.

* modules/configmake (Makefile.am): If the project uses
<winsock2.h>, include that header before defining DATADIR.
Reported by libvirt: https://lists.gnu.org/archive/html/bug-gnulib/2019-07/msg00089.html
---

I've tested that this will fix the issue originally reported by
libvirt.  Bruno's suggestion of renaming configmake.h's version to
something like MAKEVAR_DATADIR would also work, but if we did that, it
would be better to uniformly rename all of configmake.h's macros (and
that is much more invasive to the existing users of configmake).

 ChangeLog          | 6 ++++++
 modules/configmake | 3 +++
 2 files changed, 9 insertions(+)

diff --git a/ChangeLog b/ChangeLog
index 644330370..35f870abe 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2019-08-08  Eric Blake  <eblake@redhat.com>
+
+	configmake: Avoid namespace pollution issue on mingw.
+	* modules/configmake (Makefile.am): If the project uses
+	<winsock2.h>, include that header before defining DATADIR.
+
 2019-07-28  Bruno Haible  <bruno@clisp.org>

 	mbrtowc tests: Fix regression on mingw (regression from 2018-02-24).
diff --git a/modules/configmake b/modules/configmake
index 5a60f4f80..0074071fc 100644
--- a/modules/configmake
+++ b/modules/configmake
@@ -17,6 +17,9 @@ Makefile.am:
 configmake.h: Makefile
 	$(AM_V_GEN)rm -f $@-t && \
 	{ echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
+          echo '#if HAVE_WINSOCK2_H'; \
+          echo '# include <winsock2.h> /* avoid mingw pollution on DATADIR */'; \
+          echo '#endif'; \
 	  echo '#define PREFIX "$(prefix)"'; \
 	  echo '#define EXEC_PREFIX "$(exec_prefix)"'; \
 	  echo '#define BINDIR "$(bindir)"'; \
-- 
2.20.1



             reply	other threads:[~2019-08-08 12:06 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-08-08 12:04 Eric Blake [this message]
2019-08-10 20:17 ` [PATCH] configmake: Avoid namespace pollution issue on mingw Bruno Haible
2019-08-10 21:18   ` Eric Blake
  -- strict thread matches above, loose matches on Subject: below --
2019-08-08 12:30 Eric Blake
2019-08-08 13:07 ` Eric Blake

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190808120424.2750-1-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=bug-gnulib@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).