diff mbox series

[bpf-next,v2] tools/bpf: generate pkg-config file for libbpf

Message ID 20190319230042.32087-1-bluca@debian.org
State Changes Requested
Delegated to: BPF Maintainers
Headers show
Series [bpf-next,v2] tools/bpf: generate pkg-config file for libbpf | expand

Commit Message

Luca Boccassi March 19, 2019, 11 p.m. UTC
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>
---
v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
    save kernel version in its own variable instead of calling
    make inline

 tools/lib/bpf/.gitignore         |  1 +
 tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
 tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
 3 files changed, 28 insertions(+), 3 deletions(-)
 create mode 100644 tools/lib/bpf/libbpf.pc.template

Comments

Stanislav Fomichev March 19, 2019, 11:17 p.m. UTC | #1
On 03/19, Luca Boccassi wrote:
> 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>
> ---
> v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
>     save kernel version in its own variable instead of calling
>     make inline
> 
>  tools/lib/bpf/.gitignore         |  1 +
>  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
>  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
>  3 files changed, 28 insertions(+), 3 deletions(-)
>  create mode 100644 tools/lib/bpf/libbpf.pc.template
> 
> 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 a05c43468bd0..1df3ebfb3118 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)
> @@ -89,6 +90,7 @@ OBJ		= $@
>  N		=
>  
>  LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
> +KERNEL_VERSION = $(shell make --no-print-directory -sC ../../.. kernelversion)
Oh, we do already have LIBBPF_VERSION, why not use that? This way
you don't need to do anything for out-of-tree libbpf from github.

I don't remember what was the strategy regarding libbpf versioning, but
that 0.0.1 should be changed to something sensible (be set to the kernel
version upon release?)

>  
>  # Set compile option CFLAGS
>  ifdef EXTRA_CFLAGS
> @@ -137,7 +139,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
>  
> @@ -179,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@|$(KERNEL_VERSION)|" \
> +		< $@.template > $@
> +
>  check: check_abi
>  
>  check_abi: $(OUTPUT)libbpf.so
> @@ -208,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
>  
> @@ -218,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..0cac2f5f54a6
> --- /dev/null
> +++ b/tools/lib/bpf/libbpf.pc.template
> @@ -0,0 +1,11 @@
> +prefix=@PREFIX@
> +libdir=@LIBDIR@
> +includedir=${prefix}/include/bpf
> +
> +Name: libbpf
> +URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
> +Description: Linux kernel BPF library
> +Version: @VERSION@
> +Libs: -L${libdir} -lbpf
> +Requires.private: libelf
> +Cflags: -I${includedir}
> -- 
> 2.20.1
>
Luca Boccassi March 20, 2019, 1:22 p.m. UTC | #2
On Tue, 2019-03-19 at 16:17 -0700, Stanislav Fomichev wrote:
> On 03/19, Luca Boccassi wrote:
> > 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>
> > ---
> > v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
> >     save kernel version in its own variable instead of calling
> >     make inline
> > 
> >  tools/lib/bpf/.gitignore         |  1 +
> >  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
> >  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
> >  3 files changed, 28 insertions(+), 3 deletions(-)
> >  create mode 100644 tools/lib/bpf/libbpf.pc.template
> > 
> > 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 a05c43468bd0..1df3ebfb3118 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)
> > @@ -89,6 +90,7 @@ OBJ		= $@
> >  N		=
> >  
> >  LIBBPF_VERSION =
> > $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
> > +KERNEL_VERSION = $(shell make --no-print-directory -sC ../../..
> > kernelversion)
> Oh, we do already have LIBBPF_VERSION, why not use that? This way
> you don't need to do anything for out-of-tree libbpf from github.
> 
> I don't remember what was the strategy regarding libbpf versioning,
> but
> that 0.0.1 should be changed to something sensible (be set to the
> kernel
> version upon release?)

[re-sending as reply via phone added html and the list daemon said no-
no]

