Subject: [PATCH v2 2/2] config.mak.uname: use iconv from Homebrew on macOS

From: René Scharfe <[email-masked]>
Date: Sat, 13 Dec 2025 19:42:42 +0100

The library function iconv(3) supplied with macOS versions 15.7.2
(Sequoia) and 26.1 (Tahoe) is unreliable when doing conversions from
ISO-2022-JP to UTF-8 in multiple steps; t3900 reports this breakage:

  not ok 17 - ISO-2022-JP should be shown in UTF-8 now
  not ok 25 - ISO-2022-JP should be shown in UTF-8 now
  not ok 38 - commit --fixup into ISO-2022-JP from UTF-8

As a workaround, use libiconv from Homebrew, if available.  Search it in
its default locations: /opt/homebrew for Apple Silicon and /usr/local
for macOS Intel, with the former taking precedence.  Respect ICONVDIR if
already set by the user, though.

Helped-by: Koji Nakamaru <[email-masked]>
Signed-off-by: René Scharfe <[email-masked]>
---
 Makefile         | 3 +++
 config.mak.uname | 7 +++++++
 2 files changed, 10 insertions(+)

diff --git a/Makefile b/Makefile
index dbd2760d18..80af832529 100644
--- a/Makefile
+++ b/Makefile
@@ -1707,6 +1707,9 @@ ifndef NO_HOMEBREW
         ifdef HOMEBREW_MSGFMT
 		MSGFMT = $(HOMEBREW_MSGFMT)
         endif
+        ifdef HOMEBREW_ICONVDIR
+		ICONVDIR ?= $(HOMEBREW_ICONVDIR)
+        endif
 endif
 
 ifdef NO_LIBGEN_H
diff --git a/config.mak.uname b/config.mak.uname
index a6521575ee..a926943141 100644
--- a/config.mak.uname
+++ b/config.mak.uname
@@ -172,6 +172,13 @@ ifeq ($(uname_S),Darwin)
                 endif
         endif
 
+        ifeq ($(shell test -d /usr/local/opt/libiconv/ && echo y),y)
+		HOMEBREW_ICONVDIR = /usr/local/opt/libiconv
+        endif
+        ifeq ($(shell test -d /opt/homebrew/opt/libiconv/ && echo y),y)
+		HOMEBREW_ICONVDIR = /opt/homebrew/opt/libiconv
+        endif
+
 	# The builtin FSMonitor on MacOS builds upon Simple-IPC.  Both require
 	# Unix domain sockets and PThreads.
         ifndef NO_PTHREADS
-- 
2.52.0