[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: avoiding unnecessary dependency on -lrt and -lpthread
From: |
Paul Eggert |
Subject: |
Re: avoiding unnecessary dependency on -lrt and -lpthread |
Date: |
Mon, 21 Feb 2005 23:29:39 -0800 |
User-agent: |
Gnus/5.1006 (Gnus v5.10.6) Emacs/21.4 (gnu/linux) |
Jim Meyering <address@hidden> writes:
> gethrxtime uses clock_gettime on Linux systems (and any other system
> without nanouptime), so such systems will get link errors for
> clock_gettime if it's in a separate library like -lrt.
Sorry, I didn't test with new-enough GNU/Linux systems. I installed
this further patch to work around the problem. This is "make check"
tested with Debian GNU/Linux 3.0 and 3.1-beta (x86), Solaris 8 64-bit
sparc (Forte 6 cc), Solaris 9 32-bit sparc (Forte 7 c89), and OpenBSD
3.4 x86.
2005-02-21 Paul Eggert <address@hidden>
* m4/xnanosleep.m4: New file.
* lib/Makefile.am (libfetish_a_SOURCES): Remove xnanosleep.c,
xnanosleep.h; now done by ../m4/xnanosleep.m4 automatically.
* m4/gethrxtime.m4 (gl_PREREQ_GETHRXTIME): Require gl_CLOCK_TIME,
gl_USE_SYSTEM_EXTENSIONS. Check whether CLOCK_MONOTONIC is
defined, and set LIB_GETHRXTIME accordingly. This is needed
for newer GNU/Linux systems that have clock_gettime, so that they
link in the appropriate library for it when needed.
* m4/prereq.m4 (gl_PREREQ): Require gl_XNANOSLEEP.
* src/Makefile.am (dd_LDADD, shred_LDADD): Add $(LIB_GETHRXTIME).
(nanosec_libs): Add $(LIB_XNANOSLEEP). Needed for newer GNU/Linux
hosts with clock_gettime.
--- /dev/null 2003-03-18 13:55:57 -0800
+++ m4/xnanosleep.m4 2005-02-21 22:52:42 -0800
@@ -0,0 +1,35 @@
+# xnanosleep.m4 serial 1
+dnl Copyright (C) 2005 Free Software Foundation, Inc.
+dnl This file is free software; the Free Software Foundation
+dnl gives unlimited permission to copy and/or distribute it,
+dnl with or without modifications, as long as this notice is preserved.
+
+dnl Written by Paul Eggert.
+
+AC_DEFUN([gl_XNANOSLEEP],
+[
+ AC_LIBSOURCES([xnanosleep.c, xnanosleep.h])
+ AC_LIBOBJ([xnanosleep])
+
+ dnl Prerequisites of lib/xnanosleep.c.
+ AC_REQUIRE([gl_PREREQ_GETHRXTIME])
+
+ LIB_XNANOSLEEP=
+ case $LIB_GETHRXTIME in
+ ?*)
+ AC_CACHE_CHECK([whether __linux__ is defined],
+ gl_cv_have___linux__,
+ [AC_EGREP_CPP([have___linux__],
+ [
+# ifdef __linux__
+ have___linux__
+# endif
+ ],
+ gl_cv_have___linux__=yes,
+ gl_cv_have___linux__=no)])
+ if test $gl_cv_have___linux__ = yes; then
+ LIB_XNANOSLEEP=$LIB_GETHRXTIME
+ fi;;
+ esac
+ AC_SUBST([LIB_XNANOSLEEP])
+])
Index: lib/Makefile.am
===================================================================
RCS file: /fetish/cu/lib/Makefile.am,v
retrieving revision 1.213
diff -p -u -r1.213 Makefile.am
--- lib/Makefile.am 20 Feb 2005 12:25:43 -0000 1.213
+++ lib/Makefile.am 22 Feb 2005 06:58:35 -0000
@@ -56,7 +56,6 @@ libfetish_a_SOURCES = \
xgetcwd.c xgetcwd.h \
xgethostname.c xgethostname.h \
xmemcoll.c xmemcoll.h \
- xnanosleep.c xnanosleep.h \
xreadlink.c xreadlink.h \
xstrndup.c xstrndup.h \
xstrtod.c xstrtod.h \
Index: m4/gethrxtime.m4
===================================================================
RCS file: /fetish/cu/m4/gethrxtime.m4,v
retrieving revision 1.1
diff -p -u -r1.1 gethrxtime.m4
--- m4/gethrxtime.m4 21 Feb 2005 08:06:25 -0000 1.1
+++ m4/gethrxtime.m4 22 Feb 2005 06:58:35 -0000
@@ -1,9 +1,11 @@
-# gethrxtime.m4 serial 1
+# gethrxtime.m4 serial 2
dnl Copyright (C) 2005 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
dnl with or without modifications, as long as this notice is preserved.
+dnl Written by Paul Eggert.
+
AC_DEFUN([gl_GETHRXTIME],
[
AC_LIBSOURCES([gethrxtime.c, gethrxtime.h, xtime.h])
@@ -48,10 +50,27 @@ AC_DEFUN([gl_XTIME],
# Prerequisites of lib/gethrxtime.c.
AC_DEFUN([gl_PREREQ_GETHRXTIME],
[
- dnl Do not AC_REQUIRE([gl_CLOCK_TIME]), since that would unnecessarily
- dnl require -lrt on Solaris. Invocations of clock_gettime should be
- dnl safe in gethrxtime.c since Solaris has native gethrtime.
AC_REQUIRE([AC_HEADER_TIME])
+ AC_REQUIRE([gl_CLOCK_TIME])
+ AC_REQUIRE([gl_USE_SYSTEM_EXTENSIONS])
AC_CHECK_FUNCS_ONCE(gettimeofday microuptime nanouptime)
- :
+
+ if test $ac_cv_func_nanouptime != yes; then
+ LIB_GETHRXTIME=
+ AC_CACHE_CHECK([whether CLOCK_MONOTONIC is defined],
+ gl_cv_have_CLOCK_MONOTONIC,
+ [AC_EGREP_CPP([have_CLOCK_MONOTONIC],
+ [
+# include <time.h>
+# ifdef CLOCK_MONOTONIC
+ have_CLOCK_MONOTONIC
+# endif
+ ],
+ gl_cv_have_CLOCK_MONOTONIC=yes,
+ gl_cv_have_CLOCK_MONOTONIC=no)])
+ if test $gl_cv_have_CLOCK_MONOTONIC = yes; then
+ LIB_GETHRXTIME=$LIB_CLOCK_GETTIME
+ fi
+ AC_SUBST([LIB_GETHRXTIME])
+ fi
])
Index: m4/prereq.m4
===================================================================
RCS file: /fetish/cu/m4/prereq.m4,v
retrieving revision 1.101
diff -p -u -r1.101 prereq.m4
--- m4/prereq.m4 21 Feb 2005 08:12:37 -0000 1.101
+++ m4/prereq.m4 22 Feb 2005 06:58:35 -0000
@@ -119,6 +119,7 @@ AC_DEFUN([gl_PREREQ],
AC_REQUIRE([gl_UTIMENS])
AC_REQUIRE([gl_XALLOC])
AC_REQUIRE([gl_XGETCWD])
+ AC_REQUIRE([gl_XNANOSLEEP])
AC_REQUIRE([gl_XREADLINK])
AC_REQUIRE([gl_XSTRTOD])
AC_REQUIRE([gl_XSTRTOL])
Index: src/Makefile.am
===================================================================
RCS file: /fetish/cu/src/Makefile.am,v
retrieving revision 1.50
diff -p -u -r1.50 Makefile.am
--- src/Makefile.am 21 Feb 2005 08:13:12 -0000 1.50
+++ src/Makefile.am 22 Feb 2005 06:58:36 -0000
@@ -43,10 +43,10 @@ test_LDADD = $(LDADD) $(LIB_EACCESS)
__LDADD = $(LDADD) $(LIB_EACCESS)
# for clock_gettime and fdatasync
-dd_LDADD = $(LDADD) $(LIB_FDATASYNC)
+dd_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
dir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
ls_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
-shred_LDADD = $(LDADD) $(LIB_FDATASYNC)
+shred_LDADD = $(LDADD) $(LIB_GETHRXTIME) $(LIB_FDATASYNC)
vdir_LDADD = $(LDADD) $(LIB_CLOCK_GETTIME)
## If necessary, add -lm to resolve use of pow in lib/strtod.c.
@@ -69,7 +69,7 @@ seq_LDADD = $(LDADD) $(SEQ_LIBM)
# If necessary, add -lm to resolve the `pow' reference in lib/strtod.c
# or for the fesetround reference in programs using nanosec.c.
nanosec_libs = \
- $(LDADD) $(FESETROUND_LIBM) $(POW_LIB) $(LIB_NANOSLEEP)
+ $(LDADD) $(FESETROUND_LIBM) $(POW_LIB) $(LIB_XNANOSLEEP) $(LIB_NANOSLEEP)
sleep_LDADD = $(nanosec_libs)
tail_LDADD = $(nanosec_libs)