#998017 pkg-config: Build a library with its own .pc file

Package:
pkg-config
Source:
pkg-config
Description:
manage compile and link flags for libraries (transitional package)
Submitter:
Alejandro Colomar
Date:
2021-10-28 17:15:06 UTC
Severity:
wishlist
Tags:
#998017#5
Date:
2021-10-28 14:48:02 UTC
From:
To:
Dear Maintainer,

I'm building a library with its own pkg-config file.
That avoids repeating the information in the .pc file again in the Makefile.
And it also avoids releasing broken .pc files; if the .pc file was incorrect,
my library simply wouldn't build.

However, there's no easy way to do that (and I found today the source of a
bug in my build system due to a missing line).  It would be easier if
pkg-config allowed that in a simple manner.

To build (link) a library, I have the following in my Makefile:

PC_ENV := PKG_CONFIG_PATH=lib/pkgconfig
req_pc := $(shell $(PC_ENV) pkg-config --print-requires-private libfoo)
LIBS := -L$(builddir)
LIBS += $(shell $(PC_ENV) pkg-config --libs libfoo)
LIBS += $(shell $(PC_ENV) pkg-config --libs $(req_pc))

However, I noticed today that I was missing the information in Libs.private
from my .pc file.  But I don't want to invoke '--static --libs', since that
would pull the Libs.private from all my dependencies, which I don't need.

So I need to extract those with sed.  But pkg-config could (and I think
should) do that.

To mirror cc syntax, where -static means link an executable against
static libraries, but -shared means build a shared library,
I think the best syntax for pkg-config would be to add a --shared flag.
For pkg-config, --static would be used for linking an executable against
a static library, and --shared would be used to build a shared object.

So, the following lines should be enough to pull all libs necessary for
building the shared object corresponding to a given .pc file:

PC_ENV := PKG_CONFIG_PATH=lib/pkgconfig
LIBS := $(shell $(PC_ENV) pkg-config --shared --libs libfoo)


Thanks,

Alex

#998017#10
Date:
2021-10-28 17:13:35 UTC
From:
To:
PC_ENV := PKG_CONFIG_PATH=lib/pkgconfig
req_pc := $(shell $(PC_ENV) pkg-config --print-requires-private libfoo)
LIBS := -L$(builddir)
LIBS += $(shell $(PC_ENV) pkg-config --libs libfoo)
LIBS += $(shell $(PC_ENV) pkg-config --libs $(req_pc) 2>/dev/null)
LIBS += $(shell sed -n '/^Libs.private: /s///p'
lib/pkgconfig/libfoo-uninstalled.pc)