| 1 |
AC_DEFUN([AC_TNY_ICONV_CHECK], |
|---|
| 2 |
[ |
|---|
| 3 |
|
|---|
| 4 |
have_iconv=no |
|---|
| 5 |
AC_ARG_WITH(libiconv, [ --with-libiconv Prefix where libiconv is installed]) |
|---|
| 6 |
case $withval in |
|---|
| 7 |
/*) |
|---|
| 8 |
ICONV_CFLAGS="-I$withval/include" |
|---|
| 9 |
ICONV_LIBS="-L$withval/lib" |
|---|
| 10 |
;; |
|---|
| 11 |
esac |
|---|
| 12 |
|
|---|
| 13 |
save_CFLAGS="$CFLAGS" |
|---|
| 14 |
save_LIBS="$LIBS" |
|---|
| 15 |
CFLAGS="$CFLAGS $ICONV_CFLAGS" |
|---|
| 16 |
LIBS="$LIBS $ICONV_LIBS -liconv" |
|---|
| 17 |
AC_CACHE_CHECK(for iconv in -liconv, ac_cv_libiconv, AC_LINK_IFELSE([AC_LANG_PROGRAM([[ |
|---|
| 18 |
#include <iconv.h> |
|---|
| 19 |
]], [[ |
|---|
| 20 |
iconv_t cd; |
|---|
| 21 |
cd = iconv_open ("UTF-8", "ISO-8859-1"); |
|---|
| 22 |
]])],[ac_cv_libiconv=yes],[ac_cv_libiconv=no])) |
|---|
| 23 |
if test $ac_cv_libiconv = yes; then |
|---|
| 24 |
ICONV_LIBS="$ICONV_LIBS -liconv" |
|---|
| 25 |
have_iconv=yes |
|---|
| 26 |
else |
|---|
| 27 |
CFLAGS="$save_CFLAGS" |
|---|
| 28 |
LIBS="$save_LIBS" |
|---|
| 29 |
AC_CHECK_FUNC(iconv, have_iconv=yes, have_iconv=no) |
|---|
| 30 |
fi |
|---|
| 31 |
|
|---|
| 32 |
if test $have_iconv = yes; then |
|---|
| 33 |
if test $ac_cv_libiconv = no; then |
|---|
| 34 |
AC_CHECK_FUNCS(gnu_get_libc_version) |
|---|
| 35 |
fi |
|---|
| 36 |
AC_CACHE_CHECK([if iconv() handles UTF-8], ac_cv_libiconv_utf8, AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
|---|
| 37 |
#include <iconv.h> |
|---|
| 38 |
#include <stdlib.h> |
|---|
| 39 |
#include <string.h> |
|---|
| 40 |
#ifdef HAVE_GNU_GET_LIBC_VERSION |
|---|
| 41 |
#include <gnu/libc-version.h> |
|---|
| 42 |
#endif |
|---|
| 43 |
|
|---|
| 44 |
int main (int argc, char **argv) |
|---|
| 45 |
{ |
|---|
| 46 |
const char *from = "Some Text \xA4"; |
|---|
| 47 |
const char *utf8 = "Some Text \xC2\xA4"; |
|---|
| 48 |
char *transbuf = (char *) malloc (20), *trans = transbuf; |
|---|
| 49 |
iconv_t cd; |
|---|
| 50 |
size_t from_len = strlen (from), utf8_len = 20; |
|---|
| 51 |
size_t utf8_real_len = strlen (utf8); |
|---|
| 52 |
|
|---|
| 53 |
#ifdef HAVE_GNU_GET_LIBC_VERSION |
|---|
| 54 |
/* glibc 2.1.2's iconv is broken in hard to test ways. */ |
|---|
| 55 |
if (!strcmp (gnu_get_libc_version (), "2.1.2")) |
|---|
| 56 |
return (1); |
|---|
| 57 |
|
|---|
| 58 |
|
|---|
| 59 |
cd = iconv_open ("UTF-8", "ISO-8859-1"); |
|---|
| 60 |
if (cd == (iconv_t) -1) |
|---|
| 61 |
return (1); |
|---|
| 62 |
if (iconv (cd, &from, &from_len, &trans, &utf8_len) == -1 || from_len != 0) |
|---|
| 63 |
return (1); |
|---|
| 64 |
if (memcmp (utf8, transbuf, utf8_real_len) != 0) |
|---|
| 65 |
return (1); |
|---|
| 66 |
|
|---|
| 67 |
return (0); |
|---|
| 68 |
}]])],[ac_cv_libiconv_utf8=yes],[ac_cv_libiconv_utf8=no; have_iconv=no],[ac_cv_libiconv_utf8=no; have_iconv=no])) |
|---|
| 69 |
fi |
|---|
| 70 |
|
|---|
| 71 |
if test "$have_iconv" = no; then |
|---|
| 72 |
AC_MSG_ERROR([You need to install a working iconv implementation, such as ftp://ftp.gnu.org/pub/gnu/libiconv]) |
|---|
| 73 |
fi |
|---|
| 74 |
AC_SUBST(ICONV_CFLAGS) |
|---|
| 75 |
AC_SUBST(ICONV_LIBS) |
|---|
| 76 |
|
|---|
| 77 |
CFLAGS="$CFLAGS -I$srcdir" |
|---|
| 78 |
|
|---|
| 79 |
AC_ARG_WITH([iconv-detect-h], |
|---|
| 80 |
AC_HELP_STRING([--with-iconv-detect-h], |
|---|
| 81 |
[Use a hand generated iconv-detect.h rather than running iconv-detect (in libtinymail-camel/camel-lite)]), |
|---|
| 82 |
[cp $withval iconv-detect.h], |
|---|
| 83 |
AC_MSG_CHECKING(preferred charset formats for system iconv) |
|---|
| 84 |
AC_RUN_IFELSE([AC_LANG_SOURCE([[ |
|---|
| 85 |
|
|---|
| 86 |
|
|---|
| 87 |
]])],[ |
|---|
| 88 |
AC_MSG_RESULT(found) |
|---|
| 89 |
],[ |
|---|
| 90 |
AC_MSG_RESULT(not found) |
|---|
| 91 |
],[]) |
|---|
| 92 |
|
|---|
| 93 |
CFLAGS="$save_CFLAGS" |
|---|
| 94 |
LIBS="$save_LIBS" |
|---|
| 95 |
) |
|---|
| 96 |
]) |
|---|