Merge branch 'rw/make-needs-librt'

Makefile assumed that -lrt is always available on platforms that
want to use clock_gettime() and CLOCK_MONOTONIC, which is not a
case for recent Mac OS X.  The necessary symbols are often found in
libc on many modern systems and having -lrt on the command line, as
long as the library exists, had no effect, but when the platform
removes librt.a that is a different matter--having -lrt will break
the linkage.

This change could be seen as a regression for those who do need to
specify -lrt, as they now specifically ask for NEEDS_LIBRT when
building. Hopefully they are in the minority these days.

* rw/make-needs-librt:
  config.mak.uname: define NEEDS_LIBRT under Linux, for now
  Makefile: add NEEDS_LIBRT to optionally link with librt
This commit is contained in:
Junio C Hamano 2016-07-25 14:13:35 -07:00
commit 937be62993
2 changed files with 11 additions and 3 deletions

View File

@ -351,9 +351,12 @@ all::
# Define GMTIME_UNRELIABLE_ERRORS if your gmtime() function does not # Define GMTIME_UNRELIABLE_ERRORS if your gmtime() function does not
# return NULL when it receives a bogus time_t. # return NULL when it receives a bogus time_t.
# #
# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime in librt. # Define HAVE_CLOCK_GETTIME if your platform has clock_gettime.
# #
# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC in librt. # Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC.
#
# Define NEEDS_LIBRT if your platform requires linking with librt (glibc version
# before 2.17) for clock_gettime and CLOCK_MONOTONIC.
# #
# Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily # Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily
# compiles the following initialization: # compiles the following initialization:
@ -1467,13 +1470,16 @@ endif
ifdef HAVE_CLOCK_GETTIME ifdef HAVE_CLOCK_GETTIME
BASIC_CFLAGS += -DHAVE_CLOCK_GETTIME BASIC_CFLAGS += -DHAVE_CLOCK_GETTIME
EXTLIBS += -lrt
endif endif
ifdef HAVE_CLOCK_MONOTONIC ifdef HAVE_CLOCK_MONOTONIC
BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
endif endif
ifdef NEEDS_LIBRT
EXTLIBS += -lrt
endif
ifdef HAVE_BSD_SYSCTL ifdef HAVE_BSD_SYSCTL
BASIC_CFLAGS += -DHAVE_BSD_SYSCTL BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
endif endif

View File

@ -36,6 +36,8 @@ ifeq ($(uname_S),Linux)
HAVE_DEV_TTY = YesPlease HAVE_DEV_TTY = YesPlease
HAVE_CLOCK_GETTIME = YesPlease HAVE_CLOCK_GETTIME = YesPlease
HAVE_CLOCK_MONOTONIC = YesPlease HAVE_CLOCK_MONOTONIC = YesPlease
# -lrt is needed for clock_gettime on glibc <= 2.16
NEEDS_LIBRT = YesPlease
HAVE_GETDELIM = YesPlease HAVE_GETDELIM = YesPlease
SANE_TEXT_GREP=-a SANE_TEXT_GREP=-a
endif endif