xref: /PHP-7.2/ext/imap/config.m4 (revision 902d39a3)
1dnl
2dnl $Id$
3dnl
4
5AC_DEFUN([IMAP_INC_CHK],[if test -r "$i$1/c-client.h"; then
6    AC_DEFINE(HAVE_IMAP2000, 1, [ ])
7    IMAP_DIR=$i
8    IMAP_INC_DIR=$i$1
9    break
10  elif test -r "$i$1/rfc822.h"; then
11    IMAP_DIR=$i;
12    IMAP_INC_DIR=$i$1
13	break
14])
15
16AC_DEFUN([IMAP_LIB_CHK],[
17  str="$IMAP_DIR/$1/lib$lib.*"
18  for i in `echo $str`; do
19    test -r $i && IMAP_LIBDIR=$IMAP_DIR/$1 && break 2
20  done
21])
22
23dnl PHP_IMAP_TEST_BUILD(function, action-if-ok, action-if-not-ok, extra-libs, extra-source)
24AC_DEFUN([PHP_IMAP_TEST_BUILD], [
25  PHP_TEST_BUILD([$1], [$2], [$3], [$4], [$5]
26  [
27#if defined(__GNUC__) && __GNUC__ >= 4
28# define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
29#else
30# define PHP_IMAP_EXPORT
31#endif
32
33    PHP_IMAP_EXPORT void mm_log(void){}
34    PHP_IMAP_EXPORT void mm_dlog(void){}
35    PHP_IMAP_EXPORT void mm_flags(void){}
36    PHP_IMAP_EXPORT void mm_fatal(void){}
37    PHP_IMAP_EXPORT void mm_critical(void){}
38    PHP_IMAP_EXPORT void mm_nocritical(void){}
39    PHP_IMAP_EXPORT void mm_notify(void){}
40    PHP_IMAP_EXPORT void mm_login(void){}
41    PHP_IMAP_EXPORT void mm_diskerror(void){}
42    PHP_IMAP_EXPORT void mm_status(void){}
43    PHP_IMAP_EXPORT void mm_lsub(void){}
44    PHP_IMAP_EXPORT void mm_list(void){}
45    PHP_IMAP_EXPORT void mm_exists(void){}
46    PHP_IMAP_EXPORT void mm_searched(void){}
47    PHP_IMAP_EXPORT void mm_expunged(void){}
48  ])
49])
50
51AC_DEFUN([PHP_IMAP_KRB_CHK], [
52  if test "$PHP_KERBEROS" != "no"; then
53    PHP_SETUP_KERBEROS(IMAP_SHARED_LIBADD,
54    [
55      AC_DEFINE(HAVE_IMAP_KRB,1,[ ])
56    ], [
57      AC_MSG_ERROR([Kerberos libraries not found.
58
59      Check the path given to --with-kerberos (if no path is given, searches in /usr/kerberos, /usr/local and /usr )
60      ])
61    ])
62  else
63    AC_EGREP_HEADER(auth_gss, $IMAP_INC_DIR/linkage.h, [
64      AC_MSG_ERROR([This c-client library is built with Kerberos support.
65
66      Add --with-kerberos to your configure line. Check config.log for details.
67      ])
68    ])
69  fi
70])
71
72AC_DEFUN([PHP_IMAP_SSL_CHK], [
73  if test "$PHP_IMAP_SSL" != "no"; then
74    if test "$PHP_OPENSSL" = ""; then
75      PHP_OPENSSL='no'
76    fi
77    PHP_SETUP_OPENSSL(IMAP_SHARED_LIBADD,
78    [
79      AC_DEFINE(HAVE_IMAP_SSL,1,[ ])
80    ], [
81      AC_MSG_ERROR([OpenSSL libraries not found.
82
83      Check the path given to --with-openssl-dir and output in config.log)
84      ])
85    ])
86  elif test -f "$IMAP_INC_DIR/linkage.c"; then
87    AC_EGREP_HEADER(ssl_onceonlyinit, $IMAP_INC_DIR/linkage.c, [
88      AC_MSG_ERROR([This c-client library is built with SSL support.
89
90      Add --with-imap-ssl to your configure line. Check config.log for details.
91      ])
92    ])
93  fi
94])
95
96
97PHP_ARG_WITH(imap,for IMAP support,
98[  --with-imap[=DIR]         Include IMAP support. DIR is the c-client install prefix])
99
100PHP_ARG_WITH(kerberos,for IMAP Kerberos support,
101[  --with-kerberos[=DIR]     IMAP: Include Kerberos support. DIR is the Kerberos install prefix], no, no)
102
103PHP_ARG_WITH(imap-ssl,for IMAP SSL support,
104[  --with-imap-ssl[=DIR]     IMAP: Include SSL support. DIR is the OpenSSL install prefix], no, no)
105
106
107if test "$PHP_IMAP" != "no"; then
108    PHP_SUBST(IMAP_SHARED_LIBADD)
109    PHP_NEW_EXTENSION(imap, php_imap.c, $ext_shared)
110    AC_DEFINE(HAVE_IMAP,1,[ ])
111
112    for i in $PHP_IMAP /usr/local /usr; do
113      IMAP_INC_CHK()
114      el[]IMAP_INC_CHK(/include/c-client)
115      el[]IMAP_INC_CHK(/include/imap)
116      el[]IMAP_INC_CHK(/include)
117      el[]IMAP_INC_CHK(/imap)
118      el[]IMAP_INC_CHK(/c-client)
119      fi
120    done
121
122    dnl Check for c-client version 2004
123    AC_EGREP_HEADER(mail_fetch_overview_sequence, $IMAP_INC_DIR/mail.h, [
124      AC_DEFINE(HAVE_IMAP2004,1,[ ])
125    ])
126
127    dnl Check for new version of the utf8_mime2text() function
128    old_CFLAGS=$CFLAGS
129    CFLAGS="-I$IMAP_INC_DIR"
130    AC_CACHE_CHECK(for utf8_mime2text signature, ac_cv_utf8_mime2text,
131      AC_TRY_COMPILE([
132#include <stdio.h>
133#include <c-client.h>
134      ],[
135        SIZEDTEXT *src, *dst;
136        utf8_mime2text(src, dst);
137      ],[
138        ac_cv_utf8_mime2text=old
139      ],[
140        ac_cv_utf8_mime2text=new
141      ])
142    )
143    if test "$ac_cv_utf8_mime2text" = "new"; then
144      AC_DEFINE(HAVE_NEW_MIME2TEXT, 1, [Whether utf8_mime2text() has new signature])
145    fi
146    CFLAGS=$old_CFLAGS
147
148    old_CFLAGS=$CFLAGS
149    CFLAGS="-I$IMAP_INC_DIR"
150    AC_CACHE_CHECK(for U8T_DECOMPOSE, ac_cv_u8t_decompose,
151      AC_TRY_COMPILE([
152#include <c-client.h>
153      ],[
154         int i = U8T_CANONICAL;
155      ],[
156         ac_cv_u8t_decompose=yes
157      ],[
158         ac_cv_u8t_decompose=no
159      ])
160    )
161    CFLAGS=$old_CFLAGS
162
163    if test "$ac_cv_u8t_decompose" = "no" && test "$ac_cv_utf8_mime2text" = "new"; then
164		AC_MSG_ERROR([utf8_mime2text() has new signature, but U8T_CANONICAL is missing. This should not happen. Check config.log for additional information.])
165    fi
166    if test "$ac_cv_u8t_decompose" = "yes" && test "$ac_cv_utf8_mime2text" = "old"; then
167		AC_MSG_ERROR([utf8_mime2text() has old signature, but U8T_CANONICAL is present. This should not happen. Check config.log for additional information.])
168    fi
169
170    dnl Check for c-client version 2001
171    old_CPPFLAGS=$CPPFLAGS
172    CPPFLAGS=-I$IMAP_INC_DIR
173    AC_EGREP_CPP(this_is_true, [
174#include "imap4r1.h"
175#if defined(IMAPSSLPORT)
176      this_is_true
177#endif
178    ],[
179      AC_DEFINE(HAVE_IMAP2001, 1, [ ])
180    ],[])
181    CPPFLAGS=$old_CPPFLAGS
182
183    PHP_CHECK_LIBRARY(pam, pam_start,
184    [
185      PHP_ADD_LIBRARY(pam,, IMAP_SHARED_LIBADD)
186      AC_DEFINE(HAVE_LIBPAM,1,[ ])
187    ])
188
189    PHP_CHECK_LIBRARY(crypt, crypt,
190    [
191      PHP_ADD_LIBRARY(crypt,, IMAP_SHARED_LIBADD)
192      AC_DEFINE(HAVE_LIBCRYPT,1,[ ])
193    ])
194
195    PHP_EXPAND_PATH($IMAP_DIR, IMAP_DIR)
196
197    if test -z "$IMAP_DIR"; then
198      AC_MSG_ERROR(Cannot find rfc822.h. Please check your c-client installation.)
199    fi
200
201    if test ! -r "$IMAP_DIR/c-client/libc-client.a" && test -r "$IMAP_DIR/c-client/c-client.a" ; then
202      ln -s "$IMAP_DIR/c-client/c-client.a" "$IMAP_DIR/c-client/libc-client.a" >/dev/null 2>&1
203    elif test ! -r "$IMAP_DIR/$PHP_LIBDIR/libc-client.a" && test -r "$IMAP_DIR/$PHP_LIBDIR/c-client.a"; then
204      ln -s "$IMAP_DIR/$PHP_LIBDIR/c-client.a" "$IMAP_DIR/$PHP_LIBDIR/libc-client.a" >/dev/null 2>&1
205    fi
206
207    for lib in c-client4 c-client imap; do
208      IMAP_LIB=$lib
209      IMAP_LIB_CHK($PHP_LIBDIR)
210      IMAP_LIB_CHK(c-client)
211    done
212
213    if test -z "$IMAP_LIBDIR"; then
214      AC_MSG_ERROR(Cannot find imap library (libc-client.a). Please check your c-client installation.)
215    fi
216
217    PHP_ADD_INCLUDE($IMAP_INC_DIR)
218    PHP_ADD_LIBRARY_DEFER($IMAP_LIB,, IMAP_SHARED_LIBADD)
219    PHP_ADD_LIBPATH($IMAP_LIBDIR, IMAP_SHARED_LIBADD)
220    PHP_IMAP_KRB_CHK
221    PHP_IMAP_SSL_CHK
222
223    dnl Test the build in the end
224    TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD"
225
226    dnl Check if auth_gss exists
227    PHP_IMAP_TEST_BUILD(auth_gssapi_valid, [
228      AC_DEFINE(HAVE_IMAP_AUTH_GSS, 1, [ ])
229    ], [], $TST_LIBS)
230
231    dnl Check if utf8_to_mutf7 exists. We need to do some gymnastics because
232    dnl utf8_to_mutf7 takes an argument and will segfault without it. We
233    dnl therefore test another function utf8_to_mutf7_php() which calls
234    dnl the utf8_to_mutf7() function with the empty string as an argument.
235    PHP_IMAP_TEST_BUILD(utf8_to_mutf7_php, [
236      AC_DEFINE(HAVE_IMAP_MUTF7, 1, [ ])
237    ], [], $TST_LIBS, [
238      char utf8_to_mutf7_php(){ return utf8_to_mutf7(""); }
239    ])
240
241    AC_MSG_CHECKING(whether rfc822_output_address_list function present)
242    PHP_TEST_BUILD(foobar, [
243      AC_MSG_RESULT(yes)
244      AC_DEFINE(HAVE_RFC822_OUTPUT_ADDRESS_LIST, 1, [ ])
245    ], [
246      AC_MSG_RESULT(no)
247	], [
248      $TST_LIBS
249    ], [
250#if defined(__GNUC__) && __GNUC__ >= 4
251# define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
252#else
253# define PHP_IMAP_EXPORT
254#endif
255
256      PHP_IMAP_EXPORT void mm_log(void){}
257      PHP_IMAP_EXPORT void mm_dlog(void){}
258      PHP_IMAP_EXPORT void mm_flags(void){}
259      PHP_IMAP_EXPORT void mm_fatal(void){}
260      PHP_IMAP_EXPORT void mm_critical(void){}
261      PHP_IMAP_EXPORT void mm_nocritical(void){}
262      PHP_IMAP_EXPORT void mm_notify(void){}
263      PHP_IMAP_EXPORT void mm_login(void){}
264      PHP_IMAP_EXPORT void mm_diskerror(void){}
265      PHP_IMAP_EXPORT void mm_status(void){}
266      PHP_IMAP_EXPORT void mm_lsub(void){}
267      PHP_IMAP_EXPORT void mm_list(void){}
268      PHP_IMAP_EXPORT void mm_exists(void){}
269      PHP_IMAP_EXPORT void mm_searched(void){}
270      PHP_IMAP_EXPORT void mm_expunged(void){}
271      void rfc822_output_address_list(void);
272      void (*f)(void);
273      char foobar () {f = rfc822_output_address_list;}
274    ])
275
276    AC_MSG_CHECKING(whether build with IMAP works)
277    PHP_IMAP_TEST_BUILD(mail_newbody, [
278      AC_MSG_RESULT(yes)
279    ], [
280      AC_MSG_RESULT(no)
281      AC_MSG_ERROR([build test failed. Please check the config.log for details.])
282    ], $TST_LIBS)
283fi
284