build: Detect gmtime_* definitions via configure

This improves the portability of the codebase and fixes compilation
with mingw-w64 7.0+.

Co-authored-by: fanquake <fanquake@gmail.com>

Zcash: We do not yet have FormatISO8601DateTime or FormatISO8601Date,
so those parts of the backport are omitted.

(cherry-picked from commit bitcoin/bitcoin@a46484c8b3)
This commit is contained in:
Ben Woosley 2020-03-18 15:23:25 -07:00 committed by Kris Nuttycombe
parent e03b964abf
commit 66725e686c
1 changed files with 17 additions and 0 deletions

View File

@ -686,6 +686,22 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <sys/socket.h>]],
[ AC_MSG_RESULT(no)] [ AC_MSG_RESULT(no)]
) )
dnl check for gmtime_r(), fallback to gmtime_s() if that is unavailable
dnl fail if neither are available.
AC_MSG_CHECKING(for gmtime_r)
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
[[ gmtime_r((const time_t *) nullptr, (struct tm *) nullptr); ]])],
[ AC_MSG_RESULT(yes); AC_DEFINE(HAVE_GMTIME_R, 1, [Define this symbol if gmtime_r is available]) ],
[ AC_MSG_RESULT(no);
AC_MSG_CHECKING(for gmtime_s);
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include <ctime>]],
[[ gmtime_s((struct tm *) nullptr, (const time_t *) nullptr); ]])],
[ AC_MSG_RESULT(yes)],
[ AC_MSG_RESULT(no); AC_MSG_ERROR(Both gmtime_r and gmtime_s are unavailable) ]
)
]
)
AC_MSG_CHECKING([for visibility attribute]) AC_MSG_CHECKING([for visibility attribute])
AC_LINK_IFELSE([AC_LANG_SOURCE([ AC_LINK_IFELSE([AC_LANG_SOURCE([
int foo_def( void ) __attribute__((visibility("default"))); int foo_def( void ) __attribute__((visibility("default")));
@ -1008,6 +1024,7 @@ AC_SUBST(LEVELDB_TARGET_FLAGS)
AC_SUBST(EVENT_LIBS) AC_SUBST(EVENT_LIBS)
AC_SUBST(EVENT_PTHREADS_LIBS) AC_SUBST(EVENT_PTHREADS_LIBS)
AC_SUBST(ZMQ_LIBS) AC_SUBST(ZMQ_LIBS)
AC_SUBST(HAVE_GMTIME_R)
AC_SUBST(LIBZCASH_LIBS) AC_SUBST(LIBZCASH_LIBS)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile src/test/buildenv.py]) AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile src/test/buildenv.py])
AC_CONFIG_FILES([qa/pull-tester/tests_config.ini],[chmod +x qa/pull-tester/tests_config.ini]) AC_CONFIG_FILES([qa/pull-tester/tests_config.ini],[chmod +x qa/pull-tester/tests_config.ini])