Skip to content

Commit d19e3a5

Browse files
rdwamplergitster
authored andcommitted
Makefile: add NEEDS_LIBRT to optionally link with librt
We unconditionally link with librt, when HAVE_CLOCK_GETTIME is defined. But clock_gettime() has been available in most libc implementations for some time now (e.g., for glibc since version 2.17) and no longer requires linking with librt. Furthermore, commit a6c3c63 (configure.ac: check for clock_gettime() and CLOCK_MONOTONIC) will automatically determined which library (libc or librt) is required for linking when checking for clock_gettime(). The assumption to unconditionally link with librt was OK, since either almost every Unix-like system provides a version of librt for backwards compatibility or other systems, namely Windows or OS X, never provided clock_gettime(). However, in the latest release of OS X (macOS Sierra), this function has been added to OS X libc version. As a result, when running the configuration script, HAVE_CLOCK_GETTIME is set and since librt is not present, it causes a linker error. This patches requires those not building via the configuration scripts to define NEEDS_LIBRT in addition to HAVE_CLOCK_GETTIME, if needed. Signed-off-by: Ronald Wampler <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 0b65a8d commit d19e3a5

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

Makefile

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,9 +351,12 @@ all::
351351
# Define GMTIME_UNRELIABLE_ERRORS if your gmtime() function does not
352352
# return NULL when it receives a bogus time_t.
353353
#
354-
# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime in librt.
354+
# Define HAVE_CLOCK_GETTIME if your platform has clock_gettime.
355355
#
356-
# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC in librt.
356+
# Define HAVE_CLOCK_MONOTONIC if your platform has CLOCK_MONOTONIC.
357+
#
358+
# Define NEEDS_LIBRT if your platform requires linking with librt (glibc version
359+
# before 2.17) for clock_gettime and CLOCK_MONOTONIC.
357360
#
358361
# Define USE_PARENS_AROUND_GETTEXT_N to "yes" if your compiler happily
359362
# compiles the following initialization:
@@ -1465,13 +1468,16 @@ endif
14651468

14661469
ifdef HAVE_CLOCK_GETTIME
14671470
BASIC_CFLAGS += -DHAVE_CLOCK_GETTIME
1468-
EXTLIBS += -lrt
14691471
endif
14701472

14711473
ifdef HAVE_CLOCK_MONOTONIC
14721474
BASIC_CFLAGS += -DHAVE_CLOCK_MONOTONIC
14731475
endif
14741476

1477+
ifdef NEEDS_LIBRT
1478+
EXTLIBS += -lrt
1479+
endif
1480+
14751481
ifdef HAVE_BSD_SYSCTL
14761482
BASIC_CFLAGS += -DHAVE_BSD_SYSCTL
14771483
endif

0 commit comments

Comments
 (0)