annotate CSP2/CSP2_env/env-d9b9114564458d9d-741b3de822f2aaca6c6caa4325c4afce/share/aclocal/iconv.m4 @ 68:5028fdace37b

planemo upload commit 2e9511a184a1ca667c7be0c6321a36dc4e3d116d
author jpayne
date Tue, 18 Mar 2025 16:23:26 -0400
parents
children
rev   line source
jpayne@68 1 # iconv.m4 serial 27
jpayne@68 2 dnl Copyright (C) 2000-2002, 2007-2014, 2016-2024 Free Software Foundation,
jpayne@68 3 dnl Inc.
jpayne@68 4 dnl This file is free software; the Free Software Foundation
jpayne@68 5 dnl gives unlimited permission to copy and/or distribute it,
jpayne@68 6 dnl with or without modifications, as long as this notice is preserved.
jpayne@68 7
jpayne@68 8 dnl From Bruno Haible.
jpayne@68 9
jpayne@68 10 AC_PREREQ([2.64])
jpayne@68 11
jpayne@68 12 dnl Note: AM_ICONV is documented in the GNU gettext manual
jpayne@68 13 dnl <https://www.gnu.org/software/gettext/manual/html_node/AM_005fICONV.html>.
jpayne@68 14 dnl Don't make changes that are incompatible with that documentation!
jpayne@68 15
jpayne@68 16 AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
jpayne@68 17 [
jpayne@68 18 dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
jpayne@68 19 AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
jpayne@68 20 AC_REQUIRE([AC_LIB_RPATH])
jpayne@68 21
jpayne@68 22 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
jpayne@68 23 dnl accordingly.
jpayne@68 24 AC_LIB_LINKFLAGS_BODY([iconv])
jpayne@68 25 ])
jpayne@68 26
jpayne@68 27 AC_DEFUN([AM_ICONV_LINK],
jpayne@68 28 [
jpayne@68 29 dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
jpayne@68 30 dnl those with the standalone portable GNU libiconv installed).
jpayne@68 31 AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
jpayne@68 32
jpayne@68 33 dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
jpayne@68 34 dnl accordingly.
jpayne@68 35 AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
jpayne@68 36
jpayne@68 37 dnl Add $INCICONV to CPPFLAGS before performing the following checks,
jpayne@68 38 dnl because if the user has installed libiconv and not disabled its use
jpayne@68 39 dnl via --without-libiconv-prefix, he wants to use it. The first
jpayne@68 40 dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
jpayne@68 41 gl_saved_CPPFLAGS="$CPPFLAGS"
jpayne@68 42 AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
jpayne@68 43
jpayne@68 44 AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
jpayne@68 45 am_cv_func_iconv="no, consider installing GNU libiconv"
jpayne@68 46 am_cv_lib_iconv=no
jpayne@68 47 AC_LINK_IFELSE(
jpayne@68 48 [AC_LANG_PROGRAM(
jpayne@68 49 [[
jpayne@68 50 #include <stdlib.h>
jpayne@68 51 #include <iconv.h>
jpayne@68 52 ]],
jpayne@68 53 [[iconv_t cd = iconv_open("","");
jpayne@68 54 iconv(cd,NULL,NULL,NULL,NULL);
jpayne@68 55 iconv_close(cd);]])],
jpayne@68 56 [am_cv_func_iconv=yes])
jpayne@68 57 if test "$am_cv_func_iconv" != yes; then
jpayne@68 58 gl_saved_LIBS="$LIBS"
jpayne@68 59 LIBS="$LIBS $LIBICONV"
jpayne@68 60 AC_LINK_IFELSE(
jpayne@68 61 [AC_LANG_PROGRAM(
jpayne@68 62 [[
jpayne@68 63 #include <stdlib.h>
jpayne@68 64 #include <iconv.h>
jpayne@68 65 ]],
jpayne@68 66 [[iconv_t cd = iconv_open("","");
jpayne@68 67 iconv(cd,NULL,NULL,NULL,NULL);
jpayne@68 68 iconv_close(cd);]])],
jpayne@68 69 [am_cv_lib_iconv=yes]
jpayne@68 70 [am_cv_func_iconv=yes])
jpayne@68 71 LIBS="$gl_saved_LIBS"
jpayne@68 72 fi
jpayne@68 73 ])
jpayne@68 74 if test "$am_cv_func_iconv" = yes; then
jpayne@68 75 AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
jpayne@68 76 dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11,
jpayne@68 77 dnl Solaris 10.
jpayne@68 78 gl_saved_LIBS="$LIBS"
jpayne@68 79 if test $am_cv_lib_iconv = yes; then
jpayne@68 80 LIBS="$LIBS $LIBICONV"
jpayne@68 81 fi
jpayne@68 82 am_cv_func_iconv_works=no
jpayne@68 83 for ac_iconv_const in '' 'const'; do
jpayne@68 84 AC_RUN_IFELSE(
jpayne@68 85 [AC_LANG_PROGRAM(
jpayne@68 86 [[
jpayne@68 87 #include <iconv.h>
jpayne@68 88 #include <string.h>
jpayne@68 89
jpayne@68 90 #ifndef ICONV_CONST
jpayne@68 91 # define ICONV_CONST $ac_iconv_const
jpayne@68 92 #endif
jpayne@68 93 ]],
jpayne@68 94 [[int result = 0;
jpayne@68 95 /* Test against AIX 5.1...7.2 bug: Failures are not distinguishable from
jpayne@68 96 successful returns. This is even documented in
jpayne@68 97 <https://www.ibm.com/support/knowledgecenter/ssw_aix_72/i_bostechref/iconv.html> */
jpayne@68 98 {
jpayne@68 99 iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
jpayne@68 100 if (cd_utf8_to_88591 != (iconv_t)(-1))
jpayne@68 101 {
jpayne@68 102 static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */
jpayne@68 103 char buf[10];
jpayne@68 104 ICONV_CONST char *inptr = input;
jpayne@68 105 size_t inbytesleft = strlen (input);
jpayne@68 106 char *outptr = buf;
jpayne@68 107 size_t outbytesleft = sizeof (buf);
jpayne@68 108 size_t res = iconv (cd_utf8_to_88591,
jpayne@68 109 &inptr, &inbytesleft,
jpayne@68 110 &outptr, &outbytesleft);
jpayne@68 111 if (res == 0)
jpayne@68 112 result |= 1;
jpayne@68 113 iconv_close (cd_utf8_to_88591);
jpayne@68 114 }
jpayne@68 115 }
jpayne@68 116 /* Test against Solaris 10 bug: Failures are not distinguishable from
jpayne@68 117 successful returns. */
jpayne@68 118 {
jpayne@68 119 iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
jpayne@68 120 if (cd_ascii_to_88591 != (iconv_t)(-1))
jpayne@68 121 {
jpayne@68 122 static ICONV_CONST char input[] = "\263";
jpayne@68 123 char buf[10];
jpayne@68 124 ICONV_CONST char *inptr = input;
jpayne@68 125 size_t inbytesleft = strlen (input);
jpayne@68 126 char *outptr = buf;
jpayne@68 127 size_t outbytesleft = sizeof (buf);
jpayne@68 128 size_t res = iconv (cd_ascii_to_88591,
jpayne@68 129 &inptr, &inbytesleft,
jpayne@68 130 &outptr, &outbytesleft);
jpayne@68 131 if (res == 0)
jpayne@68 132 result |= 2;
jpayne@68 133 iconv_close (cd_ascii_to_88591);
jpayne@68 134 }
jpayne@68 135 }
jpayne@68 136 /* Test against AIX 6.1..7.1 bug: Buffer overrun. */
jpayne@68 137 {
jpayne@68 138 iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
jpayne@68 139 if (cd_88591_to_utf8 != (iconv_t)(-1))
jpayne@68 140 {
jpayne@68 141 static ICONV_CONST char input[] = "\304";
jpayne@68 142 static char buf[2] = { (char)0xDE, (char)0xAD };
jpayne@68 143 ICONV_CONST char *inptr = input;
jpayne@68 144 size_t inbytesleft = 1;
jpayne@68 145 char *outptr = buf;
jpayne@68 146 size_t outbytesleft = 1;
jpayne@68 147 size_t res = iconv (cd_88591_to_utf8,
jpayne@68 148 &inptr, &inbytesleft,
jpayne@68 149 &outptr, &outbytesleft);
jpayne@68 150 if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
jpayne@68 151 result |= 4;
jpayne@68 152 iconv_close (cd_88591_to_utf8);
jpayne@68 153 }
jpayne@68 154 }
jpayne@68 155 #if 0 /* This bug could be worked around by the caller. */
jpayne@68 156 /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
jpayne@68 157 {
jpayne@68 158 iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
jpayne@68 159 if (cd_88591_to_utf8 != (iconv_t)(-1))
jpayne@68 160 {
jpayne@68 161 static ICONV_CONST char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
jpayne@68 162 char buf[50];
jpayne@68 163 ICONV_CONST char *inptr = input;
jpayne@68 164 size_t inbytesleft = strlen (input);
jpayne@68 165 char *outptr = buf;
jpayne@68 166 size_t outbytesleft = sizeof (buf);
jpayne@68 167 size_t res = iconv (cd_88591_to_utf8,
jpayne@68 168 &inptr, &inbytesleft,
jpayne@68 169 &outptr, &outbytesleft);
jpayne@68 170 if ((int)res > 0)
jpayne@68 171 result |= 8;
jpayne@68 172 iconv_close (cd_88591_to_utf8);
jpayne@68 173 }
jpayne@68 174 }
jpayne@68 175 #endif
jpayne@68 176 /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
jpayne@68 177 provided. */
jpayne@68 178 {
jpayne@68 179 /* Try standardized names. */
jpayne@68 180 iconv_t cd1 = iconv_open ("UTF-8", "EUC-JP");
jpayne@68 181 /* Try IRIX, OSF/1 names. */
jpayne@68 182 iconv_t cd2 = iconv_open ("UTF-8", "eucJP");
jpayne@68 183 /* Try AIX names. */
jpayne@68 184 iconv_t cd3 = iconv_open ("UTF-8", "IBM-eucJP");
jpayne@68 185 /* Try HP-UX names. */
jpayne@68 186 iconv_t cd4 = iconv_open ("utf8", "eucJP");
jpayne@68 187 if (cd1 == (iconv_t)(-1) && cd2 == (iconv_t)(-1)
jpayne@68 188 && cd3 == (iconv_t)(-1) && cd4 == (iconv_t)(-1))
jpayne@68 189 result |= 16;
jpayne@68 190 if (cd1 != (iconv_t)(-1))
jpayne@68 191 iconv_close (cd1);
jpayne@68 192 if (cd2 != (iconv_t)(-1))
jpayne@68 193 iconv_close (cd2);
jpayne@68 194 if (cd3 != (iconv_t)(-1))
jpayne@68 195 iconv_close (cd3);
jpayne@68 196 if (cd4 != (iconv_t)(-1))
jpayne@68 197 iconv_close (cd4);
jpayne@68 198 }
jpayne@68 199 return result;
jpayne@68 200 ]])],
jpayne@68 201 [am_cv_func_iconv_works=yes], ,
jpayne@68 202 [case "$host_os" in
jpayne@68 203 aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
jpayne@68 204 *) am_cv_func_iconv_works="guessing yes" ;;
jpayne@68 205 esac])
jpayne@68 206 test "$am_cv_func_iconv_works" = no || break
jpayne@68 207 done
jpayne@68 208 LIBS="$gl_saved_LIBS"
jpayne@68 209 ])
jpayne@68 210 case "$am_cv_func_iconv_works" in
jpayne@68 211 *no) am_func_iconv=no am_cv_lib_iconv=no ;;
jpayne@68 212 *) am_func_iconv=yes ;;
jpayne@68 213 esac
jpayne@68 214 else
jpayne@68 215 am_func_iconv=no am_cv_lib_iconv=no
jpayne@68 216 fi
jpayne@68 217 if test "$am_func_iconv" = yes; then
jpayne@68 218 AC_DEFINE([HAVE_ICONV], [1],
jpayne@68 219 [Define if you have the iconv() function and it works.])
jpayne@68 220 fi
jpayne@68 221 if test "$am_cv_lib_iconv" = yes; then
jpayne@68 222 AC_MSG_CHECKING([how to link with libiconv])
jpayne@68 223 AC_MSG_RESULT([$LIBICONV])
jpayne@68 224 else
jpayne@68 225 dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
jpayne@68 226 dnl either.
jpayne@68 227 CPPFLAGS="$gl_saved_CPPFLAGS"
jpayne@68 228 LIBICONV=
jpayne@68 229 LTLIBICONV=
jpayne@68 230 fi
jpayne@68 231 AC_SUBST([LIBICONV])
jpayne@68 232 AC_SUBST([LTLIBICONV])
jpayne@68 233 ])
jpayne@68 234
jpayne@68 235 dnl Define AM_ICONV using AC_DEFUN_ONCE, in order to avoid warnings like
jpayne@68 236 dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
jpayne@68 237 AC_DEFUN_ONCE([AM_ICONV],
jpayne@68 238 [
jpayne@68 239 AM_ICONV_LINK
jpayne@68 240 if test "$am_cv_func_iconv" = yes; then
jpayne@68 241 AC_CACHE_CHECK([whether iconv is compatible with its POSIX signature],
jpayne@68 242 [gl_cv_iconv_nonconst],
jpayne@68 243 [AC_COMPILE_IFELSE(
jpayne@68 244 [AC_LANG_PROGRAM(
jpayne@68 245 [[
jpayne@68 246 #include <stdlib.h>
jpayne@68 247 #include <iconv.h>
jpayne@68 248 extern
jpayne@68 249 #ifdef __cplusplus
jpayne@68 250 "C"
jpayne@68 251 #endif
jpayne@68 252 size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
jpayne@68 253 ]],
jpayne@68 254 [[]])],
jpayne@68 255 [gl_cv_iconv_nonconst=yes],
jpayne@68 256 [gl_cv_iconv_nonconst=no])
jpayne@68 257 ])
jpayne@68 258 else
jpayne@68 259 dnl When compiling GNU libiconv on a system that does not have iconv yet,
jpayne@68 260 dnl pick the POSIX compliant declaration without 'const'.
jpayne@68 261 gl_cv_iconv_nonconst=yes
jpayne@68 262 fi
jpayne@68 263 if test $gl_cv_iconv_nonconst = yes; then
jpayne@68 264 iconv_arg1=""
jpayne@68 265 else
jpayne@68 266 iconv_arg1="const"
jpayne@68 267 fi
jpayne@68 268 AC_DEFINE_UNQUOTED([ICONV_CONST], [$iconv_arg1],
jpayne@68 269 [Define as const if the declaration of iconv() needs const.])
jpayne@68 270 dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
jpayne@68 271 m4_ifdef([gl_ICONV_H_DEFAULTS],
jpayne@68 272 [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
jpayne@68 273 if test $gl_cv_iconv_nonconst != yes; then
jpayne@68 274 ICONV_CONST="const"
jpayne@68 275 fi
jpayne@68 276 ])
jpayne@68 277
jpayne@68 278 dnl A summary result, for those packages which want to print a summary at the
jpayne@68 279 dnl end of the configuration.
jpayne@68 280 if test "$am_func_iconv" = yes; then
jpayne@68 281 if test -n "$LIBICONV"; then
jpayne@68 282 am_cv_func_iconv_summary='yes, in libiconv'
jpayne@68 283 else
jpayne@68 284 am_cv_func_iconv_summary='yes, in libc'
jpayne@68 285 fi
jpayne@68 286 else
jpayne@68 287 if test "$am_cv_func_iconv" = yes; then
jpayne@68 288 am_cv_func_iconv_summary='not working, consider installing GNU libiconv'
jpayne@68 289 else
jpayne@68 290 am_cv_func_iconv_summary='no, consider installing GNU libiconv'
jpayne@68 291 fi
jpayne@68 292 fi
jpayne@68 293 ])