Subject: [PATCH v2] macos: do let the build find the gettext headers/libraries/msgfmt

From: "Johannes Schindelin via GitGitGadget" <[email-masked]>
Date: Sat, 25 Apr 2020 12:54:26 +0000

From: Johannes Schindelin <[email-masked]>

Apparently a recent Homebrew update now installs `gettext` into a
subdirectory under /usr/local/, requiring the CFLAGS/LDFLAGS to list
explicit directories _even_ when asking to force-link the `gettext`
package.

Likewise, the `msgfmt` tool is no longer in the `PATH`.

While it is unclear which change is responsible for this breakage (that
most notably only occurs on CI build agents that updated very recently),
https://github.com/Homebrew/homebrew-core/pull/53489 should fix it.

Nevertheless, let's work around this issue, as there are still quite a
few build agents out there that need some help in this regard: we
explicitly do not call `brew update` in our CI/PR builds anymore.

Helped-by: Carlo Marcelo Arenas Belón <[email-masked]>
Signed-off-by: Johannes Schindelin <[email-masked]>
---
    Prepare for Homebrew changing the gettext package
    
    In an early Azure Pipelines preview of what is to come, I saw the 
    osx-clang and osx-gcc jobs fail consistently.
    
    This patch tries to prevent that from affecting our CI/PR builds.
    
    Changes since v1:
    
     * Described a bit better what the issue is, and that there is a
       "de-keg" change that should fix this (but as we no longer call brew
       update, some build agents, that won't matter for slightly out of date
       agents).
     * Guarded the added flags behind a check whether the directory exists
       in the first place.

Published-As: https://github.com/gitgitgadget/git/releases/tag/pr-616%2Fdscho%2Fbrew-gettext-update-v2
Fetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-616/dscho/brew-gettext-update-v2
Pull-Request: https://github.com/gitgitgadget/git/pull/616

Range-diff vs v1:

 1:  c56a2321f62 ! 1:  1aa1b049e5c macos: do let the build find the gettext headers/libraries/msgfmt
     @@ Commit message
      
          Likewise, the `msgfmt` tool is no longer in the `PATH`.
      
     -    Let's work around this issue.
     +    While it is unclear which change is responsible for this breakage (that
     +    most notably only occurs on CI build agents that updated very recently),
     +    https://github.com/Homebrew/homebrew-core/pull/53489 should fix it.
      
     +    Nevertheless, let's work around this issue, as there are still quite a
     +    few build agents out there that need some help in this regard: we
     +    explicitly do not call `brew update` in our CI/PR builds anymore.
     +
     +    Helped-by: Carlo Marcelo Arenas Belón <[email-masked]>
          Signed-off-by: Johannes Schindelin <[email-masked]>
      
       ## config.mak.uname ##
     @@ config.mak.uname: ifeq ($(uname_S),Darwin)
       	HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
      -	BASIC_CFLAGS += -I/usr/local/include
      -	BASIC_LDFLAGS += -L/usr/local/lib
     -+	BASIC_CFLAGS += -I/usr/local/include -I/usr/local/opt/gettext/include
     -+	BASIC_LDFLAGS += -L/usr/local/lib -L/usr/local/opt/gettext/lib
     -+	ifeq ($(shell test -x /usr/local/opt/gettext/bin/msgfmt && echo y),y)
     -+		MSGFMT = /usr/local/opt/gettext/bin/msgfmt
     ++
     ++	# Workaround for `gettext` being keg-only and not even being linked via
     ++	# `brew link --force gettext`, should be obsolete as of
     ++	# https://github.com/Homebrew/homebrew-core/pull/53489
     ++	ifeq ($(shell test -d /usr/local/opt/gettext/ && echo y),y)
     ++		BASIC_CFLAGS += -I/usr/local/include -I/usr/local/opt/gettext/include
     ++		BASIC_LDFLAGS += -L/usr/local/lib -L/usr/local/opt/gettext/lib
     ++		ifeq ($(shell test -x /usr/local/opt/gettext/bin/msgfmt && echo y),y)
     ++			MSGFMT = /usr/local/opt/gettext/bin/msgfmt
     ++		endif
      +	endif
       endif
       ifeq ($(uname_S),SunOS)

 config.mak.uname | 13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

diff --git a/config.mak.uname b/config.mak.uname
index 0ab8e009383..1ea16e89288 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -133,8 +133,17 @@ ifeq ($(uname_S),Darwin)
 	HAVE_BSD_SYSCTL = YesPlease
 	FREAD_READS_DIRECTORIES = UnfortunatelyYes
 	HAVE_NS_GET_EXECUTABLE_PATH = YesPlease
-	BASIC_CFLAGS += -I/usr/local/include
-	BASIC_LDFLAGS += -L/usr/local/lib
+
+	# Workaround for `gettext` being keg-only and not even being linked via
+	# `brew link --force gettext`, should be obsolete as of
+	# https://github.com/Homebrew/homebrew-core/pull/53489
+	ifeq ($(shell test -d /usr/local/opt/gettext/ && echo y),y)
+		BASIC_CFLAGS += -I/usr/local/include -I/usr/local/opt/gettext/include
+		BASIC_LDFLAGS += -L/usr/local/lib -L/usr/local/opt/gettext/lib
+		ifeq ($(shell test -x /usr/local/opt/gettext/bin/msgfmt && echo y),y)
+			MSGFMT = /usr/local/opt/gettext/bin/msgfmt
+		endif
+	endif
 endif
 ifeq ($(uname_S),SunOS)
 	NEEDS_SOCKET = YesPlease

base-commit: e870325ee8575d5c3d7afe0ba2c9be072c692b65
-- 
gitgitgadget