From a125b5631228873144b0297b05c44628f4a9745e Mon Sep 17 00:00:00 2001
From: "Uwe L. Korn" <uwe.korn@quantco.com>
Date: Wed, 13 Mar 2024 20:46:27 +0100
Subject: [PATCH 8/8] Avoid close inconsistencies

When building libgettextsrc on Windows, we run into an error with an undefined symbol
`close_used_without_requesting_gnulib_module_close`. This appears to be because
the build adds `../libgrep` to the C preprocesor include path, and that directory
includes a `unistd.h` that does not have gnulib's replacement for the standard C
function `close()` defined. This is because libgrep doesn't rely on anything that
needs it, and gnulib has infrastructure to only include configure checks for the
elements that are needed by a given library. But libgettextsrc's `write-catalog.c`
shouldn't be built against this version of `unistd.h`, because it uses `close()`
and therefore does need the wrapper. The solution is to only add libgrep to the
preprocessor search path for the `msggrep` program, which is the one that actually
needs the library.
---
 gettext-tools/src/Makefile.am | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/gettext-tools/src/Makefile.am b/gettext-tools/src/Makefile.am
index 2a8c9d8..d53d727 100644
--- a/gettext-tools/src/Makefile.am
+++ b/gettext-tools/src/Makefile.am
@@ -99,7 +99,6 @@ pkglibdir = $(libdir)/gettext
 AM_CPPFLAGS = \
   -I. -I$(srcdir) \
   -I.. -I$(top_srcdir) \
-  -I$(top_srcdir)/libgrep \
   -I../gnulib-lib -I$(top_srcdir)/gnulib-lib \
   -I../../gettext-runtime/intl -I$(top_srcdir)/../gettext-runtime/intl
 DEFS = \
@@ -415,7 +414,7 @@ msgconv_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
 msgen_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
 msgexec_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
 msgfilter_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
-msggrep_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
+msggrep_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/libgrep -DINSTALLDIR=\"$(bindir)\"
 msginit_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
 msguniq_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
 recode_sr_latin_CPPFLAGS = $(AM_CPPFLAGS) -DINSTALLDIR=\"$(bindir)\"
