From 4c893341f5513055a148bedbf7e2fbff392325b2 Mon Sep 17 00:00:00 2001 From: Andrii Nakryiko Date: Mon, 3 Mar 2025 16:58:22 -0800 Subject: [PATCH] Makefile: detect pkg-config availability Detect whether build system has pkg-config tool, and if not, fallback to manually specifying -lelf -lz as dependency. Closes: https://github.com/libbpf/libbpf/issues/885 Signed-off-by: Andrii Nakryiko --- src/Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/Makefile b/src/Makefile index d1fb4bb..61052d3 100644 --- a/src/Makefile +++ b/src/Makefile @@ -26,6 +26,7 @@ endef $(call allow-override,CC,$(CROSS_COMPILE)cc) $(call allow-override,LD,$(CROSS_COMPILE)ld) +PKG_CONFIG ?= pkg-config TOPDIR = .. @@ -41,10 +42,12 @@ ALL_CFLAGS += $(CFLAGS) \ $(EXTRA_CFLAGS) ALL_LDFLAGS += $(LDFLAGS) $(EXTRA_LDFLAGS) +ifeq ($(shell command -v $(PKG_CONFIG) 2> /dev/null),) +NO_PKG_CONFIG := 1 +endif ifdef NO_PKG_CONFIG ALL_LDFLAGS += -lelf -lz else - PKG_CONFIG ?= pkg-config ALL_CFLAGS += $(shell $(PKG_CONFIG) --cflags libelf zlib) ALL_LDFLAGS += $(shell $(PKG_CONFIG) --libs libelf zlib) endif