[PATCH] 1.4 Fix clock_gettime configure detection

Gilles Espinasse g.esp at free.fr
Sun Jan 22 08:21:41 CET 2012


AC_CHECK_FUNCS is not enought for clock_gettime as AC_SEARCH_LIBS has to be used

Changed configure clock_gettime test to only run in the case when cipher/random.c code will use that.
This avoid linking to librt/libpthread when no required.

Tested with a combination of
ac_cv_func_gettimeofday=no gnupg_cv_func_gethrtime=no gnupg_cv_func_broken_gethrtime=yes ./configure --enable-minimal

--enable-minimal is a test case as librt/libpthread already link with libusb

Signed-off-by: Gilles Espinasse <g.esp at free.fr>
---
 configure.ac      |   26 ++++++++++++++++++++++++--
 g10/Makefile.am   |    2 +-
 tools/Makefile.am |    2 +-
 3 files changed, 26 insertions(+), 4 deletions(-)

diff --git a/configure.ac b/configure.ac
index 181c07b..0cc2b46 100644
--- a/configure.ac
+++ b/configure.ac
@@ -1023,7 +1023,7 @@ AC_FUNC_VPRINTF
 AC_FUNC_FORK
 AC_CHECK_FUNCS(strerror stpcpy strlwr tcgetattr strtoul mmap sysconf)
 AC_CHECK_FUNCS(strcasecmp strncasecmp ctermid times unsetenv getpwnam getpwuid)
-AC_CHECK_FUNCS(memmove gettimeofday getrusage setrlimit clock_gettime)
+AC_CHECK_FUNCS(memmove gettimeofday getrusage setrlimit)
 AC_CHECK_FUNCS(atexit raise getpagesize strftime nl_langinfo setlocale)
 AC_CHECK_FUNCS(waitpid wait4 sigaction sigprocmask rand pipe stat getaddrinfo)
 AC_CHECK_FUNCS(fcntl ftruncate)
@@ -1037,7 +1037,6 @@ AC_CHECK_TYPES([struct sigaction, sigset_t],,,[#include <signal.h>])
 
 AC_CHECK_FUNC(getopt,,AC_CHECK_LIB(iberty,getopt,AC_SUBST(GETOPT,"-liberty")))
 
-#
 # check for gethrtime and run a testprogram to see whether
 # it is broken.  It has been reported that some Solaris and HP UX systems
 # raise an SIGILL
@@ -1073,6 +1072,29 @@ if test $gnupg_cv_func_gethrtime = yes; then
     fi
 fi
 
+dnl clock_gettime is only used when gethrtime and gettimeofday are not available
+dnl so avoid linking to external lib when not needed
+if test x"$ac_cv_func_gettimeofday" != xyes && test x"$gnupg_cv_func_gethrtime" != xyes && test x"$gnupg_cv_func_broken_gethrtime" != xno; then
+    dnl Check for clock_gettime, in libc for FreeBSD, in rt for linux,
+    dnl in rt for Solaris 7, in posix4 for Solaris 2.5.1
+    LIB_CLOCK_GETTIME=
+    clk_saved_libs=$LIBS
+    AC_SEARCH_LIBS([clock_gettime], [rt posix4],
+        [test "$ac_cv_search_clock_gettime" = "none required" ||
+        LIB_CLOCK_GETTIME=$ac_cv_search_clock_gettime])
+    AC_SUBST([LIB_CLOCK_GETTIME])
+
+    AC_MSG_CHECKING([for working clock_gettime])
+    AC_LINK_IFELSE([AC_LANG_PROGRAM([[#include <time.h>]],
+        [[clock_gettime(CLOCK_REALTIME, 0);]])], [gnupg_cv_clock_gettime=yes], [gnupg_cv_clock_gettime=no])
+    AC_MSG_RESULT($gnupg_cv_clock_gettime)
+
+    if test x"$gnupg_cv_clock_gettime" = xyes; then
+        AC_DEFINE([HAVE_CLOCK_GETTIME], 1,
+        [Define to 1 if you have the `clock_gettime' function.])
+    fi
+    LIBS=$clk_saved_libs
+fi
 
 GNUPG_CHECK_MLOCK
 GNUPG_FUNC_MKDIR_TAKES_ONE_ARG
diff --git a/g10/Makefile.am b/g10/Makefile.am
index 60e7e11..ebceb2e 100644
--- a/g10/Makefile.am
+++ b/g10/Makefile.am
@@ -127,7 +127,7 @@ gpgv_SOURCES = gpgv.c           \
 	      verify.c
 
 LDADD =  $(needed_libs) $(other_libs) @ZLIBS@ @W32LIBS@
-gpg_LDADD = $(LDADD) @LIBREADLINE@ @DLLIBS@ @NETLIBS@ @LIBUSB@
+gpg_LDADD = $(LDADD) @LIBREADLINE@ @DLLIBS@ @NETLIBS@ @LIBUSB@ @LIB_CLOCK_GETTIME@
 
 $(PROGRAMS): $(needed_libs)
 
diff --git a/tools/Makefile.am b/tools/Makefile.am
index 0c6e691..604354a 100644
--- a/tools/Makefile.am
+++ b/tools/Makefile.am
@@ -41,7 +41,7 @@ endif
 
 gpgsplit_LDADD  = $(needed_libs) $(other_libs) @ZLIBS@
 mpicalc_LDADD   = $(needed_libs) $(other_libs) @W32LIBS@
-bftest_LDADD    = $(needed_libs) $(other_libs) @W32LIBS@ @DLLIBS@ @NETLIBS@ @LIBREADLINE@
+bftest_LDADD    = $(needed_libs) $(other_libs) @W32LIBS@ @DLLIBS@ @NETLIBS@ @LIBREADLINE@ @LIB_CLOCK_GETTIME@
 shmtest_LDADD   = $(needed_libs) $(other_libs) @LIBREADLINE@
 
 gpgsplit mpicalc bftest shmtest: $(needed_libs)
-- 
1.5.6.5




More information about the Gnupg-devel mailing list