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