build: use a UTF-8 locale for builtin icon cache generation

gtk-update-icon-cache may need to run in a UTF-8 locale when generating
gtkbuiltincache.h. Otherwise GLib can fail to convert UTF-8 output in
ASCII locales such as 646.

Choose a usable UTF-8 locale for this rule, while allowing packagers to
override it with GTK_UPDATE_ICON_CACHE_LOCALE. If no known UTF-8 locale
is available, fall back to the previous behavior.

This is based on the build fix carried by NetBSD pkgsrc for GTK2, but
avoids hard-coding en_US.UTF-8 so Debian, Gentoo, Arch and other systems
can use their available UTF-8 locale.

Ported-from: NetBSD pkgsrc x11/gtk2 patch-gtk_Makefile.in
This commit is contained in:
Daemonratte 2026-04-30 11:05:21 +02:00
commit 8ea53af676

View file

@ -1464,10 +1464,25 @@ endif
gtkbuiltincache.h: @REBUILD@ stamp-icons
$(MAKE) $(AM_MAKEFLAGS) gtk-update-icon-cache$(EXEEXT)
$(gtk_update_icon_cache_program) --force --ignore-theme-index \
--include-image-data \
--source builtin_icons stock-icons > gtkbuiltincache.h.tmp && \
mv gtkbuiltincache.h.tmp gtkbuiltincache.h
{ lc_all=$${GTK_UPDATE_ICON_CACHE_LOCALE-}; \
if test -z "$$lc_all"; then \
for locale in C.UTF-8 C.utf8 en_US.UTF-8 en_US.utf8; do \
if LC_ALL=$$locale locale charmap >/dev/null 2>&1; then \
lc_all=$$locale; \
break; \
fi; \
done; \
fi; \
if test -n "$$lc_all"; then \
LC_ALL=$$lc_all $(gtk_update_icon_cache_program) --force --ignore-theme-index \
--include-image-data \
--source builtin_icons stock-icons > gtkbuiltincache.h.tmp; \
else \
$(gtk_update_icon_cache_program) --force --ignore-theme-index \
--include-image-data \
--source builtin_icons stock-icons > gtkbuiltincache.h.tmp; \
fi; \
} && mv gtkbuiltincache.h.tmp gtkbuiltincache.h
EXTRA_DIST += \
$(STOCK_ICONS) \