xref: /PHP-8.1/ext/imap/config.m4 (revision f9cbeaa0)
1AC_DEFUN([IMAP_INC_CHK],[if test -r "$i$1/c-client.h"; then
2    AC_DEFINE(HAVE_IMAP2000, 1, [ ])
3    IMAP_DIR=$i
4    IMAP_INC_DIR=$i$1
5    break
6  elif test -r "$i$1/rfc822.h"; then
7    IMAP_DIR=$i;
8    IMAP_INC_DIR=$i$1
9    break
10])
11
12AC_DEFUN([IMAP_LIB_CHK],[
13  str="$IMAP_DIR/$1/lib$lib.*"
14  for i in `echo $str`; do
15    test -r $i && IMAP_LIBDIR=$IMAP_DIR/$1 && break 2
16  done
17])
18
19dnl PHP_IMAP_TEST_BUILD(function, action-if-ok, action-if-not-ok, extra-libs, extra-source)
20dnl
21dnl The UW-IMAP c-client library was not originally designed to be a
22dnl shared library. The mm_foo functions are callbacks, and are required
23dnl to be implemented by the program that is linking to c-client. This
24dnl macro does the work of defining them all to no-ops for you. Note
25dnl that PHP_TEST_BUILD is a link test; the undefined symbols will only
26dnl cause problems if you actually try to link with c-client. For
27dnl example, if your test is trivial enough to be optimized out, and if
28dnl you link with --as-needed, the test/library may be omitted entirely
29dnl from the final executable. In that case linking will of course
30dnl succeed, but your luck won't necessarily apply at lower optimization
31dnl levels or systems where --as-needed is not used.
32AC_DEFUN([PHP_IMAP_TEST_BUILD], [
33  PHP_TEST_BUILD([$1], [$2], [$3], [$4], [$5]
34  [
35#if defined(__GNUC__) && __GNUC__ >= 4
36# define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
37#else
38# define PHP_IMAP_EXPORT
39#endif
40
41    PHP_IMAP_EXPORT void mm_log(void){}
42    PHP_IMAP_EXPORT void mm_dlog(void){}
43    PHP_IMAP_EXPORT void mm_flags(void){}
44    PHP_IMAP_EXPORT void mm_fatal(void){}
45    PHP_IMAP_EXPORT void mm_critical(void){}
46    PHP_IMAP_EXPORT void mm_nocritical(void){}
47    PHP_IMAP_EXPORT void mm_notify(void){}
48    PHP_IMAP_EXPORT void mm_login(void){}
49    PHP_IMAP_EXPORT void mm_diskerror(void){}
50    PHP_IMAP_EXPORT void mm_status(void){}
51    PHP_IMAP_EXPORT void mm_lsub(void){}
52    PHP_IMAP_EXPORT void mm_list(void){}
53    PHP_IMAP_EXPORT void mm_exists(void){}
54    PHP_IMAP_EXPORT void mm_searched(void){}
55    PHP_IMAP_EXPORT void mm_expunged(void){}
56  ])
57])
58
59AC_DEFUN([PHP_IMAP_KRB_CHK], [
60  if test "$PHP_KERBEROS" != "no"; then
61    PKG_CHECK_MODULES([KERBEROS], [krb5-gssapi krb5])
62
63    PHP_EVAL_INCLINE($KERBEROS_CFLAGS)
64    PHP_EVAL_LIBLINE($KERBEROS_LIBS, IMAP_SHARED_LIBADD)
65
66    AC_DEFINE(HAVE_IMAP_KRB, 1, [Whether IMAP extension has Kerberos support])
67  else
68    AC_EGREP_HEADER(auth_gss, $IMAP_INC_DIR/linkage.h, [
69      AC_MSG_ERROR([This c-client library is built with Kerberos support.
70
71      Add --with-kerberos to your configure line. Check config.log for details.
72      ])
73    ])
74  fi
75])
76
77AC_DEFUN([PHP_IMAP_SSL_CHK], [
78  if test "$PHP_IMAP_SSL" != "no"; then
79    if test "$PHP_OPENSSL" = ""; then
80      PHP_OPENSSL='no'
81    fi
82    PHP_SETUP_OPENSSL(IMAP_SHARED_LIBADD,
83    [
84      AC_DEFINE(HAVE_IMAP_SSL,1,[ ])
85    ], [
86      AC_MSG_ERROR([OpenSSL libraries not found.
87
88      Check whether openssl is on your PKG_CONFIG_PATH and the output in config.log)
89      ])
90    ])
91  elif test -f "$IMAP_INC_DIR/linkage.c"; then
92    AC_EGREP_HEADER(ssl_onceonlyinit, $IMAP_INC_DIR/linkage.c, [
93      AC_MSG_ERROR([This c-client library is built with SSL support.
94
95      Add --with-imap-ssl to your configure line. Check config.log for details.
96      ])
97    ])
98  fi
99])
100
101PHP_ARG_WITH([imap],
102  [for IMAP support],
103  [AS_HELP_STRING([[--with-imap[=DIR]]],
104    [Include IMAP support. DIR is the c-client install prefix])])
105
106PHP_ARG_WITH([kerberos],
107  [for IMAP Kerberos support],
108  [AS_HELP_STRING([--with-kerberos],
109    [IMAP: Include Kerberos support])],
110  [no],
111  [no])
112
113PHP_ARG_WITH([imap-ssl],
114  [for IMAP SSL support],
115  [AS_HELP_STRING([[--with-imap-ssl]],
116    [IMAP: Include SSL support])],
117  [no],
118  [no])
119
120if test "$PHP_IMAP" != "no"; then
121    PHP_SUBST(IMAP_SHARED_LIBADD)
122    PHP_NEW_EXTENSION(imap, php_imap.c, $ext_shared,, -DZEND_ENABLE_STATIC_TSRMLS_CACHE=1)
123    AC_DEFINE(HAVE_IMAP,1,[ ])
124
125    for i in $PHP_IMAP /usr/local /usr; do
126      IMAP_INC_CHK()
127      el[]IMAP_INC_CHK(/include/c-client)
128      el[]IMAP_INC_CHK(/include/imap)
129      el[]IMAP_INC_CHK(/include)
130      el[]IMAP_INC_CHK(/imap)
131      el[]IMAP_INC_CHK(/c-client)
132      fi
133    done
134
135    dnl Check for c-client version 2004
136    AC_EGREP_HEADER(mail_fetch_overview_sequence, $IMAP_INC_DIR/mail.h, [
137      AC_DEFINE(HAVE_IMAP2004,1,[ ])
138    ])
139
140    dnl Check for new version of the utf8_mime2text() function
141    old_CFLAGS=$CFLAGS
142    CFLAGS="-I$IMAP_INC_DIR"
143    AC_CACHE_CHECK(for utf8_mime2text signature, ac_cv_utf8_mime2text,
144      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
145#include <stdio.h>
146#include <c-client.h>
147      ]],[[
148        SIZEDTEXT *src, *dst;
149        utf8_mime2text(src, dst);
150      ]])],[
151        ac_cv_utf8_mime2text=old
152      ],[
153        ac_cv_utf8_mime2text=new
154      ])
155    )
156    if test "$ac_cv_utf8_mime2text" = "new"; then
157      AC_DEFINE(HAVE_NEW_MIME2TEXT, 1, [Whether utf8_mime2text() has new signature])
158    fi
159    CFLAGS=$old_CFLAGS
160
161    old_CFLAGS=$CFLAGS
162    CFLAGS="-I$IMAP_INC_DIR"
163    AC_CACHE_CHECK(for U8T_DECOMPOSE, ac_cv_u8t_decompose,
164      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
165#include <c-client.h>
166      ]],[[
167         int i = U8T_CANONICAL;
168      ]])],[
169         ac_cv_u8t_decompose=yes
170      ],[
171         ac_cv_u8t_decompose=no
172      ])
173    )
174    CFLAGS=$old_CFLAGS
175
176    if test "$ac_cv_u8t_decompose" = "no" && test "$ac_cv_utf8_mime2text" = "new"; then
177		AC_MSG_ERROR([utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.])
178    fi
179    if test "$ac_cv_u8t_decompose" = "yes" && test "$ac_cv_utf8_mime2text" = "old"; then
180		AC_MSG_ERROR([utf8_mime2text() has old signature, but U8T_CANONICAL is present. This should not happen. Check config.log for additional information.])
181    fi
182
183    dnl Check for c-client version 2001
184    old_CPPFLAGS=$CPPFLAGS
185    CPPFLAGS=-I$IMAP_INC_DIR
186    AC_EGREP_CPP(this_is_true, [
187#include "imap4r1.h"
188#if defined(IMAPSSLPORT)
189      this_is_true
190#endif
191    ],[
192      AC_DEFINE(HAVE_IMAP2001, 1, [ ])
193    ],[])
194    CPPFLAGS=$old_CPPFLAGS
195
196    PHP_CHECK_LIBRARY(pam, pam_start,
197    [
198      PHP_ADD_LIBRARY(pam,, IMAP_SHARED_LIBADD)
199      AC_DEFINE(HAVE_LIBPAM,1,[ ])
200    ])
201
202    PHP_CHECK_LIBRARY(crypt, crypt,
203    [
204      PHP_ADD_LIBRARY(crypt,, IMAP_SHARED_LIBADD)
205      AC_DEFINE(HAVE_LIBCRYPT,1,[ ])
206    ])
207
208    PHP_EXPAND_PATH($IMAP_DIR, IMAP_DIR)
209
210    if test -z "$IMAP_DIR"; then
211      AC_MSG_ERROR(Cannot find rfc822.h. Please check your c-client installation.)
212    fi
213
214    if test ! -r "$IMAP_DIR/c-client/libc-client.a" && test -r "$IMAP_DIR/c-client/c-client.a" ; then
215      ln -s "$IMAP_DIR/c-client/c-client.a" "$IMAP_DIR/c-client/libc-client.a" >/dev/null 2>&1
216    elif test ! -r "$IMAP_DIR/$PHP_LIBDIR/libc-client.a" && test -r "$IMAP_DIR/$PHP_LIBDIR/c-client.a"; then
217      ln -s "$IMAP_DIR/$PHP_LIBDIR/c-client.a" "$IMAP_DIR/$PHP_LIBDIR/libc-client.a" >/dev/null 2>&1
218    fi
219
220    for lib in c-client4 c-client imap; do
221      IMAP_LIB=$lib
222      IMAP_LIB_CHK($PHP_LIBDIR)
223      IMAP_LIB_CHK(c-client)
224    done
225
226    if test -z "$IMAP_LIBDIR"; then
227      AC_MSG_ERROR(Cannot find imap library (libc-client.a). Please check your c-client installation.)
228    fi
229
230    PHP_ADD_INCLUDE($IMAP_INC_DIR)
231    PHP_ADD_LIBRARY_DEFER($IMAP_LIB,, IMAP_SHARED_LIBADD)
232    PHP_ADD_LIBPATH($IMAP_LIBDIR, IMAP_SHARED_LIBADD)
233    PHP_IMAP_KRB_CHK
234    PHP_IMAP_SSL_CHK
235
236    dnl Test the build in the end
237    TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD"
238
239    dnl Check if auth_gss exists
240    PHP_IMAP_TEST_BUILD(auth_gssapi_valid, [
241      AC_DEFINE(HAVE_IMAP_AUTH_GSS, 1, [ ])
242    ], [], $TST_LIBS)
243
244    dnl Check if utf8_to_mutf7 exists.
245    old_CPPFLAGS="${CPPFLAGS}"
246    CPPFLAGS="${CPPFLAGS} -I${IMAP_INC_DIR}"
247    AC_LANG_PUSH(C)
248    AC_CACHE_CHECK(for utf8_to_mutf7, ac_cv_utf8_to_mutf7,
249      AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <c-client.h>]],[[
250        unsigned char c = '\0';
251        utf8_to_mutf7(&c);
252      ]])],[
253        AC_DEFINE(HAVE_IMAP_MUTF7, 1, [ ])
254        ac_cv_utf8_to_mutf7=yes
255      ],[
256        ac_cv_utf8_to_mutf7=no
257      ])
258    )
259    AC_LANG_POP
260
261
262    AC_MSG_CHECKING(whether rfc822_output_address_list function present)
263    PHP_TEST_BUILD(foobar, [
264      AC_MSG_RESULT(yes)
265      AC_DEFINE(HAVE_RFC822_OUTPUT_ADDRESS_LIST, 1, [ ])
266    ], [
267      AC_MSG_RESULT(no)
268	], [
269      $TST_LIBS
270    ], [
271#if defined(__GNUC__) && __GNUC__ >= 4
272# define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
273#else
274# define PHP_IMAP_EXPORT
275#endif
276
277      PHP_IMAP_EXPORT void mm_log(void){}
278      PHP_IMAP_EXPORT void mm_dlog(void){}
279      PHP_IMAP_EXPORT void mm_flags(void){}
280      PHP_IMAP_EXPORT void mm_fatal(void){}
281      PHP_IMAP_EXPORT void mm_critical(void){}
282      PHP_IMAP_EXPORT void mm_nocritical(void){}
283      PHP_IMAP_EXPORT void mm_notify(void){}
284      PHP_IMAP_EXPORT void mm_login(void){}
285      PHP_IMAP_EXPORT void mm_diskerror(void){}
286      PHP_IMAP_EXPORT void mm_status(void){}
287      PHP_IMAP_EXPORT void mm_lsub(void){}
288      PHP_IMAP_EXPORT void mm_list(void){}
289      PHP_IMAP_EXPORT void mm_exists(void){}
290      PHP_IMAP_EXPORT void mm_searched(void){}
291      PHP_IMAP_EXPORT void mm_expunged(void){}
292      void rfc822_output_address_list(void);
293      void (*f)(void);
294      char foobar () {f = rfc822_output_address_list;}
295    ])
296
297    AC_MSG_CHECKING(whether build with IMAP works)
298    PHP_IMAP_TEST_BUILD(mail_newbody, [
299      AC_MSG_RESULT(yes)
300    ], [
301      AC_MSG_RESULT(no)
302      AC_MSG_ERROR([build test failed. Please check the config.log for details.])
303    ], $TST_LIBS)
304fi
305