Blame m4/iconv.m4

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