utf8.c: enable workaround for iconv under macOS 14/15

The previous commit introduced a workaround in utf8.c to deal
with broken iconv implementations.

It is enabled when a MacOS version is used that has a buggy
iconv library and there is no external library provided
(and linked against) from neither MacPorts nor Homebrew nor Fink.
For Homebrew, MacPorts and Fink we check if libiconv exist.
Introduce 2 new macros: HAS_GOOD_LIBICONV and NEEDS_GOOD_LIBICONV.

For Homebrew HAS_GOOD_LIBICONV is set when the libiconv directory
exist.
MacPorts can be installed with or without libiconv, so check if
libiconv.dylib exists (which is a softlink)

Fink compiles and installs libiconv by default.
Note that a fresh installation of Fink now defaults to /opt/sw.
Older versions used /sw as default, so leave the check and setting
of BASIC_CFLAGS and BASIC_LDFLAGS as is.
For the new default check for the existance of /opt/sw as well.
Add a check for /opt/sw/lib/libiconv.dylib which sets HAS_GOOD_LIBICONV

Signed-off-by: Torsten Bögershausen <tboegi@web.de>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Torsten Bögershausen
2026-01-12 17:25:53 +01:00
committed by Junio C Hamano
parent d0cec08d70
commit d281241518
2 changed files with 17 additions and 0 deletions

View File

@@ -1687,11 +1687,21 @@ ifeq ($(uname_S),Darwin)
BASIC_CFLAGS += -I/sw/include BASIC_CFLAGS += -I/sw/include
BASIC_LDFLAGS += -L/sw/lib BASIC_LDFLAGS += -L/sw/lib
endif endif
ifeq ($(shell test -d /opt/sw/lib && echo y),y)
BASIC_CFLAGS += -I/opt/sw/include
BASIC_LDFLAGS += -L/opt/sw/lib
ifeq ($(shell test -e /opt/sw/lib/libiconv.dylib && echo y),y)
HAS_GOOD_LIBICONV = Yes
endif
endif
endif endif
ifndef NO_DARWIN_PORTS ifndef NO_DARWIN_PORTS
ifeq ($(shell test -d /opt/local/lib && echo y),y) ifeq ($(shell test -d /opt/local/lib && echo y),y)
BASIC_CFLAGS += -I/opt/local/include BASIC_CFLAGS += -I/opt/local/include
BASIC_LDFLAGS += -L/opt/local/lib BASIC_LDFLAGS += -L/opt/local/lib
ifeq ($(shell test -e /opt/local/lib/libiconv.dylib && echo y),y)
HAS_GOOD_LIBICONV = Yes
endif
endif endif
endif endif
ifndef NO_APPLE_COMMON_CRYPTO ifndef NO_APPLE_COMMON_CRYPTO
@@ -1714,6 +1724,7 @@ endif
ifdef USE_HOMEBREW_LIBICONV ifdef USE_HOMEBREW_LIBICONV
ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/libiconv && echo y),y) ifeq ($(shell test -d $(HOMEBREW_PREFIX)/opt/libiconv && echo y),y)
ICONVDIR ?= $(HOMEBREW_PREFIX)/opt/libiconv ICONVDIR ?= $(HOMEBREW_PREFIX)/opt/libiconv
HAS_GOOD_LIBICONV = Yes
endif endif
endif endif
endif endif
@@ -1859,6 +1870,11 @@ ifndef NO_ICONV
endif endif
EXTLIBS += $(ICONV_LINK) -liconv EXTLIBS += $(ICONV_LINK) -liconv
endif endif
ifdef NEEDS_GOOD_LIBICONV
ifndef HAS_GOOD_LIBICONV
BASIC_CFLAGS += -DICONV_RESTART_RESET
endif
endif
endif endif
ifdef ICONV_OMITS_BOM ifdef ICONV_OMITS_BOM
BASIC_CFLAGS += -DICONV_OMITS_BOM BASIC_CFLAGS += -DICONV_OMITS_BOM

View File

@@ -157,6 +157,7 @@ ifeq ($(uname_S),Darwin)
endif endif
ifeq ($(shell test "$(DARWIN_MAJOR_VERSION)" -ge 24 && echo 1),1) ifeq ($(shell test "$(DARWIN_MAJOR_VERSION)" -ge 24 && echo 1),1)
USE_HOMEBREW_LIBICONV = UnfortunatelyYes USE_HOMEBREW_LIBICONV = UnfortunatelyYes
NEEDS_GOOD_LIBICONV = UnfortunatelyYes
endif endif
# The builtin FSMonitor on MacOS builds upon Simple-IPC. Both require # The builtin FSMonitor on MacOS builds upon Simple-IPC. Both require