Skip to content

Commit f5012d5

Browse files
committed
Update iconv.m4
1 parent d6921ed commit f5012d5

File tree

1 file changed

+116
-90
lines changed

1 file changed

+116
-90
lines changed

m4/iconv.m4

Lines changed: 116 additions & 90 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,19 @@
1-
# iconv.m4 serial 18 (gettext-0.18.2)
2-
dnl Copyright (C) 2000-2002, 2007-2012 Free Software Foundation, Inc.
1+
# iconv.m4
2+
# serial 27
3+
dnl Copyright (C) 2000-2002, 2007-2014, 2016-2024 Free Software Foundation,
4+
dnl Inc.
35
dnl This file is free software; the Free Software Foundation
46
dnl gives unlimited permission to copy and/or distribute it,
57
dnl with or without modifications, as long as this notice is preserved.
68

79
dnl From Bruno Haible.
810

11+
AC_PREREQ([2.64])
12+
13+
dnl Note: AM_ICONV is documented in the GNU gettext manual
14+
dnl <https://www.gnu.org/software/gettext/manual/html_node/AM_005fICONV.html>.
15+
dnl Don't make changes that are incompatible with that documentation!
16+
917
AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
1018
[
1119
dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
@@ -31,7 +39,7 @@ AC_DEFUN([AM_ICONV_LINK],
3139
dnl because if the user has installed libiconv and not disabled its use
3240
dnl via --without-libiconv-prefix, he wants to use it. The first
3341
dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
34-
am_save_CPPFLAGS="$CPPFLAGS"
42+
gl_saved_CPPFLAGS="$CPPFLAGS"
3543
AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
3644
3745
AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
@@ -48,7 +56,7 @@ AC_DEFUN([AM_ICONV_LINK],
4856
iconv_close(cd);]])],
4957
[am_cv_func_iconv=yes])
5058
if test "$am_cv_func_iconv" != yes; then
51-
am_save_LIBS="$LIBS"
59+
gl_saved_LIBS="$LIBS"
5260
LIBS="$LIBS $LIBICONV"
5361
AC_LINK_IFELSE(
5462
[AC_LANG_PROGRAM(
@@ -61,38 +69,45 @@ AC_DEFUN([AM_ICONV_LINK],
6169
iconv_close(cd);]])],
6270
[am_cv_lib_iconv=yes]
6371
[am_cv_func_iconv=yes])
64-
LIBS="$am_save_LIBS"
72+
LIBS="$gl_saved_LIBS"
6573
fi
6674
])
6775
if test "$am_cv_func_iconv" = yes; then
6876
AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
6977
dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11,
7078
dnl Solaris 10.
71-
am_save_LIBS="$LIBS"
79+
gl_saved_LIBS="$LIBS"
7280
if test $am_cv_lib_iconv = yes; then
7381
LIBS="$LIBS $LIBICONV"
7482
fi
75-
AC_RUN_IFELSE(
76-
[AC_LANG_SOURCE([[
83+
am_cv_func_iconv_works=no
84+
for ac_iconv_const in '' 'const'; do
85+
AC_RUN_IFELSE(
86+
[AC_LANG_PROGRAM(
87+
[[
7788
#include <iconv.h>
7889
#include <string.h>
79-
int main ()
80-
{
81-
int result = 0;
82-
/* Test against AIX 5.1 bug: Failures are not distinguishable from successful
83-
returns. */
90+
91+
#ifndef ICONV_CONST
92+
# define ICONV_CONST $ac_iconv_const
93+
#endif
94+
]],
95+
[[int result = 0;
96+
/* Test against AIX 5.1...7.2 bug: Failures are not distinguishable from
97+
successful returns. This is even documented in
98+
<https://www.ibm.com/support/knowledgecenter/ssw_aix_72/i_bostechref/iconv.html> */
8499
{
85100
iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
86101
if (cd_utf8_to_88591 != (iconv_t)(-1))
87102
{
88-
static const char input[] = "\342\202\254"; /* EURO SIGN */
103+
static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */
89104
char buf[10];
90-
const char *inptr = input;
105+
ICONV_CONST char *inptr = input;
91106
size_t inbytesleft = strlen (input);
92107
char *outptr = buf;
93108
size_t outbytesleft = sizeof (buf);
94109
size_t res = iconv (cd_utf8_to_88591,
95-
(char **) &inptr, &inbytesleft,
110+
&inptr, &inbytesleft,
96111
&outptr, &outbytesleft);
97112
if (res == 0)
98113
result |= 1;
@@ -105,14 +120,14 @@ int main ()
105120
iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
106121
if (cd_ascii_to_88591 != (iconv_t)(-1))
107122
{
108-
static const char input[] = "\263";
123+
static ICONV_CONST char input[] = "\263";
109124
char buf[10];
110-
const char *inptr = input;
125+
ICONV_CONST char *inptr = input;
111126
size_t inbytesleft = strlen (input);
112127
char *outptr = buf;
113128
size_t outbytesleft = sizeof (buf);
114129
size_t res = iconv (cd_ascii_to_88591,
115-
(char **) &inptr, &inbytesleft,
130+
&inptr, &inbytesleft,
116131
&outptr, &outbytesleft);
117132
if (res == 0)
118133
result |= 2;
@@ -124,14 +139,14 @@ int main ()
124139
iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
125140
if (cd_88591_to_utf8 != (iconv_t)(-1))
126141
{
127-
static const char input[] = "\304";
142+
static ICONV_CONST char input[] = "\304";
128143
static char buf[2] = { (char)0xDE, (char)0xAD };
129-
const char *inptr = input;
144+
ICONV_CONST char *inptr = input;
130145
size_t inbytesleft = 1;
131146
char *outptr = buf;
132147
size_t outbytesleft = 1;
133148
size_t res = iconv (cd_88591_to_utf8,
134-
(char **) &inptr, &inbytesleft,
149+
&inptr, &inbytesleft,
135150
&outptr, &outbytesleft);
136151
if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
137152
result |= 4;
@@ -144,14 +159,14 @@ int main ()
144159
iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
145160
if (cd_88591_to_utf8 != (iconv_t)(-1))
146161
{
147-
static const char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
162+
static ICONV_CONST char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
148163
char buf[50];
149-
const char *inptr = input;
164+
ICONV_CONST char *inptr = input;
150165
size_t inbytesleft = strlen (input);
151166
char *outptr = buf;
152167
size_t outbytesleft = sizeof (buf);
153168
size_t res = iconv (cd_88591_to_utf8,
154-
(char **) &inptr, &inbytesleft,
169+
&inptr, &inbytesleft,
155170
&outptr, &outbytesleft);
156171
if ((int)res > 0)
157172
result |= 8;
@@ -161,28 +176,37 @@ int main ()
161176
#endif
162177
/* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
163178
provided. */
164-
if (/* Try standardized names. */
165-
iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
166-
/* Try IRIX, OSF/1 names. */
167-
&& iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
168-
/* Try AIX names. */
169-
&& iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
170-
/* Try HP-UX names. */
171-
&& iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
172-
result |= 16;
179+
{
180+
/* Try standardized names. */
181+
iconv_t cd1 = iconv_open ("UTF-8", "EUC-JP");
182+
/* Try IRIX, OSF/1 names. */
183+
iconv_t cd2 = iconv_open ("UTF-8", "eucJP");
184+
/* Try AIX names. */
185+
iconv_t cd3 = iconv_open ("UTF-8", "IBM-eucJP");
186+
/* Try HP-UX names. */
187+
iconv_t cd4 = iconv_open ("utf8", "eucJP");
188+
if (cd1 == (iconv_t)(-1) && cd2 == (iconv_t)(-1)
189+
&& cd3 == (iconv_t)(-1) && cd4 == (iconv_t)(-1))
190+
result |= 16;
191+
if (cd1 != (iconv_t)(-1))
192+
iconv_close (cd1);
193+
if (cd2 != (iconv_t)(-1))
194+
iconv_close (cd2);
195+
if (cd3 != (iconv_t)(-1))
196+
iconv_close (cd3);
197+
if (cd4 != (iconv_t)(-1))
198+
iconv_close (cd4);
199+
}
173200
return result;
174-
}]])],
175-
[am_cv_func_iconv_works=yes],
176-
[am_cv_func_iconv_works=no],
177-
[
178-
changequote(,)dnl
179-
case "$host_os" in
180-
aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
181-
*) am_cv_func_iconv_works="guessing yes" ;;
182-
esac
183-
changequote([,])dnl
184-
])
185-
LIBS="$am_save_LIBS"
201+
]])],
202+
[am_cv_func_iconv_works=yes], ,
203+
[case "$host_os" in
204+
aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
205+
*) am_cv_func_iconv_works="guessing yes" ;;
206+
esac])
207+
test "$am_cv_func_iconv_works" = no || break
208+
done
209+
LIBS="$gl_saved_LIBS"
186210
])
187211
case "$am_cv_func_iconv_works" in
188212
*no) am_func_iconv=no am_cv_lib_iconv=no ;;
@@ -201,68 +225,70 @@ changequote([,])dnl
201225
else
202226
dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
203227
dnl either.
204-
CPPFLAGS="$am_save_CPPFLAGS"
228+
CPPFLAGS="$gl_saved_CPPFLAGS"
205229
LIBICONV=
206230
LTLIBICONV=
207231
fi
208232
AC_SUBST([LIBICONV])
209233
AC_SUBST([LTLIBICONV])
210234
])
211235