That looks like the ABI version though, rather than the source version?
The source version is more appropriate for the PC file
Luca Boccassi March 20, 2019, 1:30 p.m. UTC | #3
On Wed, 2019-03-20 at 13:22 +0000, Luca Boccassi wrote:
> On Tue, 2019-03-19 at 16:17 -0700, Stanislav Fomichev wrote:
> > On 03/19, Luca Boccassi wrote:
> > > 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>
> > > ---
> > > v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
> > >     save kernel version in its own variable instead of calling
> > >     make inline
> > > 
> > >  tools/lib/bpf/.gitignore         |  1 +
> > >  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
> > >  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
> > >  3 files changed, 28 insertions(+), 3 deletions(-)
> > >  create mode 100644 tools/lib/bpf/libbpf.pc.template
> > > 
> > > 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 a05c43468bd0..1df3ebfb3118 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)
> > > @@ -89,6 +90,7 @@ OBJ		= $@
> > >  N		=
> > >  
> > >  LIBBPF_VERSION =
> > > $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
> > > +KERNEL_VERSION = $(shell make --no-print-directory -sC ../../..
> > > kernelversion)
> > Oh, we do already have LIBBPF_VERSION, why not use that? This way
> > you don't need to do anything for out-of-tree libbpf from github.
> > 
> > I don't remember what was the strategy regarding libbpf versioning,
> > but
> > that 0.0.1 should be changed to something sensible (be set to the
> > kernel
> > version upon release?)
> 
> [re-sending as reply via phone added html and the list daemon said
> no-
> no]
> 
> That looks like the ABI version though, rather than the source
> version?
> The source version is more appropriate for the PC file

That said, the versioning looks looks like it could use some love and
it's not really a factor that should gate a pkg-config file and could
be done separately if required, so in v3 I've removed KERNEL_VERSION
and used LIBBPF_VERSION as you suggested.

Thanks for reviewing!
Stanislav Fomichev March 20, 2019, 5:21 p.m. UTC | #4
On 03/20, Luca Boccassi wrote:
> On Wed, 2019-03-20 at 13:22 +0000, Luca Boccassi wrote:
> > On Tue, 2019-03-19 at 16:17 -0700, Stanislav Fomichev wrote:
> > > On 03/19, Luca Boccassi wrote:
> > > > 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>
> > > > ---
> > > > v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
> > > >     save kernel version in its own variable instead of calling
> > > >     make inline
> > > > 
> > > >  tools/lib/bpf/.gitignore         |  1 +
> > > >  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
> > > >  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
> > > >  3 files changed, 28 insertions(+), 3 deletions(-)
> > > >  create mode 100644 tools/lib/bpf/libbpf.pc.template
> > > > 
> > > > 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 a05c43468bd0..1df3ebfb3118 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)
> > > > @@ -89,6 +90,7 @@ OBJ		= $@
> > > >  N		=
> > > >  
> > > >  LIBBPF_VERSION =
> > > > $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
> > > > +KERNEL_VERSION = $(shell make --no-print-directory -sC ../../..
> > > > kernelversion)
> > > Oh, we do already have LIBBPF_VERSION, why not use that? This way
> > > you don't need to do anything for out-of-tree libbpf from github.
> > > 
> > > I don't remember what was the strategy regarding libbpf versioning,
> > > but
> > > that 0.0.1 should be changed to something sensible (be set to the
> > > kernel
> > > version upon release?)
> > 
> > [re-sending as reply via phone added html and the list daemon said
> > no-
> > no]
> > 
> > That looks like the ABI version though, rather than the source
> > version?
> > The source version is more appropriate for the PC file
> 
> That said, the versioning looks looks like it could use some love and
> it's not really a factor that should gate a pkg-config file and could
> be done separately if required, so in v3 I've removed KERNEL_VERSION
> and used LIBBPF_VERSION as you suggested.
Agree :-) There was some conversation recently about incrementing it per
kernel release vs real api change. I don't remember what the outcome
was exactly.

