aboutsummaryrefslogtreecommitdiff
path: root/m4/iconv.m4
diff options
context:
space:
mode:
Diffstat (limited to 'm4/iconv.m4')
-rw-r--r--m4/iconv.m4245
1 files changed, 216 insertions, 29 deletions
diff --git a/m4/iconv.m4 b/m4/iconv.m4
index 654c415..e593b72 100644
--- a/m4/iconv.m4
+++ b/m4/iconv.m4
@@ -1,5 +1,6 @@
1# iconv.m4 serial AM4 (gettext-0.11.3) 1# iconv.m4 serial 21
2dnl Copyright (C) 2000-2002 Free Software Foundation, Inc. 2dnl Copyright (C) 2000-2002, 2007-2014, 2016-2020 Free Software Foundation,
3dnl Inc.
3dnl This file is free software; the Free Software Foundation 4dnl This file is free software; the Free Software Foundation
4dnl gives unlimited permission to copy and/or distribute it, 5dnl gives unlimited permission to copy and/or distribute it,
5dnl with or without modifications, as long as this notice is preserved. 6dnl with or without modifications, as long as this notice is preserved.
@@ -21,6 +22,7 @@ AC_DEFUN([AM_ICONV_LINK],
21[ 22[
22 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and 23 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
23 dnl those with the standalone portable GNU libiconv installed). 24 dnl those with the standalone portable GNU libiconv installed).
25 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
24 26
25 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV 27 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
26 dnl accordingly. 28 dnl accordingly.
@@ -29,34 +31,185 @@ AC_DEFUN([AM_ICONV_LINK],
29 dnl Add $INCICONV to CPPFLAGS before performing the following checks, 31 dnl Add $INCICONV to CPPFLAGS before performing the following checks,
30 dnl because if the user has installed libiconv and not disabled its use 32 dnl because if the user has installed libiconv and not disabled its use
31 dnl via --without-libiconv-prefix, he wants to use it. The first 33 dnl via --without-libiconv-prefix, he wants to use it. The first
32 dnl AC_TRY_LINK will then fail, the second AC_TRY_LINK will succeed. 34 dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
33 am_save_CPPFLAGS="$CPPFLAGS" 35 am_save_CPPFLAGS="$CPPFLAGS"
34 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV]) 36 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
35 37
36 AC_CACHE_CHECK(for iconv, am_cv_func_iconv, [ 38 AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
37 am_cv_func_iconv="no, consider installing GNU libiconv" 39 am_cv_func_iconv="no, consider installing GNU libiconv"
38 am_cv_lib_iconv=no 40 am_cv_lib_iconv=no
39 AC_TRY_LINK([#include <stdlib.h> 41 AC_LINK_IFELSE(
40#include <iconv.h>], 42 [AC_LANG_PROGRAM(
41 [iconv_t cd = iconv_open("",""); 43 [[
42 iconv(cd,NULL,NULL,NULL,NULL); 44#include <stdlib.h>
43 iconv_close(cd);], 45#include <iconv.h>
44 am_cv_func_iconv=yes) 46 ]],
47 [[iconv_t cd = iconv_open("","");
48 iconv(cd,NULL,NULL,NULL,NULL);
49 iconv_close(cd);]])],
50 [am_cv_func_iconv=yes])
45 if test "$am_cv_func_iconv" != yes; then 51 if test "$am_cv_func_iconv" != yes; then
46 am_save_LIBS="$LIBS" 52 am_save_LIBS="$LIBS"
47 LIBS="$LIBS $LIBICONV" 53 LIBS="$LIBS $LIBICONV"
48 AC_TRY_LINK([#include <stdlib.h> 54 AC_LINK_IFELSE(
49#include <iconv.h>], 55 [AC_LANG_PROGRAM(
50 [iconv_t cd = iconv_open("",""); 56 [[
51 iconv(cd,NULL,NULL,NULL,NULL); 57#include <stdlib.h>
52 iconv_close(cd);], 58#include <iconv.h>
53 am_cv_lib_iconv=yes 59 ]],
54 am_cv_func_iconv=yes) 60 [[iconv_t cd = iconv_open("","");
61 iconv(cd,NULL,NULL,NULL,NULL);
62 iconv_close(cd);]])],
63 [am_cv_lib_iconv=yes]
64 [am_cv_func_iconv=yes])
55 LIBS="$am_save_LIBS" 65 LIBS="$am_save_LIBS"
56 fi 66 fi
57 ]) 67 ])
58 if test "$am_cv_func_iconv" = yes; then 68 if test "$am_cv_func_iconv" = yes; then
59 AC_DEFINE(HAVE_ICONV, 1, [Define if you have the iconv() function.]) 69 AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
70 dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11,
71 dnl Solaris 10.
72 am_save_LIBS="$LIBS"
73 if test $am_cv_lib_iconv = yes; then
74 LIBS="$LIBS $LIBICONV"
75 fi
76 am_cv_func_iconv_works=no
77 for ac_iconv_const in '' 'const'; do
78 AC_RUN_IFELSE(
79 [AC_LANG_PROGRAM(
80 [[
81#include <iconv.h>
82#include <string.h>
83
84#ifndef ICONV_CONST
85# define ICONV_CONST $ac_iconv_const
86#endif
87 ]],
88 [[int result = 0;
89 /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
90 returns. */
91 {
92 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
93 if (cd_utf8_to_88591 != (iconv_t)(-1))
94 {
95 static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */
96 char buf[10];
97 ICONV_CONST char *inptr = input;
98 size_t inbytesleft = strlen (input);
99 char *outptr = buf;
100 size_t outbytesleft = sizeof (buf);
101 size_t res = iconv (cd_utf8_to_88591,
102 &inptr, &inbytesleft,
103 &outptr, &outbytesleft);
104 if (res == 0)
105 result |= 1;
106 iconv_close (cd_utf8_to_88591);
107 }
108 }
109 /* Test against Solaris 10 bug: Failures are not distinguishable from
110 successful returns. */
111 {
112 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
113 if (cd_ascii_to_88591 != (iconv_t)(-1))
114 {
115 static ICONV_CONST char input[] = "\263";
116 char buf[10];
117 ICONV_CONST char *inptr = input;
118 size_t inbytesleft = strlen (input);
119 char *outptr = buf;
120 size_t outbytesleft = sizeof (buf);
121 size_t res = iconv (cd_ascii_to_88591,
122 &inptr, &inbytesleft,
123 &outptr, &outbytesleft);
124 if (res == 0)
125 result |= 2;
126 iconv_close (cd_ascii_to_88591);
127 }
128 }
129 /* Test against AIX 6.1..7.1 bug: Buffer overrun. */
130 {
131 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
132 if (cd_88591_to_utf8 != (iconv_t)(-1))
133 {
134 static ICONV_CONST char input[] = "\304";
135 static char buf[2] = { (char)0xDE, (char)0xAD };
136 ICONV_CONST char *inptr = input;
137 size_t inbytesleft = 1;
138 char *outptr = buf;
139 size_t outbytesleft = 1;
140 size_t res = iconv (cd_88591_to_utf8,
141 &inptr, &inbytesleft,
142 &outptr, &outbytesleft);
143 if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
144 result |= 4;
145 iconv_close (cd_88591_to_utf8);
146 }
147 }
148#if 0 /* This bug could be worked around by the caller. */
149 /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
150 {
151 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
152 if (cd_88591_to_utf8 != (iconv_t)(-1))
153 {
154 static ICONV_CONST char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
155 char buf[50];
156 ICONV_CONST char *inptr = input;
157 size_t inbytesleft = strlen (input);
158 char *outptr = buf;
159 size_t outbytesleft = sizeof (buf);
160 size_t res = iconv (cd_88591_to_utf8,
161 &inptr, &inbytesleft,
162 &outptr, &outbytesleft);
163 if ((int)res > 0)
164 result |= 8;
165 iconv_close (cd_88591_to_utf8);
166 }
167 }
168#endif
169 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
170 provided. */
171 {
172 /* Try standardized names. */
173 iconv_t cd1 = iconv_open ("UTF-8", "EUC-JP");
174 /* Try IRIX, OSF/1 names. */
175 iconv_t cd2 = iconv_open ("UTF-8", "eucJP");
176 /* Try AIX names. */
177 iconv_t cd3 = iconv_open ("UTF-8", "IBM-eucJP");
178 /* Try HP-UX names. */
179 iconv_t cd4 = iconv_open ("utf8", "eucJP");
180 if (cd1 == (iconv_t)(-1) && cd2 == (iconv_t)(-1)
181 && cd3 == (iconv_t)(-1) && cd4 == (iconv_t)(-1))
182 result |= 16;
183 if (cd1 != (iconv_t)(-1))
184 iconv_close (cd1);
185 if (cd2 != (iconv_t)(-1))
186 iconv_close (cd2);
187 if (cd3 != (iconv_t)(-1))
188 iconv_close (cd3);
189 if (cd4 != (iconv_t)(-1))
190 iconv_close (cd4);
191 }
192 return result;
193]])],
194 [am_cv_func_iconv_works=yes], ,
195 [case "$host_os" in
196 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
197 *) am_cv_func_iconv_works="guessing yes" ;;
198 esac])
199 test "$am_cv_func_iconv_works" = no || break
200 done
201 LIBS="$am_save_LIBS"
202 ])
203 case "$am_cv_func_iconv_works" in
204 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
205 *) am_func_iconv=yes ;;
206 esac
207 else
208 am_func_iconv=no am_cv_lib_iconv=no
209 fi
210 if test "$am_func_iconv" = yes; then
211 AC_DEFINE([HAVE_ICONV], [1],
212 [Define if you have the iconv() function and it works.])
60 fi 213 fi
61 if test "$am_cv_lib_iconv" = yes; then 214 if test "$am_cv_lib_iconv" = yes; then
62 AC_MSG_CHECKING([how to link with libiconv]) 215 AC_MSG_CHECKING([how to link with libiconv])
@@ -68,34 +221,68 @@ AC_DEFUN([AM_ICONV_LINK],
68 LIBICONV= 221 LIBICONV=
69 LTLIBICONV= 222 LTLIBICONV=
70 fi 223 fi
71 AC_SUBST(LIBICONV) 224 AC_SUBST([LIBICONV])
72 AC_SUBST(LTLIBICONV) 225 AC_SUBST([LTLIBICONV])
73]) 226])
74 227
75AC_DEFUN([AM_ICONV], 228dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
229dnl avoid warnings like
230dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
231dnl This is tricky because of the way 'aclocal' is implemented:
232dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
233dnl Otherwise aclocal's initial scan pass would miss the macro definition.
234dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
235dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
236dnl warnings.
237m4_define([gl_iconv_AC_DEFUN],
238 m4_version_prereq([2.64],
239 [[AC_DEFUN_ONCE(
240 [$1], [$2])]],
241 [m4_ifdef([gl_00GNULIB],
242 [[AC_DEFUN_ONCE(
243 [$1], [$2])]],
244 [[AC_DEFUN(
245 [$1], [$2])]])]))
246gl_iconv_AC_DEFUN([AM_ICONV],
76[ 247[
77 AM_ICONV_LINK 248 AM_ICONV_LINK
78 if test "$am_cv_func_iconv" = yes; then 249 if test "$am_cv_func_iconv" = yes; then
79 AC_MSG_CHECKING([for iconv declaration]) 250 AC_MSG_CHECKING([for iconv declaration])
80 AC_CACHE_VAL(am_cv_proto_iconv, [ 251 AC_CACHE_VAL([am_cv_proto_iconv], [
81 AC_TRY_COMPILE([ 252 AC_COMPILE_IFELSE(
253 [AC_LANG_PROGRAM(
254 [[
82#include <stdlib.h> 255#include <stdlib.h>
83#include <iconv.h> 256#include <iconv.h>
84extern 257extern
85#ifdef __cplusplus 258#ifdef __cplusplus
86"C" 259"C"
87#endif 260#endif
88#if defined(__STDC__) || defined(__cplusplus) 261#if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
89size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft); 262size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
90#else 263#else
91size_t iconv(); 264size_t iconv();
92#endif 265#endif
93], [], am_cv_proto_iconv_arg1="", am_cv_proto_iconv_arg1="const") 266 ]],
267 [[]])],
268 [am_cv_proto_iconv_arg1=""],
269 [am_cv_proto_iconv_arg1="const"])
94 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);"]) 270 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);"])
95 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'` 271 am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
96 AC_MSG_RESULT([$]{ac_t:- 272 AC_MSG_RESULT([
97 }[$]am_cv_proto_iconv) 273 $am_cv_proto_iconv])
98 AC_DEFINE_UNQUOTED(ICONV_CONST, $am_cv_proto_iconv_arg1, 274 else
99 [Define as const if the declaration of iconv() needs const.]) 275 dnl When compiling GNU libiconv on a system that does not have iconv yet,
276 dnl pick the POSIX compliant declaration without 'const'.
277 am_cv_proto_iconv_arg1=""
100 fi 278 fi
279 AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
280 [Define as const if the declaration of iconv() needs const.])
281 dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
282 m4_ifdef([gl_ICONV_H_DEFAULTS],
283 [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
284 if test -n "$am_cv_proto_iconv_arg1"; then
285 ICONV_CONST="const"
286 fi
287 ])
101]) 288])