mirror of
https://github.com/netdata/libbpf.git
synced 2026-03-21 00:39:07 +08:00
makefile: sync 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. This has been applied on bpf-next, so the corresponding change is backported here: https://git.kernel.org/pub/scm/linux/kernel/git/bpf/bpf-next.git/commit/?id=dd399ac9e343c7573c47d6820e4a23013c54749d Signed-off-by: Luca Boccassi <luca.boccassi@microsoft.com>
This commit is contained in:
committed by
Andrii Nakryiko
parent
27a5f60a8b
commit
93bc1d03f4
17
src/Makefile
17
src/Makefile
@@ -31,6 +31,8 @@ HEADERS := bpf.h libbpf.h btf.h
|
||||
UAPI_HEADERS := $(addprefix $(TOPDIR)/include/uapi/linux/,bpf.h bpf_common.h \
|
||||
btf.h)
|
||||
|
||||
PC_FILE := libbpf.pc
|
||||
|
||||
INSTALL = install
|
||||
|
||||
DESTDIR ?=
|
||||
@@ -46,7 +48,7 @@ LIBDIR ?= $(PREFIX)/$(LIBSUBDIR)
|
||||
INCLUDEDIR ?= $(PREFIX)/include
|
||||
UAPIDIR ?= $(PREFIX)/include
|
||||
|
||||
all: $(LIBS)
|
||||
all: $(LIBS) $(PC_FILE)
|
||||
|
||||
$(OBJDIR)/libbpf.a: $(OBJS)
|
||||
$(AR) rcs $@ $^
|
||||
@@ -54,6 +56,12 @@ $(OBJDIR)/libbpf.a: $(OBJS)
|
||||
$(OBJDIR)/libbpf.so: $(OBJS)
|
||||
$(CC) -shared $(LDFLAGS) $^ -o $@
|
||||
|
||||
$(OBJDIR)/libbpf.pc:
|
||||
sed -e "s|@PREFIX@|$(PREFIX)|" \
|
||||
-e "s|@LIBDIR@|$(LIBDIR)|" \
|
||||
-e "s|@VERSION@|$(LIBBPF_VERSION)|" \
|
||||
< libbpf.pc.template > $@
|
||||
|
||||
$(OBJDIR)/%.o: %.c
|
||||
$(CC) $(ALL_CFLAGS) -c $< -o $@
|
||||
|
||||
@@ -64,7 +72,7 @@ define do_install
|
||||
$(INSTALL) $1 $(if $3,-m $3,) '$(DESTDIR)$2'
|
||||
endef
|
||||
|
||||
install: all install_headers
|
||||
install: all install_headers install_pkgconfig
|
||||
$(call do_install,$(LIBS),$(LIBDIR))
|
||||
|
||||
install_headers:
|
||||
@@ -75,5 +83,8 @@ install_headers:
|
||||
install_uapi_headers:
|
||||
$(call do_install,$(UAPI_HEADERS),$(UAPIDIR)/linux,644)
|
||||
|
||||
install_pkgconfig: $(PC_FILE)
|
||||
$(call do_install,$(PC_FILE),$(LIBDIR)/pkgconfig,644)
|
||||
|
||||
clean:
|
||||
rm -f *.o *.a *.so
|
||||
rm -f *.o *.a *.so *.pc
|
||||
|
||||
Reference in New Issue
Block a user