xref: /php-src/ext/iconv/config.m4 (revision de665853)
1PHP_ARG_WITH([iconv],
2  [for iconv support],
3  [AS_HELP_STRING([[--without-iconv[=DIR]]],
4    [Exclude iconv support])],
5  [yes])
6
7if test "$PHP_ICONV" != "no"; then
8  PHP_SETUP_ICONV([ICONV_SHARED_LIBADD],,
9    [AC_MSG_FAILURE([The iconv not found.])])
10
11  save_LIBS=$LIBS
12  save_CFLAGS=$CFLAGS
13  LIBS="$LIBS $ICONV_SHARED_LIBADD"
14  CFLAGS="$INCLUDES $CFLAGS"
15
16  AC_CACHE_CHECK([for iconv implementation], [php_cv_iconv_implementation], [
17    AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <gnu/libc-version.h>],
18      [gnu_get_libc_version();])],
19      [php_cv_iconv_implementation=glibc],
20      [php_cv_iconv_implementation=unknown])
21
22    AS_VAR_IF([php_cv_iconv_implementation], [unknown],
23      [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <iconv.h>],
24        [(void) _libiconv_version])],
25        [php_cv_iconv_implementation="GNU libiconv"],
26        [php_cv_iconv_implementation=unknown])])
27
28    dnl BSD iconv by Konstantin Chuguev.
29    AS_VAR_IF([php_cv_iconv_implementation], [unknown],
30      [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <iconv.h>],
31        [iconv_ccs_init(NULL, NULL);])],
32        [php_cv_iconv_implementation=BSD],
33        [php_cv_iconv_implementation=unknown])])
34
35    AS_VAR_IF([php_cv_iconv_implementation], [unknown],
36      [AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <iconv.h>],
37        [cstoccsid("");])],
38        [php_cv_iconv_implementation=IBM],
39        [php_cv_iconv_implementation=unknown])])
40  ])
41
42  AH_TEMPLATE([PHP_ICONV_IMPL], [The iconv implementation.])
43
44  AS_CASE([$php_cv_iconv_implementation],
45    [glibc], [
46      AC_DEFINE([HAVE_GLIBC_ICONV], [1],
47        [Define to 1 if iconv implementation is glibc.])
48      AC_DEFINE([PHP_ICONV_IMPL], ["glibc"])
49    ],
50    ["GNU libiconv"], [
51      AC_DEFINE([PHP_ICONV_IMPL], ["libiconv"])
52      AC_DEFINE([HAVE_LIBICONV], [1])
53    ],
54    [BSD], [AC_DEFINE([PHP_ICONV_IMPL], ["BSD iconv"])],
55    [IBM], [
56      AC_DEFINE([HAVE_IBM_ICONV], [1],
57        [Define to 1 if iconv implementation is IBM.])
58      AC_DEFINE([PHP_ICONV_IMPL], ["IBM iconv"])
59    ])
60
61  AC_CACHE_CHECK([if iconv supports errno], [php_cv_iconv_errno],
62    [AC_RUN_IFELSE([AC_LANG_SOURCE([
63#include <iconv.h>
64#include <errno.h>
65
66int main(void) {
67  iconv_t cd;
68  cd = iconv_open( "*blahblah*", "*blahblahblah*" );
69  if (cd == (iconv_t)(-1)) {
70    if (errno == EINVAL) {
71      return 0;
72  } else {
73      return 1;
74    }
75  }
76  iconv_close( cd );
77  return 2;
78}
79    ])],
80    [php_cv_iconv_errno=yes],
81    [php_cv_iconv_errno=no],
82    [php_cv_iconv_errno=yes])])
83  AS_VAR_IF([php_cv_iconv_errno], [yes],,
84    [AC_MSG_FAILURE([The iconv check failed, 'errno' is missing.])])
85
86  AC_CACHE_CHECK([if iconv supports //IGNORE], [php_cv_iconv_ignore],
87    [AC_RUN_IFELSE([AC_LANG_SOURCE([
88#include <iconv.h>
89#include <stdlib.h>
90
91int main(void) {
92  iconv_t cd = iconv_open( "UTF-8//IGNORE", "UTF-8" );
93  if(cd == (iconv_t)-1) {
94    return 1;
95  }
96  char *in_p = "\xC3\xC3\xC3\xB8";
97  size_t in_left = 4, out_left = 4096;
98  char *out = malloc(out_left);
99  char *out_p = out;
100  size_t result = iconv(cd, (char **) &in_p, &in_left, (char **) &out_p, &out_left);
101  if(result == (size_t)-1) {
102    return 1;
103  }
104  return 0;
105}
106    ])],
107    [php_cv_iconv_ignore=yes],
108    [php_cv_iconv_ignore=no],
109    [php_cv_iconv_ignore=no])])
110  AS_VAR_IF([php_cv_iconv_ignore], [no],
111    [AC_DEFINE([ICONV_BROKEN_IGNORE], [1],
112      [Define to 1 if iconv has broken IGNORE.])])
113
114  LIBS=$save_LIBS
115  CFLAGS=$save_CFLAGS
116
117  AC_DEFINE([HAVE_ICONV], [1],
118    [Define to 1 if the PHP extension 'iconv' is available.])
119
120  PHP_NEW_EXTENSION([iconv],
121    [iconv.c],
122    [$ext_shared],,
123    [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
124  PHP_SUBST([ICONV_SHARED_LIBADD])
125  PHP_INSTALL_HEADERS([ext/iconv], [php_iconv.h])
126fi
127