]> granicus.if.org Git - strace/commitdiff
build: do not hardcode -lrt
authorDmitry V. Levin <ldv@altlinux.org>
Wed, 14 Mar 2018 21:15:55 +0000 (21:15 +0000)
committerDmitry V. Levin <ldv@altlinux.org>
Wed, 14 Mar 2018 21:15:55 +0000 (21:15 +0000)
Depending on libc implementation, various -lrt functions can be
implemented either in -lc or in -lrt.  For example, starting with
glibc-2.17 the clock_* suite of functions is available directly in -lc.

Check whether clock_* and mq_* suites of functions are provided
by -lrt or by the main C library, do not link with -lrt unnecessarily.

This change affects only tests yet, but this is going to be
more important as soon as strace starts using clock_gettime.

* configure.ac (AC_SEARCH_LIBS): Check for clock_gettime and mq_open
in -lrt.
(AC_SUBST): Add clock_LIBS and mq_LIBS.
* tests/Makefile.am (mq_LDADD): Replace -lrt with $(mq_LIBS).
(threads_execve_LDADD, times_LDADD): Replace -lrt with $(clock_LIBS).

configure.ac
tests/Makefile.am

index b4c1990f7a48ebeb1bd01e96b945cd25df903bbb..0895cde771a4bb5070279be3f7b58926224b8112 100644 (file)
@@ -809,6 +809,25 @@ if test "x$ac_cv_lib_dl_dladdr" = xyes; then
 fi
 AC_SUBST(dl_LIBS)
 
+saved_LIBS="$LIBS"
+AC_SEARCH_LIBS([clock_gettime], [rt])
+LIBS="$saved_LIBS"
+case "$ac_cv_search_clock_gettime" in
+       no) AC_MSG_FAILURE([failed to find clock_gettime]) ;;
+       -l*) clock_LIBS="$ac_cv_search_clock_gettime" ;;
+       *) clock_LIBS= ;;
+esac
+AC_SUBST(clock_LIBS)
+
+saved_LIBS="$LIBS"
+AC_SEARCH_LIBS([mq_open], [rt])
+LIBS="$saved_LIBS"
+case "$ac_cv_search_mq_open" in
+       -l*) mq_LIBS="$ac_cv_search_mq_open" ;;
+       *) mq_LIBS= ;;
+esac
+AC_SUBST(mq_LIBS)
+
 AC_PATH_PROG([PERL], [perl])
 
 AC_CHECK_TOOL([READELF], [readelf])
index ec307012bc5135651a2d354ac531f2092f4f0916..813bdb37a13e254609a15fb99e7bcb9680dc184a 100644 (file)
@@ -172,7 +172,7 @@ fstatat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 ftruncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 lstat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 mmap64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
-mq_LDADD = -lrt $(LDADD)
+mq_LDADD = $(mq_LIBS) $(LDADD)
 newfstatat_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 pc_LDADD = $(dl_LIBS) $(LDADD)
 pread64_pwrite64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
@@ -181,8 +181,8 @@ preadv_pwritev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 pwritev_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 stat64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 statfs_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
-threads_execve_LDADD = -lrt -lpthread $(LDADD)
-times_LDADD = -lrt $(LDADD)
+threads_execve_LDADD = -lpthread $(clock_LIBS) $(LDADD)
+times_LDADD = $(clock_LIBS) $(LDADD)
 truncate64_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64
 uio_CPPFLAGS = $(AM_CPPFLAGS) -D_FILE_OFFSET_BITS=64