> Thanks for reviewing!
> 
> -- 
> Kind regards,
> Luca Boccassi
Luca Boccassi March 20, 2019, 8:39 p.m. UTC | #5
On Wed, 2019-03-20 at 10:21 -0700, Stanislav Fomichev wrote:
> On 03/20, Luca Boccassi wrote:
> > On Wed, 2019-03-20 at 13:22 +0000, Luca Boccassi wrote:
> > > On Tue, 2019-03-19 at 16:17 -0700, Stanislav Fomichev wrote:
> > > > On 03/19, Luca Boccassi wrote:
> > > > > 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>
> > > > > ---
> > > > > v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
> > > > >     save kernel version in its own variable instead of
> > > > > calling
> > > > >     make inline
> > > > > 
> > > > >  tools/lib/bpf/.gitignore         |  1 +
> > > > >  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
> > > > >  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
> > > > >  3 files changed, 28 insertions(+), 3 deletions(-)
> > > > >  create mode 100644 tools/lib/bpf/libbpf.pc.template
> > > > > 
> > > > > 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 a05c43468bd0..1df3ebfb3118 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)
> > > > > @@ -89,6 +90,7 @@ OBJ		= $@
> > > > >  N		=
> > > > >  
> > > > >  LIBBPF_VERSION =
> > > > > $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
> > > > > +KERNEL_VERSION = $(shell make --no-print-directory -sC
> > > > > ../../..
> > > > > kernelversion)
> > > > Oh, we do already have LIBBPF_VERSION, why not use that? This
> > > > way
> > > > you don't need to do anything for out-of-tree libbpf from
> > > > github.
> > > > 
> > > > I don't remember what was the strategy regarding libbpf
> > > > versioning,
> > > > but
> > > > that 0.0.1 should be changed to something sensible (be set to
> > > > the
> > > > kernel
> > > > version upon release?)
> > > 
> > > [re-sending as reply via phone added html and the list daemon
> > > said
> > > no-
> > > no]
> > > 
> > > That looks like the ABI version though, rather than the source
> > > version?
> > > The source version is more appropriate for the PC file
> > 
> > That said, the versioning looks looks like it could use some love
> > and
> > it's not really a factor that should gate a pkg-config file and
> > could
> > be done separately if required, so in v3 I've removed
> > KERNEL_VERSION
> > and used LIBBPF_VERSION as you suggested.
> Agree :-) There was some conversation recently about incrementing it
> per
> kernel release vs real api change. I don't remember what the outcome
> was exactly.

I see, thanks. Anything else you'd like me to change?
Stanislav Fomichev March 20, 2019, 8:44 p.m. UTC | #6
On 03/20, Luca Boccassi wrote:
> On Wed, 2019-03-20 at 10:21 -0700, Stanislav Fomichev wrote:
> > On 03/20, Luca Boccassi wrote:
> > > On Wed, 2019-03-20 at 13:22 +0000, Luca Boccassi wrote:
> > > > On Tue, 2019-03-19 at 16:17 -0700, Stanislav Fomichev wrote:
> > > > > On 03/19, Luca Boccassi wrote:
> > > > > > 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>
> > > > > > ---
> > > > > > v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
> > > > > >     save kernel version in its own variable instead of
> > > > > > calling
> > > > > >     make inline
> > > > > > 
> > > > > >  tools/lib/bpf/.gitignore         |  1 +
> > > > > >  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
> > > > > >  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
> > > > > >  3 files changed, 28 insertions(+), 3 deletions(-)
> > > > > >  create mode 100644 tools/lib/bpf/libbpf.pc.template
> > > > > > 
> > > > > > 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 a05c43468bd0..1df3ebfb3118 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)
> > > > > > @@ -89,6 +90,7 @@ OBJ		= $@
> > > > > >  N		=
> > > > > >  
> > > > > >  LIBBPF_VERSION =
> > > > > > $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
> > > > > > +KERNEL_VERSION = $(shell make --no-print-directory -sC
> > > > > > ../../..
> > > > > > kernelversion)
> > > > > Oh, we do already have LIBBPF_VERSION, why not use that? This
> > > > > way
> > > > > you don't need to do anything for out-of-tree libbpf from
> > > > > github.
> > > > > 
> > > > > I don't remember what was the strategy regarding libbpf
> > > > > versioning,
> > > > > but
> > > > > that 0.0.1 should be changed to something sensible (be set to
> > > > > the
> > > > > kernel
> > > > > version upon release?)
> > > > 
> > > > [re-sending as reply via phone added html and the list daemon
> > > > said
> > > > no-
> > > > no]
> > > > 
> > > > That looks like the ABI version though, rather than the source
> > > > version?
> > > > The source version is more appropriate for the PC file
> > > 
> > > That said, the versioning looks looks like it could use some love
> > > and
> > > it's not really a factor that should gate a pkg-config file and
> > > could
> > > be done separately if required, so in v3 I've removed
> > > KERNEL_VERSION
> > > and used LIBBPF_VERSION as you suggested.
> > Agree :-) There was some conversation recently about incrementing it
> > per
> > kernel release vs real api change. I don't remember what the outcome
> > was exactly.
> 
> I see, thanks. Anything else you'd like me to change?
No, everything looks good to me, wait for the reply from the bpf
maintainers.

