Nico Huber submitted this change.

View Change

Approvals: build bot (Jenkins): Verified Angel Pons: Looks good to me, approved
Makefile: check if librt is an external library

Some systems, e.g. OpenBSD, have clock_gettime / librt build into the
libc and therefore fail to link against it with -lrt. Thus, detect this
and link only if needed.

Change-Id: I2c1668a350aa0806fccfb4e9cd8b04861f085ee9
Signed-off-by: Thomas Heijligen <thomas.heijligen@secunet.com>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/61523
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Angel Pons <th3fanbus@gmail.com>
---
M Makefile
M Makefile.include
2 files changed, 8 insertions(+), 0 deletions(-)

diff --git a/Makefile b/Makefile
index 086cd45..f928019 100644
--- a/Makefile
+++ b/Makefile
@@ -239,6 +239,7 @@
HAS_FT232H := $(call c_compile_test, Makefile.d/ft232h_test.c, $(CONFIG_LIBFTDI1_CFLAGS))
HAS_UTSNAME := $(call c_compile_test, Makefile.d/utsname_test.c)
HAS_CLOCK_GETTIME := $(call c_compile_test, Makefile.d/clock_gettime_test.c)
+HAS_EXTERN_LIBRT := $(call c_link_test, Makefile.d/clock_gettime_test.c, , -lrt)
HAS_LINUX_MTD := $(call c_compile_test, Makefile.d/linux_mtd_test.c)
HAS_LINUX_SPI := $(call c_compile_test, Makefile.d/linux_spi_test.c)
HAS_LINUX_I2C := $(call c_compile_test, Makefile.d/linux_i2c_test.c)
@@ -901,8 +902,10 @@

ifeq ($(HAS_CLOCK_GETTIME), yes)
FEATURE_FLAGS += -D'HAVE_CLOCK_GETTIME=1'
+ifeq ($(HAS_EXTERN_LIBRT), yes)
override LDFLAGS += -lrt
endif
+endif

LIBFLASHROM_OBJS = $(CHIP_OBJS) $(PROGRAMMER_OBJS) $(LIB_OBJS)
OBJS = $(CLI_OBJS) $(LIBFLASHROM_OBJS)
@@ -959,6 +962,7 @@
@echo "Checking for header \"linux/i2c.h\": $(HAS_LINUX_I2C)"
@echo "Checking for header \"sys/utsname.h\": $(HAS_UTSNAME)"
@echo "Checking for function \"clock_gettime\": $(HAS_CLOCK_GETTIME)"
+ @echo "Checking for external \"librt\": $(HAS_EXTERN_LIBRT)"
@if ! [ "$(PROGRAMMER_OBJS)" ]; then \
echo "You have to enable at least one programmer driver!"; \
exit 1; \
diff --git a/Makefile.include b/Makefile.include
index a3abcad..2316b30 100644
--- a/Makefile.include
+++ b/Makefile.include
@@ -40,6 +40,10 @@
$(call debug_shell, $(CC) -c -Wall -Werror $2 $1 -o /dev/null && echo yes || echo no)
endef

+define c_link_test # $1: file to compile and link, $2: cflags, $3: ldflags
+$(call debug_shell, $(CC) -Wall -Werror $2 $1 $3 -o /dev/null && echo yes || echo no)
+endef
+
define find_dependency
$(call debug_shell, $(if $(PKG_CONFIG_LIBDIR),PKG_CONFIG_LIBDIR=$(PKG_CONFIG_LIBDIR),) $(PKG_CONFIG) --exists $1 && echo yes || echo no)
endef

3 is the latest approved patch-set. No files were changed between the latest approved patch-set and the submitted one.

To view, visit change 61523. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I2c1668a350aa0806fccfb4e9cd8b04861f085ee9
Gerrit-Change-Number: 61523
Gerrit-PatchSet: 6
Gerrit-Owner: Thomas Heijligen <src@posteo.de>
Gerrit-Reviewer: Angel Pons <th3fanbus@gmail.com>
Gerrit-Reviewer: Felix Singer <felixsinger@posteo.net>
Gerrit-Reviewer: Nico Huber <nico.h@gmx.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-MessageType: merged