On 10/28/21 16:48, Alejandro Colomar wrote:
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)
So, that should be equivalent 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)
--
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/