sys_time: use link-warning
authorEric Blake <ebb9@byu.net>
Sat, 30 Jan 2010 15:51:59 +0000 (08:51 -0700)
committerEric Blake <ebb9@byu.net>
Mon, 1 Feb 2010 14:39:18 +0000 (07:39 -0700)
Modernize replacement header, to allow another GNULIB_POSIXCHECK
opportunity.

* m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Split defaults...
(gl_HEADER_SYS_TIME_H_DEFAULTS): ...into new macro.
(gl_SYS_TIME_MODULE_INDICATOR): New macro.
* modules/sys_time (Depends-on): Add warn-on-use.
(Makefile.am): Always build replacement.
(configure.ac): Update substitutions.
* m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY)
(gl_FUNC_GETTIMEOFDAY_CLOBBER): Include defaults, and no longer
bother with SYS_TIME_H.
* modules/gettimeofday (configure.ac): Declare indicator.
* lib/sys_time.in.h (gettimeofday): Warn if gnulib module is not
in use.

Signed-off-by: Eric Blake <ebb9@byu.net>
ChangeLog
lib/sys_time.in.h
m4/gettimeofday.m4
m4/sys_time_h.m4
modules/gettimeofday
modules/sys_time

index a812234..b89d127 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
 2010-02-01  Eric Blake  <ebb9@byu.net>
 
+       sys_time: use link-warning
+       * m4/sys_time_h.m4 (gl_HEADER_SYS_TIME_H_BODY): Split defaults...
+       (gl_HEADER_SYS_TIME_H_DEFAULTS): ...into new macro.
+       (gl_SYS_TIME_MODULE_INDICATOR): New macro.
+       * modules/sys_time (Depends-on): Add warn-on-use.
+       (Makefile.am): Always build replacement.
+       (configure.ac): Update substitutions.
+       * m4/gettimeofday.m4 (gl_FUNC_GETTIMEOFDAY)
+       (gl_FUNC_GETTIMEOFDAY_CLOBBER): Include defaults, and no longer
+       bother with SYS_TIME_H.
+       * modules/gettimeofday (configure.ac): Declare indicator.
+       * lib/sys_time.in.h (gettimeofday): Warn if gnulib module is not
+       in use.
+
        closein-tests: silence compiler warning
        * tests/test-closein.c (main): Ignore fread result.
        * modules/closein-tests (Depends-on): Add ignore-value.
index 442cae3..12f0860 100644 (file)
@@ -41,6 +41,8 @@
 
 /* The definition of _GL_ARG_NONNULL is copied here.  */
 
+/* The definition of _GL_WARN_ON_USE is copied here.  */
+
 #ifdef __cplusplus
 extern "C" {
 #endif
@@ -53,11 +55,19 @@ struct timeval
 };
 # endif
 
-# if @REPLACE_GETTIMEOFDAY@
-#  undef gettimeofday
-#  define gettimeofday rpl_gettimeofday
+# if @GNULIB_GETTIMEOFDAY@
+#  if @REPLACE_GETTIMEOFDAY@
+#   undef gettimeofday
+#   define gettimeofday rpl_gettimeofday
 extern int gettimeofday (struct timeval *restrict, void *restrict)
      _GL_ARG_NONNULL ((1));
+#  endif
+# elif defined GNULIB_POSIXCHECK
+#  undef gettimeofday
+#  if HAVE_RAW_DECL_GETTIMEOFDAY
+_GL_WARN_ON_USE (gettimeofday, "gettimeofday is unportable - "
+                "use gnulib module gettimeofday for portability");
+#  endif
 # endif
 
 #ifdef __cplusplus
