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