> -- 
> Kind regards,
> Luca Boccassi
Daniel Borkmann March 20, 2019, 8:54 p.m. UTC | #7
On 03/20/2019 09:44 PM, Stanislav Fomichev wrote:
> On 03/20, Luca Boccassi wrote:
>> On Wed, 2019-03-20 at 10:21 -0700, Stanislav Fomichev wrote:
>>> On 03/20, Luca Boccassi wrote:
>>>> On Wed, 2019-03-20 at 13:22 +0000, Luca Boccassi wrote:
>>>>> On Tue, 2019-03-19 at 16:17 -0700, Stanislav Fomichev wrote:
>>>>>> On 03/19, Luca Boccassi wrote:
>>>>>>> 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>
>>>>>>> ---
>>>>>>> v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
>>>>>>>     save kernel version in its own variable instead of
>>>>>>> calling
>>>>>>>     make inline
>>>>>>>
>>>>>>>  tools/lib/bpf/.gitignore         |  1 +
>>>>>>>  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
>>>>>>>  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
>>>>>>>  3 files changed, 28 insertions(+), 3 deletions(-)
>>>>>>>  create mode 100644 tools/lib/bpf/libbpf.pc.template
>>>>>>>
>>>>>>> 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 a05c43468bd0..1df3ebfb3118 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)
>>>>>>> @@ -89,6 +90,7 @@ OBJ		= $@
>>>>>>>  N		=
>>>>>>>  
>>>>>>>  LIBBPF_VERSION =
>>>>>>> $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
>>>>>>> +KERNEL_VERSION = $(shell make --no-print-directory -sC
>>>>>>> ../../..
>>>>>>> kernelversion)
>>>>>> Oh, we do already have LIBBPF_VERSION, why not use that? This
>>>>>> way
>>>>>> you don't need to do anything for out-of-tree libbpf from
>>>>>> github.
>>>>>>
>>>>>> I don't remember what was the strategy regarding libbpf
>>>>>> versioning,
>>>>>> but
>>>>>> that 0.0.1 should be changed to something sensible (be set to
>>>>>> the
>>>>>> kernel
>>>>>> version upon release?)
>>>>>
>>>>> [re-sending as reply via phone added html and the list daemon
>>>>> said
>>>>> no-
>>>>> no]
>>>>>
>>>>> That looks like the ABI version though, rather than the source
>>>>> version?
>>>>> The source version is more appropriate for the PC file
>>>>
>>>> That said, the versioning looks looks like it could use some love
>>>> and
>>>> it's not really a factor that should gate a pkg-config file and
>>>> could
>>>> be done separately if required, so in v3 I've removed
>>>> KERNEL_VERSION
>>>> and used LIBBPF_VERSION as you suggested.
>>> Agree :-) There was some conversation recently about incrementing it
>>> per
>>> kernel release vs real api change. I don't remember what the outcome
>>> was exactly.
>>
>> I see, thanks. Anything else you'd like me to change?
> No, everything looks good to me, wait for the reply from the bpf
> maintainers.

