[vlc-devel] [PATCH] build: create a macro to check for, and replace, possibly-inline functions.
Diego Elio Pettenò
flameeyes at flameeyes.eu
Mon Mar 9 21:30:26 CET 2015
mingw (both 32 and 64) provides a number of functions that have no C
linkage, but are only available as static inline. Define a macro that can
check for the function based on a preamble and body, and caches the
results.
Use the new macro for asprintf/vasprintf (previously implemented in
configure.ac directly) and for gmtime_r.
Signed-off-by: Diego Elio Pettenò <flameeyes at flameeyes.eu>
---
configure.ac | 41 ++++++++++++++++++++++++++---------------
m4/vlc.m4 | 17 +++++++++++++++++
2 files changed, 43 insertions(+), 15 deletions(-)
diff --git a/configure.ac b/configure.ac
index a2e71e2..b0b60b0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -556,26 +556,37 @@ need_libc=false
dnl Check for usual libc functions
AC_CHECK_DECLS([nanosleep],,,[#include <time.h>])
AC_CHECK_FUNCS([daemon fcntl fstatvfs fork getenv getpwuid_r isatty lstat memalign mmap open_memstream openat pread posix_fadvise posix_madvise setlocale stricmp strnicmp strptime uselocale pthread_cond_timedwait_monotonic_np pthread_condattr_setclock])
-AC_REPLACE_FUNCS([atof atoll dirfd fdopendir flockfile fsync getdelim getpid gmtime_r lldiv localtime_r nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strsep strtof strtok_r strtoll swab tdestroy strverscmp])
+AC_REPLACE_FUNCS([atof atoll dirfd fdopendir flockfile fsync getdelim getpid lldiv localtime_r nrand48 poll posix_memalign rewind setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strsep strtof strtok_r strtoll swab tdestroy strverscmp])
AC_CHECK_FUNCS(fdatasync,,
[AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])
])
dnl mingw64 implements those as static inline, not functions with C linkage
-AC_LINK_IFELSE([
- AC_LANG_PROGRAM([#include <stdio.h>], [
- char *c;
- if (asprintf(&c, "%s %d", "string", 1) == -1)
- c = NULL;
- ])],[AC_DEFINE([HAVE_ASPRINTF],[1],[Define to 1 if you have asprintf function])],[AC_LIBOBJ([asprintf])])
-AC_LINK_IFELSE([
- AC_LANG_PROGRAM([#include <stdio.h>
- #include <stdarg.h>], [
- char *c;
- va_list ap;
- if (vasprintf(&c, "%s %d", ap) == -1)
- c = NULL;
- ])],[AC_DEFINE([HAVE_VASPRINTF],[1],[Define to 1 if you have asprintf function])],[AC_LIBOBJ([vasprintf])])
+VLC_REPLACE_FUNC_INLINE([gmtime_r], [
+ #define _POSIX_C_SOURCE 200809L
+ #include <time.h>
+ ], [
+ time_t t; struct tm r;
+ gmtime_r(&t, &r);
+ ])
+
+VLC_REPLACE_FUNC_INLINE([asprintf], [
+ #include <stdio.h>
+ ], [
+ char *c;
+ if (asprintf(&c, "%s %d", "string", 1) == -1)
+ c = NULL;
+ ])
+
+VLC_REPLACE_FUNC_INLINE([vasprintf], [
+ #include <stdio.h>
+ #include <stdarg.h>
+ ], [
+ char *c;
+ va_list ap;
+ if (vasprintf(&c, "%s %d", ap) == -1)
+ c = NULL;
+ ])
dnl C11 static_assert()
AC_MSG_CHECKING([for static_assert in assert.h])
diff --git a/m4/vlc.m4 b/m4/vlc.m4
index 1adec40..686dfa0 100644
--- a/m4/vlc.m4
+++ b/m4/vlc.m4
@@ -96,3 +96,20 @@ AC_DEFUN([VLC_LIBRARY_SUFFIX], [
AC_MSG_RESULT(${LIBEXT})
AC_DEFINE_UNQUOTED(LIBEXT, "${LIBEXT}", [Dynamic object extension])
])
+
+dnl ===========================================================================
+dnl Custom macros for checking functions with inline fallback, for mingw32/64
+
+dnl VLC_REPLACE_FUNC_INLINE([funcname], [source preamble], [source body])
+AC_DEFUN([VLC_REPLACE_FUNC_INLINE], [
+ AS_VAR_PUSHDEF([CACHEVAR], [vlc_cv_replace_func_inline_] AS_TR_SH([$1]))
+ AC_CACHE_CHECK([for $1], CACHEVAR, [
+ AC_LINK_IFELSE([AC_LANG_PROGRAM([$2], [$3])],
+ AS_VAR_SET(CACHEVAR, [yes]),
+ AS_VAR_SET(CACHEVAR, [no]))
+ ])
+ AS_IF([test x"AS_VAR_GET(CACHEVAR)" = xyes],
+ [AC_DEFINE(AS_TR_CPP([HAVE_$1]), [1], [Define to 1 if you have $1 function])],
+ [AC_LIBOBJ([$1])])
+ AS_VAR_POPDEF([CACHEVAR])
+])
--
2.0.5
More information about the vlc-devel
mailing list