changeset 12844:aaa284caae61

sys_time: use link-warning 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>
author Eric Blake <ebb9@byu.net>
date Sat, 30 Jan 2010 08:51:59 -0700
parents ef0538387b0d
children ad16dedc2e1d
files ChangeLog lib/sys_time.in.h m4/gettimeofday.m4 m4/sys_time_h.m4 modules/gettimeofday modules/sys_time
diffstat 6 files changed, 63 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Sat Jan 30 07:44:38 2010 -0700
+++ b/ChangeLog	Sat Jan 30 08:51:59 2010 -0700
@@ -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.
--- a/lib/sys_time.in.h	Sat Jan 30 07:44:38 2010 -0700
+++ b/lib/sys_time.in.h	Sat Jan 30 08:51:59 2010 -0700
@@ -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 @@
 };
 # 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
--- a/m4/gettimeofday.m4	Sat Jan 30 07:44:38 2010 -0700
+++ b/m4/gettimeofday.m4	Sat Jan 30 08:51:59 2010 -0700
@@ -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_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 @@
 
   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 @@
 
  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.])
--- a/m4/sys_time_h.m4	Sat Jan 30 07:44:38 2010 -0700
+++ b/m4/sys_time_h.m4	Sat Jan 30 08:51:59 2010 -0700
@@ -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_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 @@
           [[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])
 ])
--- a/modules/gettimeofday	Sat Jan 30 07:44:38 2010 -0700
+++ b/modules/gettimeofday	Sat Jan 30 08:51:59 2010 -0700
@@ -10,6 +10,7 @@
 
 configure.ac:
 gl_FUNC_GETTIMEOFDAY
+gl_SYS_TIME_MODULE_INDICATOR([gettimeofday])
 
 Makefile.am:
 
--- a/modules/sys_time	Sat Jan 30 07:44:38 2010 -0700
+++ b/modules/sys_time	Sat Jan 30 08:51:59 2010 -0700
@@ -8,17 +8,18 @@
 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 @@
 	      -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 $@