Current workflow regarding libbpf versioning is that version number
increase is synced with kernel release. Meaning, new development cycle
we bump the version when we e.g. add entries into libbpf.map file for
new api functions.
Stanislav Fomichev March 20, 2019, 9:13 p.m. UTC | #8
On 03/20, Daniel Borkmann wrote:
> On 03/20/2019 09:44 PM, Stanislav Fomichev wrote:
> > On 03/20, Luca Boccassi wrote:
> >> On Wed, 2019-03-20 at 10:21 -0700, Stanislav Fomichev wrote:
> >>> On 03/20, Luca Boccassi wrote:
> >>>> On Wed, 2019-03-20 at 13:22 +0000, Luca Boccassi wrote:
> >>>>> On Tue, 2019-03-19 at 16:17 -0700, Stanislav Fomichev wrote:
> >>>>>> On 03/19, Luca Boccassi wrote:
> >>>>>>> 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>
> >>>>>>> ---
> >>>>>>> v2: use QUIET_GEN instead of QUIET_LINK to generate pc file,
> >>>>>>>     save kernel version in its own variable instead of
> >>>>>>> calling
> >>>>>>>     make inline
> >>>>>>>
> >>>>>>>  tools/lib/bpf/.gitignore         |  1 +
> >>>>>>>  tools/lib/bpf/Makefile           | 19 ++++++++++++++++---
> >>>>>>>  tools/lib/bpf/libbpf.pc.template | 11 +++++++++++
> >>>>>>>  3 files changed, 28 insertions(+), 3 deletions(-)
> >>>>>>>  create mode 100644 tools/lib/bpf/libbpf.pc.template
> >>>>>>>
> >>>>>>> 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 a05c43468bd0..1df3ebfb3118 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)
> >>>>>>> @@ -89,6 +90,7 @@ OBJ		= $@
> >>>>>>>  N		=
> >>>>>>>  
> >>>>>>>  LIBBPF_VERSION =
> >>>>>>> $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
> >>>>>>> +KERNEL_VERSION = $(shell make --no-print-directory -sC
> >>>>>>> ../../..
> >>>>>>> kernelversion)
> >>>>>> Oh, we do already have LIBBPF_VERSION, why not use that? This
> >>>>>> way
> >>>>>> you don't need to do anything for out-of-tree libbpf from
> >>>>>> github.
> >>>>>>
> >>>>>> I don't remember what was the strategy regarding libbpf
> >>>>>> versioning,
> >>>>>> but
> >>>>>> that 0.0.1 should be changed to something sensible (be set to
> >>>>>> the
> >>>>>> kernel
> >>>>>> version upon release?)
> >>>>>
> >>>>> [re-sending as reply via phone added html and the list daemon
> >>>>> said
> >>>>> no-
> >>>>> no]
> >>>>>
> >>>>> That looks like the ABI version though, rather than the source
> >>>>> version?
> >>>>> The source version is more appropriate for the PC file
> >>>>
> >>>> That said, the versioning looks looks like it could use some love
> >>>> and
> >>>> it's not really a factor that should gate a pkg-config file and
> >>>> could
> >>>> be done separately if required, so in v3 I've removed
> >>>> KERNEL_VERSION
> >>>> and used LIBBPF_VERSION as you suggested.
> >>> Agree :-) There was some conversation recently about incrementing it
> >>> per
> >>> kernel release vs real api change. I don't remember what the outcome
> >>> was exactly.
> >>
> >> I see, thanks. Anything else you'd like me to change?
> > No, everything looks good to me, wait for the reply from the bpf
> > maintainers.
> 
> Current workflow regarding libbpf versioning is that version number
> increase is synced with kernel release. Meaning, new development cycle
> we bump the version when we e.g. add entries into libbpf.map file for
> new api functions.
So it will have its own version, not matching the kernel? I thought we
would keep it 0.0.X until we figure things out and then just follow the
kernel. (I'm fine either way, just wondering).

It's still 0.0.1 in Linus's tree, bpf and in bpf-next btw, even though we
already have LIBBPF_0.0.2 in the libbpf.map file :-)
diff mbox series

Patch

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 a05c43468bd0..1df3ebfb3118 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)
@@ -89,6 +90,7 @@  OBJ		= $@
 N		=
 
 LIBBPF_VERSION = $(BPF_VERSION).$(BPF_PATCHLEVEL).$(BPF_EXTRAVERSION)
+KERNEL_VERSION = $(shell make --no-print-directory -sC ../../.. kernelversion)
 
 # Set compile option CFLAGS
 ifdef EXTRA_CFLAGS
@@ -137,7 +139,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
 
@@ -179,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@|$(KERNEL_VERSION)|" \
+		< $@.template > $@
+
 check: check_abi
 
 check_abi: $(OUTPUT)libbpf.so
@@ -208,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
 
@@ -218,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..0cac2f5f54a6
--- /dev/null
+++ b/tools/lib/bpf/libbpf.pc.template
@@ -0,0 +1,11 @@ 
+prefix=@PREFIX@
+libdir=@LIBDIR@
+includedir=${prefix}/include/bpf
+
+Name: libbpf
+URL: https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
+Description: Linux kernel BPF library
+Version: @VERSION@
+Libs: -L${libdir} -lbpf
+Requires.private: libelf
+Cflags: -I${includedir}