diff options
author | Martin Storsjo <martin@martin.st> | 2018-06-14 12:53:42 +0300 |
---|---|---|
committer | Nikos Mavrogiannopoulos <nmav@gnutls.org> | 2018-06-16 15:22:34 +0200 |
commit | 8a2ee790126f2ef4bb6ba9987e05d70d2f07ed1e (patch) | |
tree | 42900d6bce66bcd28d7629731bf2495211d458cb | |
parent | e4c2963add8a1173e6e33a789a6f5b131cb65a5a (diff) | |
download | gnutls-8a2ee790126f2ef4bb6ba9987e05d70d2f07ed1e.tar.gz |
configure: Check for clock_gettime and fmemopen using a proper test
Don't use AC_CHECK_FUNCS for these functions, but actually test by
including the real header that defines the functions. This allows
the macOS version selection work as intended, making the references
to these functions weak if targeting a version of macOS where these
functions aren't available. Thanks to -no_weak_imports, these weak
references end up in failed linker tests, marking the functions as
unavailable.
This fixes issue #142.
Signed-off-by: Martin Storsjo <martin@martin.st>
-rw-r--r-- | configure.ac | 19 |
1 files changed, 18 insertions, 1 deletions
diff --git a/configure.ac b/configure.ac index 53adee922a..8acce4d167 100644 --- a/configure.ac +++ b/configure.ac @@ -293,7 +293,24 @@ AC_C_BIGENDIAN dnl No fork on MinGW, disable some self-tests until we fix them. dnl Check clock_gettime and pthread_mutex_lock in libc (avoid linking to other libs) -AC_CHECK_FUNCS([fork setitimer inet_ntop inet_pton getrusage getpwuid_r nanosleep daemon getpid clock_gettime localtime fmemopen vasprintf mmap],,) +AC_CHECK_FUNCS([fork setitimer inet_ntop inet_pton getrusage getpwuid_r nanosleep daemon getpid localtime vasprintf mmap],,) +dnl Manually check some functions by including headers first. On macOS, you +dnl normally only have the latest SDK available, containing all existing +dnl functions, but having them restricted according to target version in +dnl headers. If we bypass the headers and just try linking (as AC_CHECK_FUNCS +dnl does), we will accidentally detect functions which we shouldn't use. Set +dnl ac_cv_func_* as well, to avoid later AC_CHECK_FUNCS from other included +dnl scripts from overriding it. +AC_MSG_CHECKING([for clock_gettime]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <time.h>], [clock_gettime(0, 0);])], + [AC_MSG_RESULT(yes); ac_cv_func_clock_gettime=yes + AC_DEFINE([HAVE_CLOCK_GETTIME], 1, [Define to 1 if you have the `clock_gettime' function.])], + [AC_MSG_RESULT(no); ac_cv_func_clock_gettime=no]) +AC_MSG_CHECKING([for fmemopen]) +AC_LINK_IFELSE([AC_LANG_PROGRAM([#include <stdio.h>], [fmemopen(0, 0, 0);])], + [AC_MSG_RESULT(yes); ac_cv_func_fmemopen=yes + AC_DEFINE([HAVE_FMEMOPEN], 1, [Define to 1 if you have the `fmemopen' function.])], + [AC_MSG_RESULT(no); ac_cv_func_fmemopen=no]) if test "$ac_cv_func_vasprintf" != "yes";then AC_MSG_CHECKING([for va_copy]) AC_LINK_IFELSE([AC_LANG_PROGRAM([ |