From 08d3e929e584b174bcbf0e2426913d0761303e7f Mon Sep 17 00:00:00 2001 From: Yossi Gottlieb Date: Sun, 22 Nov 2020 14:40:38 +0200 Subject: [PATCH] Clean up building with USE_SYSTEMD. (#8073) When USE_SYSTEMD=yes is specified, try to use pkg-config to determine libsystemd linker flags. If not found, silently fall back to simply using "-lsystemd". We now use a LIBSYSTEMD_LIBS variable so users can explicitly override it and specify their own library. If USE_SYSTEMD is unspecified the old behavior of auto-enabling it if both pkg-config and libsystemd are available is retained. --- src/Makefile | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/Makefile b/src/Makefile index a32e4c150..653a6e6b0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -180,6 +180,8 @@ FINAL_CFLAGS+= -I../deps/hiredis -I../deps/linenoise -I../deps/lua/src -I../deps # Determine systemd support and/or build preference (defaulting to auto-detection) BUILD_WITH_SYSTEMD=no +LIBSYSTEMD_LIBS=-lsystemd + # If 'USE_SYSTEMD' in the environment is neither "no" nor "yes", try to # auto-detect libsystemd's presence and link accordingly. ifneq ($(USE_SYSTEMD),no) @@ -188,17 +190,18 @@ ifneq ($(USE_SYSTEMD),no) # (unless a later check tells us otherwise) ifeq ($(LIBSYSTEMD_PKGCONFIG),0) BUILD_WITH_SYSTEMD=yes + LIBSYSTEMD_LIBS=$(shell $(PKG_CONFIG) --libs libsystemd) endif endif + +# If 'USE_SYSTEMD' is set to "yes" use pkg-config if available or fall back to +# default -lsystemd. ifeq ($(USE_SYSTEMD),yes) -ifneq ($(LIBSYSTEMD_PKGCONFIG),0) -$(error USE_SYSTEMD is set to "$(USE_SYSTEMD)", but $(PKG_CONFIG) cannot find libsystemd) -endif -# Force building with libsystemd BUILD_WITH_SYSTEMD=yes endif + ifeq ($(BUILD_WITH_SYSTEMD),yes) - FINAL_LIBS+=$(shell $(PKG_CONFIG) --libs libsystemd) + FINAL_LIBS+=$(LIBSYSTEMD_LIBS) FINAL_CFLAGS+= -DHAVE_LIBSYSTEMD endif