From: Bruno Haible <[EMAIL PROTECTED]>
Date: Mon, 17 Jul 2000 17:23:34 +0200 (CEST)
Here is a patch to convert this 'if' test to a configure time test, thus
avoiding the dependency on librt when the function clock_gettime is not
really used.
That looks like a good approach to work around the linker problem.
I can see some improvements, though:
* The check for high resolution file timestamps can be done at compile-time,
not at run-time, thus avoiding the need to worry about cross-compiling
when configuring.
* I don't see the need to rename FILE_TIMESTAMP_HI_RES to
HAVE_HI_RES_FILE_TIMESTAMP. The latter name is a bit misleading, since
it's sometimes zero even when the host has high resolution file timestamps.
Avoiding the rename simplifies the patch.
How about this patch instead? It assumes all the previous patches
I've submitted for make 3.79.1.
2000-07-23 Bruno Haible <[EMAIL PROTECTED]>
and Paul Eggert <[EMAIL PROTECTED]>
* file.c (file_timestamp_now):
Use preprocessor-time check for FILE_TIMESTAMP_HI_RES
so that clock_gettime is not linked unless needed.
* filedef.h (FILE_TIMESTAMP_HI_RES):
Remove definition; "configure" now does this.
* configure.in (jm_AC_TYPE_UINTMAX_T): Move up,
to before high resolution file timestamp check,
since that check now uses uintmax_t.
(FILE_TIMESTAMP_HI_RES): Define to nonzero if the code should use
high resolution file timestamps.
(HAVE_CLOCK_GETTIME): Do not define if !FILE_TIMESTAMP_HI_RES,
so that we don't link in clock_gettime unnecessarily.
===================================================================
RCS file: configure.in,v
retrieving revision 3.79.1.0
retrieving revision 3.79.1.1
diff -pu -r3.79.1.0 -r3.79.1.1
--- configure.in 2000/06/23 16:09:41 3.79.1.0
+++ configure.in 2000/07/23 07:22:51 3.79.1.1
@@ -53,10 +53,39 @@ AC_ARG_ENABLE(nsec-timestamps,
[make_cv_nsec_timestamps="$enableval"],
[make_cv_nsec_timestamps="yes"])
+jm_AC_TYPE_UINTMAX_T
if test "x$make_cv_nsec_timestamps" != xno; then
AC_STRUCT_ST_MTIM_NSEC
+ AC_MSG_CHECKING([whether to use high resolution file timestamps])
+ AC_CACHE_VAL(make_cv_file_timestamp_hi_res, [
+ make_cv_file_timestamp_hi_res=no
+ if test $ac_cv_struct_st_mtim_nsec != no; then
+ AC_TRY_COMPILE([
+# if HAVE_INTTYPES_H
+# include <inttypes.h>
+# endif],
+ [char a[0x7fffffff < (uintmax_t) -1 >> 30 ? 1 : -1];],
+ make_cv_file_timestamp_hi_res=yes)
+ fi])
+ AC_MSG_RESULT($make_cv_file_timestamp_hi_res)
+ if test $make_cv_file_timestamp_hi_res = yes; then
+ val=1
+ else
+ val=0
+ fi
+ AC_DEFINE_UNQUOTED(FILE_TIMESTAMP_HI_RES, $val,
+ [Use high resolution file timestamps if nonzero.])
+
+ if test $make_cv_file_timestamp_hi_res = yes; then
+ # Solaris 2.5.1 needs -lposix4 to get the clock_gettime function.
+ # Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
+ AC_SEARCH_LIBS(clock_gettime, [rt posix4])
+ if test "$ac_cv_search_clock_gettime" != no; then
+ AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
+ [Define if you have the clock_gettime function.])
+ fi
+ fi
fi
-jm_AC_TYPE_UINTMAX_T
AC_SUBST(LIBOBJS)
@@ -73,14 +102,6 @@ changequote([,])dnl
fi
AC_MSG_RESULT($ac_cv_check_symbol_$1)])dnl
-# Solaris 2.5.1 needs -lposix4 to get the clock_gettime function.
-# Solaris 7 prefers the library name -lrt to the obsolescent name -lposix4.
-AC_SEARCH_LIBS(clock_gettime, [rt posix4])
-if test "$ac_cv_search_clock_gettime" != no; then
- AC_DEFINE(HAVE_CLOCK_GETTIME, 1,
- [Define if you have the clock_gettime function.])
-fi
-
# See if we have a standard version of gettimeofday(). Since actual
# implementations can differ, just make sure we have the most common
# one.
===================================================================
RCS file: file.c,v
retrieving revision 3.79.1.1
retrieving revision 3.79.1.2
diff -pu -r3.79.1.1 -r3.79.1.2
--- file.c 2000/07/07 07:01:18 3.79.1.1
+++ file.c 2000/07/23 07:22:51 3.79.1.2
@@ -592,33 +592,32 @@ file_timestamp_now (int *resolution)
/* Don't bother with high-resolution clocks if file timestamps have
only one-second resolution. The code below should work, but it's
not worth the hassle of debugging it on hosts where it fails. */
- if (FILE_TIMESTAMP_HI_RES)
- {
-#if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
+#if FILE_TIMESTAMP_HI_RES
+# if HAVE_CLOCK_GETTIME && defined CLOCK_REALTIME
+ {
+ struct timespec timespec;
+ if (clock_gettime (CLOCK_REALTIME, ×pec) == 0)
{
- struct timespec timespec;
- if (clock_gettime (CLOCK_REALTIME, ×pec) == 0)
- {
- r = 1;
- s = timespec.tv_sec;
- ns = timespec.tv_nsec;
- goto got_time;
- }
+ r = 1;
+ s = timespec.tv_sec;
+ ns = timespec.tv_nsec;
+ goto got_time;
}
-#endif
-#if HAVE_GETTIMEOFDAY
+ }
+# endif
+# if HAVE_GETTIMEOFDAY
+ {
+ struct timeval timeval;
+ if (gettimeofday (&timeval, 0) == 0)
{
- struct timeval timeval;
- if (gettimeofday (&timeval, 0) == 0)
- {
- r = 1000;
- s = timeval.tv_sec;
- ns = timeval.tv_usec * 1000;
- goto got_time;
- }
+ r = 1000;
+ s = timeval.tv_sec;
+ ns = timeval.tv_usec * 1000;
+ goto got_time;
}
+ }
+# endif
#endif
- }
r = 1000000000;
s = time ((time_t *) 0);
===================================================================
RCS file: filedef.h,v
retrieving revision 3.79.1.1
retrieving revision 3.79.1.2
diff -pu -r3.79.1.1 -r3.79.1.2
--- filedef.h 2000/07/07 07:01:18 3.79.1.1
+++ filedef.h 2000/07/23 07:22:51 3.79.1.2
@@ -110,13 +110,10 @@ extern void set_command_state PARAMS ((s
extern void notice_finished_file PARAMS ((struct file *file));
-#ifdef ST_MTIM_NSEC
-# define FILE_TIMESTAMP_HI_RES \
- (2147483647 < INTEGER_TYPE_MAXIMUM (FILE_TIMESTAMP) >> 31)
+#if FILE_TIMESTAMP_HI_RES
# define FILE_TIMESTAMP_STAT_MODTIME(fname, st) \
file_timestamp_cons (fname, (st).st_mtime, (st).st_mtim.ST_MTIM_NSEC)
#else
-# define FILE_TIMESTAMP_HI_RES 0
# define FILE_TIMESTAMP_STAT_MODTIME(fname, st) \
file_timestamp_cons (fname, (st).st_mtime, 0)
#endif