212-
dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
213-
dnl avoid warnings like
236+
dnl Define AM_ICONV using AC_DEFUN_ONCE, in order to avoid warnings like
214237
dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
215-
dnl This is tricky because of the way 'aclocal' is implemented:
216-
dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
217-
dnl Otherwise aclocal's initial scan pass would miss the macro definition.
218-
dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
219-
dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
220-
dnl warnings.
221-
m4_define([gl_iconv_AC_DEFUN],
222-
m4_version_prereq([2.64],
223-
[[AC_DEFUN_ONCE(
224-
[$1], [$2])]],
225-
[m4_ifdef([gl_00GNULIB],
226-
[[AC_DEFUN_ONCE(
227-
[$1], [$2])]],
228-
[[AC_DEFUN(
229-
[$1], [$2])]])]))
230-
gl_iconv_AC_DEFUN([AM_ICONV],
238+
AC_DEFUN_ONCE([AM_ICONV],
231239
[
232240
AM_ICONV_LINK
233241
if test "$am_cv_func_iconv" = yes; then
234-
AC_MSG_CHECKING([for iconv declaration])
235-
AC_CACHE_VAL([am_cv_proto_iconv], [
236-
AC_COMPILE_IFELSE(
237-
[AC_LANG_PROGRAM(
238-
[[
242+
AC_CACHE_CHECK([whether iconv is compatible with its POSIX signature],
243+
[gl_cv_iconv_nonconst],
244+
[AC_COMPILE_IFELSE(
245+
[AC_LANG_PROGRAM(
246+
[[
239247
#include <stdlib.h>
240248
#include <iconv.h>
241249
extern
242250
#ifdef __cplusplus
243251
"C"
244252
#endif
245-
#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
246253
size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
247-
#else
248-
size_t iconv();
249-
#endif
250-
]],
251-
[[]])],
252-
[am_cv_proto_iconv_arg1=""],
253-
[am_cv_proto_iconv_arg1="const"])
254-
am_cv_proto_iconv="extern size_t iconv (iconv_t cd, $am_cv_proto_iconv_arg1 char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);"])
255-
am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
256-
AC_MSG_RESULT([
257-
$am_cv_proto_iconv])
258-
AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
259-
[Define as const if the declaration of iconv() needs const.])
260-
dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
261-
m4_ifdef([gl_ICONV_H_DEFAULTS],
262-
[AC_REQUIRE([gl_ICONV_H_DEFAULTS])
263-
if test -n "$am_cv_proto_iconv_arg1"; then
264-
ICONV_CONST="const"
265-
fi
254+
]],
255+
[[]])],
256+
[gl_cv_iconv_nonconst=yes],
257+
[gl_cv_iconv_nonconst=no])
266258
])
259+
else
260+
dnl When compiling GNU libiconv on a system that does not have iconv yet,
261+
dnl pick the POSIX compliant declaration without 'const'.
262+
gl_cv_iconv_nonconst=yes
263+
fi
264+
if test $gl_cv_iconv_nonconst = yes; then
265+
iconv_arg1=""
266+
else
267+
iconv_arg1="const"
268+
fi
269+
AC_DEFINE_UNQUOTED([ICONV_CONST], [$iconv_arg1],
270+
[Define as const if the declaration of iconv() needs const.])
271+
dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
272+
m4_ifdef([gl_ICONV_H_DEFAULTS],
273+
[AC_REQUIRE([gl_ICONV_H_DEFAULTS])
274+
if test $gl_cv_iconv_nonconst != yes; then
275+
ICONV_CONST="const"
276+
fi
277+
])
278+
279+
dnl A summary result, for those packages which want to print a summary at the
280+
dnl end of the configuration.
281+
if test "$am_func_iconv" = yes; then
282+
if test -n "$LIBICONV"; then
283+
am_cv_func_iconv_summary='yes, in libiconv'
284+
else
285+
am_cv_func_iconv_summary='yes, in libc'
286+
fi
287+
else
288+
if test "$am_cv_func_iconv" = yes; then
289+
am_cv_func_iconv_summary='not working, consider installing GNU libiconv'
290+
else
291+
am_cv_func_iconv_summary='no, consider installing GNU libiconv'
292+
fi
267293
fi
268294
])

0 commit comments

Comments
 (0)