Skip to content

Commit 1d8615d

Browse files
orlitzkycharmitro
authored andcommitted
ext/gettext/config.m4: symlink en_US.UTF-8 test bits to en_US for musl
The gettext() family of functions under musl does not support codeset suffixes like ".UTF-8", because the only codeset it understands is UTF-8. (Yes, it is annoying that it doesn't support the suffix for the codeset that it does understand; no, I am not in charge.) Thanks to this, we have six failing tests on musl, * FAIL Gettext basic test with en_US locale that should be on nearly every system [ext/gettext/tests/gettext_basic-enus.phpt] * FAIL Test if bindtextdomain() returns string id if no directory path is set( if directory path is 'null') [ext/gettext/tests/gettext_bindtextdomain-cwd.phpt] * FAIL Test dcgettext() functionality [ext/gettext/tests/gettext_dcgettext.phpt] * FAIL Test dgettext() functionality [ext/gettext/tests/gettext_dgettext.phpt] * FAIL Test if dngettext() returns the correct translations (optionally plural). [ext/gettext/tests/gettext_dngettext-plural.phpt] * FAIL Test ngettext() functionality [ext/gettext/tests/gettext_ngettext.phpt] These are all fixed by symlinking the en_US.UTF-8 message data to en_US, where musl is able to find it. This does not make the situation any better for developers (who don't know what libc their users will be running), but that problem is inhereted from C and is not the fault of the gettext extension. This partially addresses GH php#13696
1 parent 9334b5d commit 1d8615d

File tree

2 files changed

+40
-30
lines changed

2 files changed

+40
-30
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,9 @@ php
177177
/ext/*/configure.ac
178178
/ext/*/run-tests.php
179179

180+
# Generated by ./configure if libc might be musl
181+
/ext/gettext/tests/locale/en_US
182+
180183
# ------------------------------------------------------------------------------
181184
# Generated by Windows build system
182185
# ------------------------------------------------------------------------------

ext/gettext/config.m4

Lines changed: 37 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -5,49 +5,56 @@ PHP_ARG_WITH([gettext],
55

66
if test "$PHP_GETTEXT" != "no"; then
77
for i in $PHP_GETTEXT /usr/local /usr; do
8-
AS_IF([test -r $i/include/libintl.h], [GETTEXT_DIR=$i; break;])
8+
test -r $i/include/libintl.h && GETTEXT_DIR=$i && break
99
done
1010

11-
AS_VAR_IF([GETTEXT_DIR],,
12-
[AC_MSG_ERROR([Cannot locate header file libintl.h])])
11+
if test -z "$GETTEXT_DIR"; then
12+
AC_MSG_ERROR(Cannot locate header file libintl.h)
13+
fi
1314

1415
GETTEXT_LIBDIR=$GETTEXT_DIR/$PHP_LIBDIR
1516
GETTEXT_INCDIR=$GETTEXT_DIR/include
1617

1718
O_LDFLAGS=$LDFLAGS
1819
LDFLAGS="$LDFLAGS -L$GETTEXT_LIBDIR"
19-
AC_CHECK_LIB([intl], [bindtextdomain], [
20+
AC_CHECK_LIB(intl, bindtextdomain, [
2021
GETTEXT_LIBS=intl
2122
GETTEXT_CHECK_IN_LIB=intl
2223
],
23-
[AC_CHECK_LIB([c], [bindtextdomain], [
24+
[
25+
AC_CHECK_LIB(c, bindtextdomain, [
2426
GETTEXT_LIBS=
2527
GETTEXT_CHECK_IN_LIB=c
26-
],
27-
[AC_MSG_FAILURE([Unable to find required intl library for gettext.])])])
28-
29-
AC_DEFINE([HAVE_LIBINTL], [1], [Define to 1 if you have the 'intl' library.])
30-
PHP_NEW_EXTENSION([gettext], [gettext.c], [$ext_shared])
31-
PHP_SUBST([GETTEXT_SHARED_LIBADD])
32-
33-
PHP_ADD_INCLUDE([$GETTEXT_INCDIR])
34-
35-
AC_CHECK_LIB([$GETTEXT_CHECK_IN_LIB], [ngettext],
36-
[AC_DEFINE([HAVE_NGETTEXT], [1],
37-
[Define to 1 if you have the 'ngettext' function.])])
38-
AC_CHECK_LIB([$GETTEXT_CHECK_IN_LIB], [dngettext],
39-
[AC_DEFINE([HAVE_DNGETTEXT], [1],
40-
[Define to 1 if you have the 'dngettext' function.])])
41-
AC_CHECK_LIB([$GETTEXT_CHECK_IN_LIB], [dcngettext],
42-
[AC_DEFINE([HAVE_DCNGETTEXT], [1],
43-
[Define to 1 if you have the 'dcngettext' function.])])
44-
AC_CHECK_LIB([$GETTEXT_CHECK_IN_LIB], [bind_textdomain_codeset],
45-
[AC_DEFINE([HAVE_BIND_TEXTDOMAIN_CODESET], [1],
46-
[Define to 1 if you have the 'bind_textdomain_codeset' function.])])
28+
29+
dnl If libintl.h is provided by libc, it's possible that libc is musl.
30+
dnl The gettext family of functions under musl ignores the codeset
31+
dnl suffix on directories like "en_US.UTF-8"; instead they look only
32+
dnl in "en_US". To accomodate that, we symlink some test data from one
33+
dnl to the other.
34+
AC_MSG_NOTICE([symlinking en_US.UTF-8 messages to en_US in case you are on musl])
35+
_linkdest="${srcdir%/}"/ext/gettext/tests/locale/en_US
36+
AS_IF([test ! -e "${_linkdest}"],[
37+
ln -s en_US.UTF-8 "${_linkdest}"
38+
])
39+
],[
40+
AC_MSG_ERROR(Unable to find required gettext library)
41+
])
42+
]
43+
)
44+
45+
AC_DEFINE(HAVE_LIBINTL,1,[ ])
46+
PHP_NEW_EXTENSION(gettext, gettext.c, $ext_shared)
47+
PHP_SUBST(GETTEXT_SHARED_LIBADD)
48+
49+
PHP_ADD_INCLUDE($GETTEXT_INCDIR)
50+
51+
AC_CHECK_LIB($GETTEXT_CHECK_IN_LIB, ngettext, [AC_DEFINE(HAVE_NGETTEXT, 1, [ ])])
52+
AC_CHECK_LIB($GETTEXT_CHECK_IN_LIB, dngettext, [AC_DEFINE(HAVE_DNGETTEXT, 1, [ ])])
53+
AC_CHECK_LIB($GETTEXT_CHECK_IN_LIB, dcngettext, [AC_DEFINE(HAVE_DCNGETTEXT, 1, [ ])])
54+
AC_CHECK_LIB($GETTEXT_CHECK_IN_LIB, bind_textdomain_codeset, [AC_DEFINE(HAVE_BIND_TEXTDOMAIN_CODESET, 1, [ ])])
4755
LDFLAGS=$O_LDFLAGS
4856

49-
AS_VAR_IF([GETTEXT_LIBS],,,
50-
[PHP_ADD_LIBRARY_WITH_PATH([$GETTEXT_LIBS],
51-
[$GETTEXT_LIBDIR],
52-
[GETTEXT_SHARED_LIBADD])])
57+
if test -n "$GETTEXT_LIBS"; then
58+
PHP_ADD_LIBRARY_WITH_PATH($GETTEXT_LIBS, $GETTEXT_LIBDIR, GETTEXT_SHARED_LIBADD)
59+
fi
5360
fi

0 commit comments

Comments
 (0)