5 kx # iconv.m4 serial 19 (gettext-0.18.2)
5 kx dnl Copyright (C) 2000-2002, 2007-2014, 2016 Free Software Foundation, Inc.
5 kx dnl This file is free software; the Free Software Foundation
5 kx dnl gives unlimited permission to copy and/or distribute it,
5 kx dnl with or without modifications, as long as this notice is preserved.
5 kx
5 kx dnl From Bruno Haible.
5 kx
5 kx AC_DEFUN([AM_ICONV_LINKFLAGS_BODY],
5 kx [
5 kx dnl Prerequisites of AC_LIB_LINKFLAGS_BODY.
5 kx AC_REQUIRE([AC_LIB_PREPARE_PREFIX])
5 kx AC_REQUIRE([AC_LIB_RPATH])
5 kx
5 kx dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
5 kx dnl accordingly.
5 kx AC_LIB_LINKFLAGS_BODY([iconv])
5 kx ])
5 kx
5 kx AC_DEFUN([AM_ICONV_LINK],
5 kx [
5 kx dnl Some systems have iconv in libc, some have it in libiconv (OSF/1 and
5 kx dnl those with the standalone portable GNU libiconv installed).
5 kx AC_REQUIRE([AC_CANONICAL_HOST]) dnl for cross-compiles
5 kx
5 kx dnl Search for libiconv and define LIBICONV, LTLIBICONV and INCICONV
5 kx dnl accordingly.
5 kx AC_REQUIRE([AM_ICONV_LINKFLAGS_BODY])
5 kx
5 kx dnl Add $INCICONV to CPPFLAGS before performing the following checks,
5 kx dnl because if the user has installed libiconv and not disabled its use
5 kx dnl via --without-libiconv-prefix, he wants to use it. The first
5 kx dnl AC_LINK_IFELSE will then fail, the second AC_LINK_IFELSE will succeed.
5 kx am_save_CPPFLAGS="$CPPFLAGS"
5 kx AC_LIB_APPENDTOVAR([CPPFLAGS], [$INCICONV])
5 kx
5 kx AC_CACHE_CHECK([for iconv], [am_cv_func_iconv], [
5 kx am_cv_func_iconv="no, consider installing GNU libiconv"
5 kx am_cv_lib_iconv=no
5 kx AC_LINK_IFELSE(
5 kx [AC_LANG_PROGRAM(
5 kx [[
5 kx #include <stdlib.h>
5 kx #include <iconv.h>
5 kx ]],
5 kx [[iconv_t cd = iconv_open("","");
5 kx iconv(cd,NULL,NULL,NULL,NULL);
5 kx iconv_close(cd);]])],
5 kx [am_cv_func_iconv=yes])
5 kx if test "$am_cv_func_iconv" != yes; then
5 kx am_save_LIBS="$LIBS"
5 kx LIBS="$LIBS $LIBICONV"
5 kx AC_LINK_IFELSE(
5 kx [AC_LANG_PROGRAM(
5 kx [[
5 kx #include <stdlib.h>
5 kx #include <iconv.h>
5 kx ]],
5 kx [[iconv_t cd = iconv_open("","");
5 kx iconv(cd,NULL,NULL,NULL,NULL);
5 kx iconv_close(cd);]])],
5 kx [am_cv_lib_iconv=yes]
5 kx [am_cv_func_iconv=yes])
5 kx LIBS="$am_save_LIBS"
5 kx fi
5 kx ])
5 kx if test "$am_cv_func_iconv" = yes; then
5 kx AC_CACHE_CHECK([for working iconv], [am_cv_func_iconv_works], [
5 kx dnl This tests against bugs in AIX 5.1, AIX 6.1..7.1, HP-UX 11.11,
5 kx dnl Solaris 10.
5 kx am_save_LIBS="$LIBS"
5 kx if test $am_cv_lib_iconv = yes; then
5 kx LIBS="$LIBS $LIBICONV"
5 kx fi
5 kx am_cv_func_iconv_works=no
5 kx for ac_iconv_const in '' 'const'; do
5 kx AC_RUN_IFELSE(
5 kx [AC_LANG_PROGRAM(
5 kx [[
5 kx #include <iconv.h>
5 kx #include <string.h>
5 kx
5 kx #ifndef ICONV_CONST
5 kx # define ICONV_CONST $ac_iconv_const
5 kx #endif
5 kx ]],
5 kx [[int result = 0;
5 kx /* Test against AIX 5.1 bug: Failures are not distinguishable from successful
5 kx returns. */
5 kx {
5 kx iconv_t cd_utf8_to_88591 = iconv_open ("ISO8859-1", "UTF-8");
5 kx if (cd_utf8_to_88591 != (iconv_t)(-1))
5 kx {
5 kx static ICONV_CONST char input[] = "\342\202\254"; /* EURO SIGN */
5 kx char buf[10];
5 kx ICONV_CONST char *inptr = input;
5 kx size_t inbytesleft = strlen (input);
5 kx char *outptr = buf;
5 kx size_t outbytesleft = sizeof (buf);
5 kx size_t res = iconv (cd_utf8_to_88591,
5 kx &inptr, &inbytesleft,
5 kx &outptr, &outbytesleft);
5 kx if (res == 0)
5 kx result |= 1;
5 kx iconv_close (cd_utf8_to_88591);
5 kx }
5 kx }
5 kx /* Test against Solaris 10 bug: Failures are not distinguishable from
5 kx successful returns. */
5 kx {
5 kx iconv_t cd_ascii_to_88591 = iconv_open ("ISO8859-1", "646");
5 kx if (cd_ascii_to_88591 != (iconv_t)(-1))
5 kx {
5 kx static ICONV_CONST char input[] = "\263";
5 kx char buf[10];
5 kx ICONV_CONST char *inptr = input;
5 kx size_t inbytesleft = strlen (input);
5 kx char *outptr = buf;
5 kx size_t outbytesleft = sizeof (buf);
5 kx size_t res = iconv (cd_ascii_to_88591,
5 kx &inptr, &inbytesleft,
5 kx &outptr, &outbytesleft);
5 kx if (res == 0)
5 kx result |= 2;
5 kx iconv_close (cd_ascii_to_88591);
5 kx }
5 kx }
5 kx /* Test against AIX 6.1..7.1 bug: Buffer overrun. */
5 kx {
5 kx iconv_t cd_88591_to_utf8 = iconv_open ("UTF-8", "ISO-8859-1");
5 kx if (cd_88591_to_utf8 != (iconv_t)(-1))
5 kx {
5 kx static ICONV_CONST char input[] = "\304";
5 kx static char buf[2] = { (char)0xDE, (char)0xAD };
5 kx ICONV_CONST char *inptr = input;
5 kx size_t inbytesleft = 1;
5 kx char *outptr = buf;
5 kx size_t outbytesleft = 1;
5 kx size_t res = iconv (cd_88591_to_utf8,
5 kx &inptr, &inbytesleft,
5 kx &outptr, &outbytesleft);
5 kx if (res != (size_t)(-1) || outptr - buf > 1 || buf[1] != (char)0xAD)
5 kx result |= 4;
5 kx iconv_close (cd_88591_to_utf8);
5 kx }
5 kx }
5 kx #if 0 /* This bug could be worked around by the caller. */
5 kx /* Test against HP-UX 11.11 bug: Positive return value instead of 0. */
5 kx {
5 kx iconv_t cd_88591_to_utf8 = iconv_open ("utf8", "iso88591");
5 kx if (cd_88591_to_utf8 != (iconv_t)(-1))
5 kx {
5 kx static ICONV_CONST char input[] = "\304rger mit b\366sen B\374bchen ohne Augenma\337";
5 kx char buf[50];
5 kx ICONV_CONST char *inptr = input;
5 kx size_t inbytesleft = strlen (input);
5 kx char *outptr = buf;
5 kx size_t outbytesleft = sizeof (buf);
5 kx size_t res = iconv (cd_88591_to_utf8,
5 kx &inptr, &inbytesleft,
5 kx &outptr, &outbytesleft);
5 kx if ((int)res > 0)
5 kx result |= 8;
5 kx iconv_close (cd_88591_to_utf8);
5 kx }
5 kx }
5 kx #endif
5 kx /* Test against HP-UX 11.11 bug: No converter from EUC-JP to UTF-8 is
5 kx provided. */
5 kx if (/* Try standardized names. */
5 kx iconv_open ("UTF-8", "EUC-JP") == (iconv_t)(-1)
5 kx /* Try IRIX, OSF/1 names. */
5 kx && iconv_open ("UTF-8", "eucJP") == (iconv_t)(-1)
5 kx /* Try AIX names. */
5 kx && iconv_open ("UTF-8", "IBM-eucJP") == (iconv_t)(-1)
5 kx /* Try HP-UX names. */
5 kx && iconv_open ("utf8", "eucJP") == (iconv_t)(-1))
5 kx result |= 16;
5 kx return result;
5 kx ]])],
5 kx [am_cv_func_iconv_works=yes], ,
5 kx [case "$host_os" in
5 kx aix* | hpux*) am_cv_func_iconv_works="guessing no" ;;
5 kx *) am_cv_func_iconv_works="guessing yes" ;;
5 kx esac])
5 kx test "$am_cv_func_iconv_works" = no || break
5 kx done
5 kx LIBS="$am_save_LIBS"
5 kx ])
5 kx case "$am_cv_func_iconv_works" in
5 kx *no) am_func_iconv=no am_cv_lib_iconv=no ;;
5 kx *) am_func_iconv=yes ;;
5 kx esac
5 kx else
5 kx am_func_iconv=no am_cv_lib_iconv=no
5 kx fi
5 kx if test "$am_func_iconv" = yes; then
5 kx AC_DEFINE([HAVE_ICONV], [1],
5 kx [Define if you have the iconv() function and it works.])
5 kx fi
5 kx if test "$am_cv_lib_iconv" = yes; then
5 kx AC_MSG_CHECKING([how to link with libiconv])
5 kx AC_MSG_RESULT([$LIBICONV])
5 kx else
5 kx dnl If $LIBICONV didn't lead to a usable library, we don't need $INCICONV
5 kx dnl either.
5 kx CPPFLAGS="$am_save_CPPFLAGS"
5 kx LIBICONV=
5 kx LTLIBICONV=
5 kx fi
5 kx AC_SUBST([LIBICONV])
5 kx AC_SUBST([LTLIBICONV])
5 kx ])
5 kx
5 kx dnl Define AM_ICONV using AC_DEFUN_ONCE for Autoconf >= 2.64, in order to
5 kx dnl avoid warnings like
5 kx dnl "warning: AC_REQUIRE: `AM_ICONV' was expanded before it was required".
5 kx dnl This is tricky because of the way 'aclocal' is implemented:
5 kx dnl - It requires defining an auxiliary macro whose name ends in AC_DEFUN.
5 kx dnl Otherwise aclocal's initial scan pass would miss the macro definition.
5 kx dnl - It requires a line break inside the AC_DEFUN_ONCE and AC_DEFUN expansions.
5 kx dnl Otherwise aclocal would emit many "Use of uninitialized value $1"
5 kx dnl warnings.
5 kx m4_define([gl_iconv_AC_DEFUN],
5 kx m4_version_prereq([2.64],
5 kx [[AC_DEFUN_ONCE(
5 kx [$1], [$2])]],
5 kx [m4_ifdef([gl_00GNULIB],
5 kx [[AC_DEFUN_ONCE(
5 kx [$1], [$2])]],
5 kx [[AC_DEFUN(
5 kx [$1], [$2])]])]))
5 kx gl_iconv_AC_DEFUN([AM_ICONV],
5 kx [
5 kx AM_ICONV_LINK
5 kx if test "$am_cv_func_iconv" = yes; then
5 kx AC_MSG_CHECKING([for iconv declaration])
5 kx AC_CACHE_VAL([am_cv_proto_iconv], [
5 kx AC_COMPILE_IFELSE(
5 kx [AC_LANG_PROGRAM(
5 kx [[
5 kx #include <stdlib.h>
5 kx #include <iconv.h>
5 kx extern
5 kx #ifdef __cplusplus
5 kx "C"
5 kx #endif
5 kx #if defined(__STDC__) || defined(_MSC_VER) || defined(__cplusplus)
5 kx size_t iconv (iconv_t cd, char * *inbuf, size_t *inbytesleft, char * *outbuf, size_t *outbytesleft);
5 kx #else
5 kx size_t iconv();
5 kx #endif
5 kx ]],
5 kx [[]])],
5 kx [am_cv_proto_iconv_arg1=""],
5 kx [am_cv_proto_iconv_arg1="const"])
5 kx 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);"])
5 kx am_cv_proto_iconv=`echo "[$]am_cv_proto_iconv" | tr -s ' ' | sed -e 's/( /(/'`
5 kx AC_MSG_RESULT([
5 kx $am_cv_proto_iconv])
5 kx AC_DEFINE_UNQUOTED([ICONV_CONST], [$am_cv_proto_iconv_arg1],
5 kx [Define as const if the declaration of iconv() needs const.])
5 kx dnl Also substitute ICONV_CONST in the gnulib generated <iconv.h>.
5 kx m4_ifdef([gl_ICONV_H_DEFAULTS],
5 kx [AC_REQUIRE([gl_ICONV_H_DEFAULTS])
5 kx if test -n "$am_cv_proto_iconv_arg1"; then
5 kx ICONV_CONST="const"
5 kx fi
5 kx ])
5 kx fi
5 kx ])