From adee81fe60077d03345c94e3780752a8c2c712cf Mon Sep 17 00:00:00 2001 From: Florian Forster Date: Thu, 30 Dec 2010 09:54:15 +0100 Subject: [PATCH] Build system: Check whether X/Open flags are required for strptime. This hopefully resolved problems under Solaris, where X/Open compatibility pulls in a long list of other standards you have to stick to. For example, we don't want to force the user to use a C99 compiler. --- configure.in | 76 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- src/bind.c | 14 ++++++++--- 2 files changed, 83 insertions(+), 7 deletions(-) diff --git a/configure.in b/configure.in index 60b740c8..985e8482 100644 --- a/configure.in +++ b/configure.in @@ -614,9 +614,77 @@ AC_CHECK_FUNCS(thread_info, [have_thread_info="yes"], [have_thread_info="no"]) AC_CHECK_FUNCS(statfs, [have_statfs="yes"], [have_statfs="no"]) AC_CHECK_FUNCS(statvfs, [have_statvfs="yes"], [have_statvfs="no"]) AC_CHECK_FUNCS(getifaddrs, [have_getifaddrs="yes"], [have_getifaddrs="no"]) +AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"]) AC_CHECK_FUNCS(syslog, [have_syslog="yes"], [have_syslog="no"]) AC_CHECK_FUNCS(getutent, [have_getutent="yes"], [have_getutent="no"]) AC_CHECK_FUNCS(getutxent, [have_getutxent="yes"], [have_getutxent="no"]) + +# Check for strptime {{{ +if test "x$GCC" = "xyes" +then + SAVE_CFLAGS="$CFLAGS" + CFLAGS="$CFLAGS -Wall -Wextra -Werror" +fi + +AC_CHECK_FUNCS(strptime, [have_strptime="yes"], [have_strptime="no"]) +if test "x$have_strptime" = "xyes" +then + AC_CACHE_CHECK([whether strptime is exported by default], + [c_cv_have_strptime_default], + AC_COMPILE_IFELSE( +AC_LANG_PROGRAM( +[[ +AC_INCLUDES_DEFAULT +#include +]], +[[ + struct tm stm; + (void) strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm); +]]), + [c_cv_have_strptime_default="yes"], + [c_cv_have_strptime_default="no"])) +fi +if test "x$have_strptime" = "xyes" && test "x$c_cv_have_strptime_default" = "xno" +then + AC_CACHE_CHECK([whether strptime needs standards mode], + [c_cv_have_strptime_standards], + AC_COMPILE_IFELSE( +AC_LANG_PROGRAM( +[[ +#ifndef _ISOC99_SOURCE +# define _ISOC99_SOURCE 1 +#endif +#ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +#endif +#ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE 500 +#endif +AC_INCLUDES_DEFAULT +#include +]], +[[ + struct tm stm; + (void) strptime ("2010-12-30%13:42:42", "%Y-%m-%dT%T", &stm); +]]), + [c_cv_have_strptime_standards="yes"], + [c_cv_have_strptime_standards="no"])) + + if test "x$c_cv_have_strptime_standards" = "xyes" + then + AC_DEFINE([STRPTIME_NEEDS_STANDARDS], 1, [Set to true if strptime is only exported in X/Open mode (GNU libc).]) + else + have_strptime="no" + fi +fi + +if test "x$GCC" = "xyes" +then + CFLAGS="$SAVE_CFLAGS" +fi + +# }}} Check for strptime + AC_CHECK_FUNCS(swapctl, [have_swapctl="yes"], [have_swapctl="no"]) if test "x$have_swapctl" = "xyes"; then AC_CACHE_CHECK([whether swapctl takes two arguments], @@ -668,9 +736,6 @@ if test "x$have_swapctl" = "xyes"; then fi fi -# For load module -AC_CHECK_FUNCS(getloadavg, [have_getloadavg="yes"], [have_getloadavg="no"]) - # Check for NAN AC_ARG_WITH(nan-emulation, [AS_HELP_STRING([--with-nan-emulation], [use emulated NAN. For crosscompiling only.])], [ @@ -4381,7 +4446,10 @@ fi if test "x$with_libcurl" = "xyes" && test "x$with_libxml2" = "xyes" then plugin_ascent="yes" - plugin_bind="yes" + if test "x$have_strptime" = "xyes" + then + plugin_bind="yes" + fi fi if test "x$with_libopenipmipthread" = "xyes" diff --git a/src/bind.c b/src/bind.c index 497fcb65..db8a891f 100644 --- a/src/bind.c +++ b/src/bind.c @@ -23,9 +23,17 @@ #include "config.h" -#ifndef _XOPEN_SOURCE -# define _XOPEN_SOURCE 600 /* glibc2 needs this for strptime */ -#endif +#if STRPTIME_NEEDS_STANDARDS +# ifndef _ISOC99_SOURCE +# define _ISOC99_SOURCE 1 +# endif +# ifndef _POSIX_C_SOURCE +# define _POSIX_C_SOURCE 200112L +# endif +# ifndef _XOPEN_SOURCE +# define _XOPEN_SOURCE 500 +# endif +#endif /* STRPTIME_NEEDS_STANDARDS */ #include "collectd.h" #include "common.h" -- 2.11.0