xref: /PHP-7.3/ext/iconv/config.m4 (revision 07a4185d)
1dnl config.m4 for extension iconv
2
3PHP_ARG_WITH(iconv, for iconv support,
4[  --without-iconv[=DIR]     Exclude iconv support], yes)
5
6if test "$PHP_ICONV" != "no"; then
7
8  PHP_SETUP_ICONV(ICONV_SHARED_LIBADD, [
9    iconv_avail="yes";
10  ],[
11    iconv_avail="no";
12  ])
13
14  if test "$iconv_avail" != "no"; then
15    if test -z "$ICONV_DIR"; then
16      for i in /usr/local /usr; do
17        if test -f "$i/include/iconv.h" || test -f "$i/include/giconv.h"; then
18          PHP_ICONV_PREFIX="$i"
19          break
20        fi
21      done
22      if test -z "$PHP_ICONV_PREFIX"; then
23        PHP_ICONV_PREFIX="/usr"
24      fi
25    else
26      PHP_ICONV_PREFIX="$ICONV_DIR"
27    fi
28
29    CFLAGS="-I$PHP_ICONV_PREFIX/include $CFLAGS"
30    LDFLAGS="-L$PHP_ICONV_PREFIX/$PHP_LIBDIR $LDFLAGS"
31
32    if test -r "$PHP_ICONV_PREFIX/include/giconv.h"; then
33      PHP_ICONV_H_PATH="$PHP_ICONV_PREFIX/include/giconv.h"
34    else
35      PHP_ICONV_H_PATH="$PHP_ICONV_PREFIX/include/iconv.h"
36	fi
37
38    AC_MSG_CHECKING([if iconv is glibc's])
39    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <gnu/libc-version.h>]], [[gnu_get_libc_version();]])],[
40      AC_MSG_RESULT(yes)
41      iconv_impl_name="glibc"
42    ],[
43      AC_MSG_RESULT(no)
44    ])
45
46    if test -z "$iconv_impl_name"; then
47      AC_MSG_CHECKING([if using GNU libiconv])
48      php_iconv_old_ld="$LDFLAGS"
49      LDFLAGS="-liconv $LDFLAGS"
50      AC_RUN_IFELSE([AC_LANG_SOURCE([[
51#include <$PHP_ICONV_H_PATH>
52int main() {
53  printf("%d", _libiconv_version);
54  return 0;
55}
56      ]])],[
57        AC_MSG_RESULT(yes)
58        iconv_impl_name="gnu_libiconv"
59      ],[
60        AC_MSG_RESULT(no)
61        LDFLAGS="$php_iconv_old_ld"
62      ],[
63        AC_MSG_RESULT([no, cross-compiling])
64        LDFLAGS="$php_iconv_old_ld"
65      ])
66    fi
67
68    if test -z "$iconv_impl_name"; then
69      AC_MSG_CHECKING([if iconv is Konstantin Chuguev's])
70      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <iconv.h>]], [[iconv_ccs_init(NULL, NULL);]])],[
71        AC_MSG_RESULT(yes)
72        iconv_impl_name="bsd"
73      ],[
74        AC_MSG_RESULT(no)
75      ])
76    fi
77
78    if test -z "$iconv_impl_name"; then
79      AC_MSG_CHECKING([if using IBM iconv])
80      php_iconv_old_ld="$LDFLAGS"
81      LDFLAGS="-liconv $LDFLAGS"
82      AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <iconv.h>]], [[cstoccsid("");]])],[
83        AC_MSG_RESULT(yes)
84        iconv_impl_name="ibm"
85      ],[
86        AC_MSG_RESULT(no)
87        LDFLAGS="$php_iconv_old_ld"
88      ])
89    fi
90
91    echo > ext/iconv/php_have_bsd_iconv.h
92    echo > ext/iconv/php_have_glibc_iconv.h
93    echo > ext/iconv/php_have_libiconv.h
94    echo > ext/iconv/php_have_ibm_iconv.h
95
96    case "$iconv_impl_name" in
97      gnu_libiconv [)]
98        PHP_DEFINE([PHP_ICONV_IMPL],[\"libiconv\"],[ext/iconv])
99        AC_DEFINE([PHP_ICONV_IMPL],["libiconv"],[Which iconv implementation to use])
100        PHP_DEFINE([HAVE_LIBICONV],1,[ext/iconv])
101        PHP_ADD_LIBRARY_WITH_PATH(iconv, "$PHP_ICONV_PREFIX/$PHP_LIBDIR", ICONV_SHARED_LIBADD)
102        ;;
103
104      bsd [)]
105        PHP_DEFINE([HAVE_BSD_ICONV],1,[ext/iconv])
106        AC_DEFINE([HAVE_BSD_ICONV],1,[Konstantin Chuguev's iconv implementation])
107        PHP_DEFINE([PHP_ICONV_IMPL],[\"BSD iconv\"],[ext/iconv])
108        AC_DEFINE([PHP_ICONV_IMPL],["BSD iconv"],[Which iconv implementation to use])
109        ;;
110
111      glibc [)]
112        PHP_DEFINE([HAVE_GLIBC_ICONV],1,[ext/iconv])
113        AC_DEFINE([HAVE_GLIBC_ICONV],1,[glibc's iconv implementation])
114        PHP_DEFINE([PHP_ICONV_IMPL],[\"glibc\"],[ext/iconv])
115        AC_DEFINE([PHP_ICONV_IMPL],["glibc"],[Which iconv implementation to use])
116        ;;
117      ibm [)]
118        PHP_DEFINE([HAVE_IBM_ICONV],1,[ext/iconv])
119        AC_DEFINE([HAVE_IBM_ICONV],1,[IBM iconv implementation])
120        PHP_DEFINE([PHP_ICONV_IMPL],[\"IBM iconv\"],[ext/iconv])
121        AC_DEFINE([PHP_ICONV_IMPL],["IBM iconv"],[Which iconv implementation to use])
122        ;;
123    esac
124
125    AC_MSG_CHECKING([if iconv supports errno])
126    AC_RUN_IFELSE([AC_LANG_SOURCE([[
127#include <$PHP_ICONV_H_PATH>
128#include <errno.h>
129
130int main() {
131  iconv_t cd;
132  cd = iconv_open( "*blahblah*", "*blahblahblah*" );
133  if (cd == (iconv_t)(-1)) {
134    if (errno == EINVAL) {
135      return 0;
136  } else {
137      return 1;
138    }
139  }
140  iconv_close( cd );
141  return 2;
142}
143    ]])],[
144      AC_MSG_RESULT(yes)
145      PHP_DEFINE([ICONV_SUPPORTS_ERRNO],1,[ext/iconv])
146      AC_DEFINE([ICONV_SUPPORTS_ERRNO],1,[Whether iconv supports error no or not])
147    ],[
148      AC_MSG_RESULT(no)
149      PHP_DEFINE([ICONV_SUPPORTS_ERRNO],0,[ext/iconv])
150      AC_DEFINE([ICONV_SUPPORTS_ERRNO],0,[Whether iconv supports error no or not])
151    ],[
152      AC_MSG_RESULT(no, cross-compiling)
153      PHP_DEFINE([ICONV_SUPPORTS_ERRNO],0,[ext/iconv])
154      AC_DEFINE([ICONV_SUPPORTS_ERRNO],0,[Whether iconv supports error no or not])
155    ])
156
157    AC_MSG_CHECKING([if iconv supports //IGNORE])
158    AC_RUN_IFELSE([AC_LANG_SOURCE([[
159#include <$PHP_ICONV_H_PATH>
160#include <stdlib.h>
161
162int main() {
163  iconv_t cd = iconv_open( "UTF-8//IGNORE", "UTF-8" );
164  if(cd == (iconv_t)-1) {
165    return 1;
166  }
167  char *in_p = "\xC3\xC3\xC3\xB8";
168  size_t in_left = 4, out_left = 4096;
169  char *out = malloc(out_left);
170  char *out_p = out;
171  size_t result = iconv(cd, (char **) &in_p, &in_left, (char **) &out_p, &out_left);
172  if(result == (size_t)-1) {
173    return 1;
174  }
175  return 0;
176}
177   ]])],[
178      AC_MSG_RESULT(yes)
179      PHP_DEFINE([ICONV_BROKEN_IGNORE],0,[ext/iconv])
180      AC_DEFINE([ICONV_BROKEN_IGNORE],0,[Whether iconv supports IGNORE])
181    ],[
182      AC_MSG_RESULT(no)
183      PHP_DEFINE([ICONV_BROKEN_IGNORE],1,[ext/iconv])
184      AC_DEFINE([ICONV_BROKEN_IGNORE],1,[Whether iconv supports IGNORE])
185    ],[
186      AC_MSG_RESULT(no, cross-compiling)
187      PHP_DEFINE([ICONV_BROKEN_IGNORE],0,[ext/iconv])
188      AC_DEFINE([ICONV_BROKEN_IGNORE],0,[Whether iconv supports IGNORE])
189    ])
190
191    AC_MSG_CHECKING([if your cpp allows macro usage in include lines])
192    AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
193#define FOO <$PHP_ICONV_H_PATH>
194#include FOO
195    ]], [])], [
196      AC_MSG_RESULT([yes])
197      PHP_DEFINE([PHP_ICONV_H_PATH], [<$PHP_ICONV_H_PATH>],[ext/iconv])
198      AC_DEFINE_UNQUOTED([PHP_ICONV_H_PATH], [<$PHP_ICONV_H_PATH>], [Path to iconv.h])
199    ], [
200      AC_MSG_RESULT([no])
201    ])
202
203    PHP_NEW_EXTENSION(iconv, iconv.c, $ext_shared,, [-I\"$PHP_ICONV_PREFIX/include\" -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1])
204    PHP_SUBST(ICONV_SHARED_LIBADD)
205    PHP_INSTALL_HEADERS([ext/iconv/])
206  else
207    AC_MSG_ERROR(Please reinstall the iconv library.)
208  fi
209fi
210