macOS: make Homebrew use configurable
On macOS we opportunistically use Homebrew-installed versions of gettext(3) and msgfmt(1). Make that behavior configurable by providing make variables to disable Homebrew usage (NO_HOMEBREW) and to allow using a non-default installation location (HOMEBREW_PREFIX). Include and link only the gettext keg via the symlink opt/gettext pointing to its installed version instead of using the Homebrew prefix. This is simpler and prevents accidentally including other libraries. Suggested-by: Carlo Marcelo Arenas Belón <carenas@gmail.com> Suggested-by: Torsten Bögershausen <tboegi@web.de> Signed-off-by: René Scharfe <l.s.r@web.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
René Scharfe committed
Dec 24, 2025 at 09:02 UTC
363837afe75e7d6f6efd53775887dff67fb9e5d6
2 files changed
+22
-22
Makefile
+18
@@ -100,6 +100,12 @@ include shared.mak
100
# specify your own (or DarwinPort's) include directories and
101
# library directories by defining CFLAGS and LDFLAGS appropriately.
102
#
103
+# Define NO_HOMEBREW if you don't want to use gettext and msgfmt
104
+# installed by Homebrew.
105
+#
106
+# Define HOMEBREW_PREFIX if you have Homebrew installed in a non-default
107
+# location on macOS or on Linux and want to use it.
108
+#
109
# Define NO_APPLE_COMMON_CRYPTO if you are building on Darwin/Mac OS X
110
# and do not want to use Apple's CommonCrypto library. This allows you
111
# to provide your own OpenSSL library, for example from MacPorts.
@@ -1690,6 +1696,18 @@ ifeq ($(uname_S),Darwin)
1696
PTHREAD_LIBS =
1697
endif
1698
1699
+ifndef NO_HOMEBREW
1700
+ifdef HOMEBREW_PREFIX
1701
+ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/gettext && echo y),y)
1702
+ BASIC_CFLAGS += -I$(HOMEBREW_PREFIX)/opt/gettext/include
1703
+ BASIC_LDFLAGS += -L$(HOMEBREW_PREFIX)/opt/gettext/lib
1704
+endif
1705
+ifeq ($(shell test -x $(HOMEBREW_PREFIX)/opt/gettext/msgfmt && echo y),y)
1706
+ MSGFMT = $(HOMEBREW_PREFIX)/opt/gettext/msgfmt
1707
+endif
1708
+endif
1709
+endif
1710
+
1711
ifdef NO_LIBGEN_H
1712
COMPAT_CFLAGS += -DNO_LIBGEN_H
1713
COMPAT_OBJS += compat/basename.o
config.mak.uname
+4
-22
@@ -149,28 +149,10 @@ ifeq ($(uname_S),Darwin)
149
CSPRNG_METHOD = arc4random
150
USE_ENHANCED_BASIC_REGULAR_EXPRESSIONS = YesPlease
151
152
- # Workaround for `gettext` being keg-only and not even being linked via
153
- # `brew link --force gettext`, should be obsolete as of
154
- # https://github.com/Homebrew/homebrew-core/pull/53489
155
- ifeq ($(shell test -d /usr/local/opt/gettext/ && echo y),y)
156
- BASIC_CFLAGS += -I/usr/local/include -I/usr/local/opt/gettext/include
157
- BASIC_LDFLAGS += -L/usr/local/lib -L/usr/local/opt/gettext/lib
158
- ifeq ($(shell test -x /usr/local/opt/gettext/bin/msgfmt && echo y),y)
159
- MSGFMT = /usr/local/opt/gettext/bin/msgfmt
160
- endif
161
- # On newer ARM-based machines the default installation path has changed to
162
- # /opt/homebrew. Include it in our search paths so that the user does not
163
- # have to configure this manually.
164
- #
165
- # Note that we do not employ the same workaround as above where we manually
166
- # add gettext. The issue was fixed more than three years ago by now, and at
167
- # that point there haven't been any ARM-based Macs yet.
168
- else ifeq ($(shell test -d /opt/homebrew/ && echo y),y)
169
- BASIC_CFLAGS += -I/opt/homebrew/include
170
- BASIC_LDFLAGS += -L/opt/homebrew/lib
171
- ifeq ($(shell test -x /opt/homebrew/bin/msgfmt && echo y),y)
172
- MSGFMT = /opt/homebrew/bin/msgfmt
173
- endif
152
+ ifeq ($(uname_M),arm64)
153
+ HOMEBREW_PREFIX = /opt/homebrew
154
+ else
155
+ HOMEBREW_PREFIX = /usr/local
156
endif
157
158
# The builtin FSMonitor on MacOS builds upon Simple-IPC. Both require