xref: /PHP-8.2/ext/iconv/config.m4 (revision 250547c7)
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>
33#include <stdio.h>
34int main(void) {
35  printf("%d", _libiconv_version);
36  return 0;
37}
38      ]])],[
39        AC_MSG_RESULT(yes)
40        iconv_impl_name="gnu_libiconv"
41      ],[
42        AC_MSG_RESULT(no)
43      ],[
44        AC_MSG_RESULT([no, cross-compiling])
45      ])
46    fi
47
48    if test -z "$iconv_impl_name"; then
49      AC_MSG_CHECKING([if iconv is Konstantin Chuguev's])
50      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <iconv.h>]], [[iconv_ccs_init(NULL, NULL);]])],[
51        AC_MSG_RESULT(yes)
52        iconv_impl_name="bsd"
53      ],[
54        AC_MSG_RESULT(no)
55      ])
56    fi
57
58    if test -z "$iconv_impl_name"; then
59      AC_MSG_CHECKING([if using IBM iconv])
60      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <iconv.h>]], [[cstoccsid("");]])],[
61        AC_MSG_RESULT(yes)
62        iconv_impl_name="ibm"
63      ],[
64        AC_MSG_RESULT(no)
65      ])
66    fi
67
68    case "$iconv_impl_name" in
69      gnu_libiconv [)]
70        AC_DEFINE([PHP_ICONV_IMPL],["libiconv"],[Which iconv implementation to use])
71        AC_DEFINE([HAVE_LIBICONV],1,[Whether libiconv is used])
72        ;;
73
74      bsd [)]
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(void) {
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(void) {
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], [php_iconv.h])
152  else
153    AC_MSG_ERROR(Please reinstall the iconv library.)
154  fi
155fi
156