Skip to content

Commit 7568174

Browse files
authored
Merge pull request #11 from petk/patch-PHP_TEST_BUILD
Autotools: Refactor IMAP build tests
2 parents 2f6e5b7 + 4b8462f commit 7568174

File tree

1 file changed

+42
-20
lines changed

1 file changed

+42
-20
lines changed

config.m4

Lines changed: 42 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,23 @@ AC_DEFUN([IMAP_LIB_CHK],[
1616
done
1717
])
1818

19-
dnl PHP_IMAP_TEST_BUILD(function, action-if-ok, action-if-not-ok, extra-libs, extra-source)
19+
dnl PHP_IMAP_TEST_BUILD(function, action-if-ok, action-if-not-ok, extra-libs)
2020
dnl
2121
dnl The UW-IMAP c-client library was not originally designed to be a
2222
dnl shared library. The mm_foo functions are callbacks, and are required
2323
dnl to be implemented by the program that is linking to c-client. This
2424
dnl macro does the work of defining them all to no-ops for you. Note
25-
dnl that PHP_TEST_BUILD is a link test; the undefined symbols will only
25+
dnl that this is a link test; the undefined symbols will only
2626
dnl cause problems if you actually try to link with c-client. For
2727
dnl example, if your test is trivial enough to be optimized out, and if
2828
dnl you link with --as-needed, the test/library may be omitted entirely
2929
dnl from the final executable. In that case linking will of course
3030
dnl succeed, but your luck won't necessarily apply at lower optimization
3131
dnl levels or systems where --as-needed is not used.
3232
AC_DEFUN([PHP_IMAP_TEST_BUILD], [
33-
PHP_TEST_BUILD([$1], [$2], [$3], [$4], [$5]
34-
[
33+
old_LIBS=$LIBS
34+
LIBS="$4 $LIBS"
35+
AC_LINK_IFELSE([AC_LANG_SOURCE([
3536
#if defined(__GNUC__) && __GNUC__ >= 4
3637
# define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
3738
#else
@@ -53,6 +54,18 @@ AC_DEFUN([PHP_IMAP_TEST_BUILD], [
5354
PHP_IMAP_EXPORT void mm_exists(void){}
5455
PHP_IMAP_EXPORT void mm_searched(void){}
5556
PHP_IMAP_EXPORT void mm_expunged(void){}
57+
58+
char $1(void);
59+
int main(void) {
60+
$1();
61+
return 0;
62+
}
63+
])],[
64+
LIBS=$old_LIBS
65+
$2
66+
],[
67+
LIBS=$old_LIBS
68+
$3
5669
])
5770
])
5871

@@ -230,9 +243,10 @@ if test "$PHP_IMAP" != "no"; then
230243
TST_LIBS="$DLIBS $IMAP_SHARED_LIBADD"
231244

232245
dnl Check if auth_gss exists
233-
PHP_IMAP_TEST_BUILD(auth_gssapi_valid, [
234-
AC_DEFINE(HAVE_IMAP_AUTH_GSS, 1, [ ])
235-
], [], $TST_LIBS)
246+
PHP_IMAP_TEST_BUILD([auth_gssapi_valid],
247+
[AC_DEFINE([HAVE_IMAP_AUTH_GSS], [1], [ ])],
248+
[],
249+
[$TST_LIBS])
236250

237251
dnl Check if utf8_to_mutf7 exists.
238252
old_CPPFLAGS="${CPPFLAGS}"
@@ -252,15 +266,12 @@ if test "$PHP_IMAP" != "no"; then
252266
AC_LANG_POP
253267

254268

255-
AC_MSG_CHECKING(whether rfc822_output_address_list function present)
256-
PHP_TEST_BUILD(foobar, [
257-
AC_MSG_RESULT(yes)
258-
AC_DEFINE(HAVE_RFC822_OUTPUT_ADDRESS_LIST, 1, [ ])
259-
], [
260-
AC_MSG_RESULT(no)
261-
], [
262-
$TST_LIBS
263-
], [
269+
AC_CACHE_CHECK([whether rfc822_output_address_list function is present],
270+
[php_cv_imap_have_rfc822_output_address_list],
271+
[
272+
old_LIBS=$LIBS
273+
LIBS="$TST_LIBS $LIBS"
274+
AC_LINK_IFELSE([AC_LANG_SOURCE([
264275
#if defined(__GNUC__) && __GNUC__ >= 4
265276
# define PHP_IMAP_EXPORT __attribute__ ((visibility("default")))
266277
#else
@@ -285,13 +296,24 @@ if test "$PHP_IMAP" != "no"; then
285296
void rfc822_output_address_list(void);
286297
void (*f)(void);
287298
char foobar () {f = rfc822_output_address_list;}
299+
char foobar(void);
300+
int main(void) {
301+
foobar();
302+
return 0;
303+
}
304+
])],
305+
[php_cv_imap_have_rfc822_output_address_list=yes],
306+
[php_cv_imap_have_rfc822_output_address_list=no])
307+
LIBS=$old_LIBS
288308
])
309+
AS_VAR_IF([php_cv_imap_have_rfc822_output_address_list], [yes],
310+
[AC_DEFINE([HAVE_RFC822_OUTPUT_ADDRESS_LIST], [1],
311+
[Define to 1 if C-client has the 'rfc822_output_address_list' function.])])
289312

290313
AC_MSG_CHECKING(whether build with IMAP works)
291-
PHP_IMAP_TEST_BUILD(mail_newbody, [
292-
AC_MSG_RESULT(yes)
293-
], [
314+
PHP_IMAP_TEST_BUILD([mail_newbody],
315+
[AC_MSG_RESULT(yes)], [
294316
AC_MSG_RESULT(no)
295317
AC_MSG_ERROR([build test failed. Please check the config.log for details.])
296-
], $TST_LIBS)
318+
], [$TST_LIBS])
297319
fi

0 commit comments

Comments
 (0)