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