index 735123e..2155627 100644 (file)
@@ -1,4 +1,4 @@
-# serial 12
+# serial 13
 
 # Copyright (C) 2001-2003, 2005, 2007, 2009-2010 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -11,6 +11,7 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
 [
   AC_REQUIRE([AC_C_RESTRICT])
   AC_REQUIRE([gl_HEADER_SYS_TIME_H])
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
   AC_CHECK_FUNCS_ONCE([gettimeofday])
 
   AC_CACHE_CHECK([for gettimeofday with POSIX signature],
@@ -32,7 +33,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY],
 
   if test $gl_cv_func_gettimeofday_posix_signature != yes; then
     REPLACE_GETTIMEOFDAY=1
-    SYS_TIME_H=sys/time.h
     if test $gl_cv_func_gettimeofday_clobber != yes; then
       AC_LIBOBJ([gettimeofday])
       gl_PREREQ_GETTIMEOFDAY
@@ -78,7 +78,6 @@ AC_DEFUN([gl_FUNC_GETTIMEOFDAY_CLOBBER],
 
  if test $gl_cv_func_gettimeofday_clobber = yes; then
    REPLACE_GETTIMEOFDAY=1
-   SYS_TIME_H=sys/time.h
    gl_GETTIMEOFDAY_REPLACE_LOCALTIME
    AC_DEFINE([GETTIMEOFDAY_CLOBBERS_LOCALTIME], [1],
      [Define if gettimeofday clobbers the localtime buffer.])
index 9c16487..b14bc4b 100644 (file)
@@ -1,5 +1,5 @@
 # Configure a replacement for <sys/time.h>.
-# serial 2
+# serial 3
 
 # Copyright (C) 2007, 2009, 2010 Free Software Foundation, Inc.
 # This file is free software; the Free Software Foundation
@@ -19,15 +19,13 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H],
 AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
 [
   AC_REQUIRE([AC_C_RESTRICT])
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
   AC_CHECK_HEADERS_ONCE([sys/time.h])
   gl_CHECK_NEXT_HEADERS([sys/time.h])
 
-  if test $ac_cv_header_sys_time_h = yes; then
-    HAVE_SYS_TIME_H=1
-  else
+  if test $ac_cv_header_sys_time_h != yes; then
     HAVE_SYS_TIME_H=0
   fi
-  AC_SUBST([HAVE_SYS_TIME_H])
 
   AC_CACHE_CHECK([for struct timeval], [gl_cv_sys_struct_timeval],
     [AC_COMPILE_IFELSE(
@@ -40,20 +38,32 @@ AC_DEFUN([gl_HEADER_SYS_TIME_H_BODY],
           [[static struct timeval x; x.tv_sec = x.tv_usec;]])],
        [gl_cv_sys_struct_timeval=yes],
        [gl_cv_sys_struct_timeval=no])])
-  if test $gl_cv_sys_struct_timeval = yes; then
-    HAVE_STRUCT_TIMEVAL=1
-  else
+  if test $gl_cv_sys_struct_timeval != yes; then
     HAVE_STRUCT_TIMEVAL=0
   fi
-  AC_SUBST([HAVE_STRUCT_TIMEVAL])
 
+  dnl Check for declarations of anything we want to poison if the
+  dnl corresponding gnulib module is not in use.
+  gl_WARN_ON_USE_PREPARE([[
+#if HAVE_SYS_TIME_H
+# include <sys/time.h>
+#endif
+#include <time.h>
+    ]], [gettimeofday])
+])
+
+AC_DEFUN([gl_SYS_TIME_MODULE_INDICATOR],
+[
+  dnl Use AC_REQUIRE here, so that the default settings are expanded once only.
+  AC_REQUIRE([gl_HEADER_SYS_TIME_H_DEFAULTS])
+  GNULIB_[]m4_translit([$1],[abcdefghijklmnopqrstuvwxyz./-],[ABCDEFGHIJKLMNOPQRSTUVWXYZ___])=1
+])
+
+AC_DEFUN([gl_HEADER_SYS_TIME_H_DEFAULTS],
+[
+  GNULIB_GETTIMEOFDAY=0;     AC_SUBST([GNULIB_GETTIMEOFDAY])
   dnl Assume POSIX behavior unless another module says otherwise.
-  REPLACE_GETTIMEOFDAY=0
-  AC_SUBST([REPLACE_GETTIMEOFDAY])
-  if test $HAVE_SYS_TIME_H = 0 || test $HAVE_STRUCT_TIMEVAL = 0; then
-    SYS_TIME_H=sys/time.h
-  else
-    SYS_TIME_H=
-  fi
-  AC_SUBST([SYS_TIME_H])
+  HAVE_STRUCT_TIMEVAL=1;     AC_SUBST([HAVE_STRUCT_TIMEVAL])
+  HAVE_SYS_TIME_H=1;         AC_SUBST([HAVE_SYS_TIME_H])
+  REPLACE_GETTIMEOFDAY=0;    AC_SUBST([REPLACE_GETTIMEOFDAY])
 ])
index 0913cf1..979f601 100644 (file)
@@ -10,6 +10,7 @@ sys_time
 
 configure.ac:
 gl_FUNC_GETTIMEOFDAY
+gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
 
 Makefile.am:
 
index f0789e5..28d902e 100644 (file)
@@ -8,17 +8,18 @@ m4/sys_time_h.m4
 Depends-on:
 include_next
 arg-nonnull
+warn-on-use
 
 configure.ac:
 gl_HEADER_SYS_TIME_H
 AC_PROG_MKDIR_P
 
 Makefile.am:
-BUILT_SOURCES += $(SYS_TIME_H)
+BUILT_SOURCES += sys/time.h
 
 # We need the following in order to create <sys/time.h> when the system
 # doesn't have one that works with the given compiler.
-sys/time.h: sys_time.in.h $(ARG_NONNULL_H)
+sys/time.h: sys_time.in.h $(WARN_ON_USE_H) $(ARG_NONNULL_H)
        $(AM_V_at)$(MKDIR_P) sys
        $(AM_V_GEN)rm -f $@-t $@ && \
        { echo '/* DO NOT EDIT! GENERATED AUTOMATICALLY! */'; \
@@ -26,9 +27,11 @@ sys/time.h: sys_time.in.h $(ARG_NONNULL_H)
              -e 's|@''INCLUDE_NEXT''@|$(INCLUDE_NEXT)|g' \
              -e 's|@''PRAGMA_SYSTEM_HEADER''@|@PRAGMA_SYSTEM_HEADER@|g' \
              -e 's|@''NEXT_SYS_TIME_H''@|$(NEXT_SYS_TIME_H)|g' \
-             -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \
+             -e 's/@''GNULIB_GETTIMEOFDAY''@/$(GNULIB_GETTIMEOFDAY)/g' \
              -e 's/@''HAVE_STRUCT_TIMEVAL''@/$(HAVE_STRUCT_TIMEVAL)/g' \
+             -e 's/@''REPLACE_GETTIMEOFDAY''@/$(REPLACE_GETTIMEOFDAY)/g' \
              -e '/definition of _GL_ARG_NONNULL/r $(ARG_NONNULL_H)' \
+             -e '/definition of _GL_WARN_ON_USE/r $(WARN_ON_USE_H)' \
              < $(srcdir)/sys_time.in.h; \
        } > $@-t && \
        mv $@-t $@