tools/bpf: generate pkg-config file for libbpf
Generate a libbpf.pc file at build time so that users can rely on pkg-config to find the library, its CFLAGS and LDFLAGS. Signed-off-by: Luca Boccassi <bluca@debian.org> Acked-by: Andrey Ignatov <rdna@fb.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
This commit is contained in:
parent
356d71e00d
commit
dd399ac9e3
|
@ -1,3 +1,4 @@
|
|||
libbpf_version.h
|
||||
libbpf.pc
|
||||
FEATURE-DUMP.libbpf
|
||||
test_libbpf
|
||||
|
|
|
@ -90,6 +90,7 @@ LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
|
|||
|
||||
LIB_TARGET = libbpf.a libbpf.so.$(LIBBPF_VERSION)
|
||||
LIB_FILE = libbpf.a libbpf.so*
|
||||
PC_FILE = libbpf.pc
|
||||
|
||||
# Set compile option CFLAGS
|
||||
ifdef EXTRA_CFLAGS
|
||||
|
@ -134,13 +135,14 @@ VERSION_SCRIPT := libbpf.map
|
|||
|
||||
LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
|
||||
LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE))
|
||||
PC_FILE := $(addprefix $(OUTPUT),$(PC_FILE))
|
||||
|
||||
GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN) | \
|
||||
awk '/GLOBAL/ && /DEFAULT/ && !/UND/ {s++} END{print s}')
|
||||
VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \
|
||||
grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l)
|
||||
|
||||
CMD_TARGETS = $(LIB_TARGET)
|
||||
CMD_TARGETS = $(LIB_TARGET) $(PC_FILE)
|
||||
|
||||
CXX_TEST_TARGET = $(OUTPUT)test_libbpf
|
||||
|
||||
|
@ -187,6 +189,12 @@ $(OUTPUT)libbpf.a: $(BPF_IN)
|
|||
$(OUTPUT)test_libbpf: test_libbpf.cpp $(OUTPUT)libbpf.a
|
||||
$(QUIET_LINK)$(CXX) $(INCLUDES) $^ -lelf -o $@
|
||||
|
||||
$(OUTPUT)libbpf.pc:
|
||||
$(QUIET_GEN)sed -e "s|@PREFIX@|$(prefix)|" \
|
||||
-e "s|@LIBDIR@|$(libdir_SQ)|" \
|
||||
-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
|
||||
< libbpf.pc.template > $@
|
||||
|
||||
check: check_abi
|
||||
|
||||
check_abi: $(OUTPUT)libbpf.so
|
||||
|
@ -223,7 +231,11 @@ install_headers:
|
|||
$(call do_install,libbpf.h,$(prefix)/include/bpf,644);
|
||||
$(call do_install,btf.h,$(prefix)/include/bpf,644);
|
||||
|
||||
install: install_lib
|
||||
install_pkgconfig: $(PC_FILE)
|
||||
$(call QUIET_INSTALL, $(PC_FILE)) \
|
||||
$(call do_install,$(PC_FILE),$(libdir_SQ)/pkgconfig,644)
|
||||
|
||||
install: install_lib install_pkgconfig
|
||||
|
||||
### Cleaning rules
|
||||
|
||||
|
@ -233,7 +245,7 @@ config-clean:
|
|||
|
||||
clean:
|
||||
$(call QUIET_CLEAN, libbpf) $(RM) $(TARGETS) $(CXX_TEST_TARGET) \
|
||||
*.o *~ *.a *.so *.so.$(VERSION) .*.d .*.cmd LIBBPF-CFLAGS
|
||||
*.o *~ *.a *.so *.so.$(VERSION) .*.d .*.cmd *.pc LIBBPF-CFLAGS
|
||||
$(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP.libbpf
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
# SPDX-License-Identifier: (LGPL-2.1 OR BSD-2-Clause)
|
||||
|
||||
prefix=@PREFIX@
|
||||
libdir=@LIBDIR@
|
||||
includedir=${prefix}/include
|
||||
|
||||
Name: libbpf
|
||||
Description: BPF library
|
||||
Version: @VERSION@
|
||||
Libs: -L${libdir} -lbpf
|
||||
Requires.private: libelf
|
||||
Cflags: -I${includedir}
|
Loading…
Reference in New Issue