Message ID | 20190321223317.29584-1-luca.boccassi@gmail.com |
---|---|
State | Changes Requested |
Delegated to: | BPF Maintainers |
Headers | show |
Series | [bpf-next,v6] tools/bpf: generate pkg-config file for libbpf | expand |
On Thu, Mar 21, 2019 at 10:33:17PM +0000, luca.boccassi@gmail.com wrote: > From: Luca Boccassi <bluca@debian.org> > > 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> > --- > v2: use QUIET_GEN instead of QUIET_LINK to generate pc file, > save kernel version in its own variable instead of calling > make inline > v3: use LIBBPF_VERSION instead of kernel_version > v4: use -I${prefix}/include rather than -I${prefix}/include/bpf > in the Cflags field as requested, to keep consistency with > how the headers are used now and to avoid a dependency from > the pc file to the headers installation > v5: add acked-by, add SPDX line to pc file > v6: remove URL field, generalize Description field It fails to build: make -C ../../../lib/bpf OUTPUT=/data/users/ast/bpf-next/tools/testing/selftests/bpf/ make[1]: Entering directory `/data/users/ast/bpf-next/tools/lib/bpf' make[2]: *** No rule to make target `libbpf.pc', needed by `all_cmd'. Stop. make[1]: *** [all] Error 2 make[1]: Leaving directory `/data/users/ast/bpf-next/tools/lib/bpf'
On Thu, 2019-03-21 at 15:43 -0700, Alexei Starovoitov wrote: > On Thu, Mar 21, 2019 at 10:33:17PM +0000, luca.boccassi@gmail.com > wrote: > > From: Luca Boccassi <bluca@debian.org> > > > > 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> > > --- > > v2: use QUIET_GEN instead of QUIET_LINK to generate pc file, > > save kernel version in its own variable instead of calling > > make inline > > v3: use LIBBPF_VERSION instead of kernel_version > > v4: use -I${prefix}/include rather than -I${prefix}/include/bpf > > in the Cflags field as requested, to keep consistency with > > how the headers are used now and to avoid a dependency from > > the pc file to the headers installation > > v5: add acked-by, add SPDX line to pc file > > v6: remove URL field, generalize Description field > > It fails to build: > make -C ../../../lib/bpf OUTPUT=/data/users/ast/bpf- > next/tools/testing/selftests/bpf/ > make[1]: Entering directory `/data/users/ast/bpf-next/tools/lib/bpf' > make[2]: *** No rule to make target `libbpf.pc', needed by > `all_cmd'. Stop. > make[1]: *** [all] Error 2 > make[1]: Leaving directory `/data/users/ast/bpf-next/tools/lib/bpf' Thanks, the $(OUTPUT) prefix was missing so the out of tree build didn't work, fixed in v7.
diff --git a/tools/lib/bpf/.gitignore b/tools/lib/bpf/.gitignore index 4db74758c674..7d9e182a1f51 100644 --- a/tools/lib/bpf/.gitignore +++ b/tools/lib/bpf/.gitignore @@ -1,3 +1,4 @@ libbpf_version.h +libbpf.pc FEATURE-DUMP.libbpf test_libbpf diff --git a/tools/lib/bpf/Makefile b/tools/lib/bpf/Makefile index 61aaacf0cfa1..891fe3da1410 100644 --- a/tools/lib/bpf/Makefile +++ b/tools/lib/bpf/Makefile @@ -80,6 +80,7 @@ libdir_SQ = $(subst ','\'',$(libdir)) libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) LIB_FILE = libbpf.a libbpf.so +PC_FILE = libbpf.pc VERSION = $(BPF_VERSION) PATCHLEVEL = $(BPF_PATCHLEVEL) @@ -137,7 +138,7 @@ GLOBAL_SYM_COUNT = $(shell readelf -s --wide $(BPF_IN) | \ VERSIONED_SYM_COUNT = $(shell readelf -s --wide $(OUTPUT)libbpf.so | \ grep -Eo '[^ ]+@LIBBPF_' | cut -d@ -f1 | sort -u | wc -l) -CMD_TARGETS = $(LIB_FILE) +CMD_TARGETS = $(LIB_FILE) $(PC_FILE) CXX_TEST_TARGET = $(OUTPUT)test_libbpf @@ -180,6 +181,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)|" \ + < $@.template > $@ + check: check_abi check_abi: $(OUTPUT)libbpf.so @@ -209,7 +216,12 @@ 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 @@ -219,7 +231,7 @@ config-clean: clean: $(call QUIET_CLEAN, libbpf) $(RM) $(TARGETS) $(CXX_TEST_TARGET) \ - *.o *~ *.a *.so .*.d .*.cmd LIBBPF-CFLAGS + *.o *~ *.a *.so .*.d .*.cmd *.pc LIBBPF-CFLAGS $(call QUIET_CLEAN, core-gen) $(RM) $(OUTPUT)FEATURE-DUMP.libbpf diff --git a/tools/lib/bpf/libbpf.pc.template b/tools/lib/bpf/libbpf.pc.template new file mode 100644 index 000000000000..ac17fcef2108 --- /dev/null +++ b/tools/lib/bpf/libbpf.pc.template @@ -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}