xref: /PHP-8.0/ext/iconv/config.m4 (revision 07a4185d)
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
9  PHP_SETUP_ICONV(ICONV_SHARED_LIBADD, [
10    iconv_avail="yes";
11  ],[
12    iconv_avail="no";
13  ])
14
15  if test "$iconv_avail" != "no"; then
16    save_LDFLAGS="$LDFLAGS"
17    save_CFLAGS="$CFLAGS"
18    LDFLAGS="$ICONV_SHARED_LIBADD $LDFLAGS"
19    CFLAGS="$INCLUDES $CFLAGS"
20
21    AC_MSG_CHECKING([if iconv is glibc's])
22    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <gnu/libc-version.h>]], [[gnu_get_libc_version();]])],[
23      AC_MSG_RESULT(yes)
24      iconv_impl_name="glibc"
25    ],[
26      AC_MSG_RESULT(no)
27    ])
28
29    if test -z "$iconv_impl_name"; then
30      AC_MSG_CHECKING([if using GNU libiconv])
31      AC_RUN_IFELSE([AC_LANG_SOURCE([[
32#include <iconv.h>
33int main() {
34  printf("%d", _libiconv_version);
35  return 0;
36}
37      ]])],[
38        AC_MSG_RESULT(yes)
39        iconv_impl_name="gnu_libiconv"
40      ],[
41        AC_MSG_RESULT(no)
42      ],[
43        AC_MSG_RESULT([no, cross-compiling])
44      ])
45    fi
46
47    if test -z "$iconv_impl_name"; then
48      AC_MSG_CHECKING([if iconv is Konstantin Chuguev's])
49      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <iconv.h>]], [[iconv_ccs_init(NULL, NULL);]])],[
50        AC_MSG_RESULT(yes)
51        iconv_impl_name="bsd"
52      ],[
53        AC_MSG_RESULT(no)
54      ])
55    fi
56
57    if test -z "$iconv_impl_name"; then
58      AC_MSG_CHECKING([if using IBM iconv])
59      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <iconv.h>]], [[cstoccsid("");]])],[
60        AC_MSG_RESULT(yes)
61        iconv_impl_name="ibm"
62      ],[
63        AC_MSG_RESULT(no)
64      ])
65    fi
66
67    case "$iconv_impl_name" in
68      gnu_libiconv [)]
69        AC_DEFINE([PHP_ICONV_IMPL],["libiconv"],[Which iconv implementation to use])
70        AC_DEFINE([HAVE_LIBICONV],1,[Whether libiconv is used])
71        ;;
72
73      bsd [)]
74        AC_DEFINE([HAVE_BSD_ICONV],1,[Konstantin Chuguev's iconv implementation])
75        AC_DEFINE([PHP_ICONV_IMPL],["BSD iconv"],[Which iconv implementation to use])
76        ;;
77
78      glibc [)]
79        AC_DEFINE([HAVE_GLIBC_ICONV],1,[glibc's iconv implementation])
80        AC_DEFINE([PHP_ICONV_IMPL],["glibc"],[Which iconv implementation to use])
81        ;;
82      ibm [)]
83        AC_DEFINE([HAVE_IBM_ICONV],1,[IBM iconv implementation])
84        AC_DEFINE([PHP_ICONV_IMPL],["IBM iconv"],[Which iconv implementation to use])
85        ;;
86    esac
87
88    AC_MSG_CHECKING([if iconv supports errno])
89    AC_RUN_IFELSE([AC_LANG_SOURCE([[
90#include <iconv.h>
91#include <errno.h>
92
93int main() {
94  iconv_t cd;
95  cd = iconv_open( "*blahblah*", "*blahblahblah*" );
96  if (cd == (iconv_t)(-1)) {
97    if (errno == EINVAL) {
98      return 0;
99  } else {
100      return 1;
101    }
102  }
103  iconv_close( cd );
104  return 2;
105}
106    ]])],[
107      AC_MSG_RESULT(yes)
108    ],[
109      AC_MSG_RESULT(no)
110      AC_MSG_ERROR(iconv does not support errno)
111    ],[
112      AC_MSG_RESULT(yes, cross-compiling)
113    ])
114
115    AC_MSG_CHECKING([if iconv supports //IGNORE])
116    AC_RUN_IFELSE([AC_LANG_SOURCE([[
117#include <iconv.h>
118#include <stdlib.h>
119
120int main() {
121  iconv_t cd = iconv_open( "UTF-8//IGNORE", "UTF-8" );
122  if(cd == (iconv_t)-1) {
123    return 1;
124  }
125  char *in_p = "\xC3\xC3\xC3\xB8";
126  size_t in_left = 4, out_left = 4096;
127  char *out = malloc(out_left);
128  char *out_p = out;
129  size_t result = iconv(cd, (char **) &in_p, &in_left, (char **) &out_p, &out_left);
130  if(result == (size_t)-1) {
131    return 1;
132  }
133  return 0;
134}
135   ]])],[
136      AC_MSG_RESULT(yes)
137      AC_DEFINE([ICONV_BROKEN_IGNORE],0,[Whether iconv supports IGNORE])
138    ],[
139      AC_MSG_RESULT(no)
140      AC_DEFINE([ICONV_BROKEN_IGNORE],1,[Whether iconv supports IGNORE])
141    ],[
142      AC_MSG_RESULT(no, cross-compiling)
143      AC_DEFINE([ICONV_BROKEN_IGNORE],0,[Whether iconv supports IGNORE])
144    ])
145
146    LDFLAGS="$save_LDFLAGS"
147    CFLAGS="$save_CFLAGS"
148
149    PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
150    PHP_SUBST(ICONV_SHARED_LIBADD)
151    PHP_INSTALL_HEADERS([ext/iconv/])
152  else
153    AC_MSG_ERROR(Please reinstall the iconv library.)
154  fi
155fi
156