pkgconf / pkgconf

package compiler and linker metadata toolkit

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

`--variable` does not strip sysroot

ismell opened this issue · comments

There is a behavior difference between pkgconf and pkgconfig:

pkg-config-arm64-generic contains the following:

#!/bin/bash

PKG_CONFIG_LIBDIR=$(printf '%s:' "/build/arm64-generic"/usr/*/pkgconfig)
export PKG_CONFIG_LIBDIR

export PKG_CONFIG_SYSROOT_DIR="/build/arm64-generic"

# TODO: Consider using pkgconf cross-personalities instead
# See https://github.com/pkgconf/pkgconf/issues/264
export PKG_CONFIG_SYSTEM_INCLUDE_PATH="/usr/include:/build/arm64-generic/usr/include"

exec /usr/bin/pkg-config "$@"

pkgconfig

$ pkg-config-arm64-generic --variable=enginesdir libcrypto
/usr/lib64/engines-1.1

pkgconf

$ pkg-config-arm64-generic --variable=enginesdir libcrypto
/build/arm64-generic/usr/lib64/engines-1.1

I then tried using a personality file:

$ cat /tmp/arm64-generic.personality
Triplet: default
SysrootDir: /build/arm64-generic
DefaultSearchPaths: /build/arm64-generic/usr/lib64/pkgconfig:/build/arm64-generic/usr/share/pkgconfig 
SystemIncludePaths: /build/arm64-generic/usr/include 
SystemLibraryPaths: /build/arm64-generic/lib64 /build/arm64-generic/usr/lib64 
$ pkg-config --personality=/tmp/arm64-generic.personality --variable=enginesdir libcrypto
/build/arm64-generic/usr/lib64/engines-1.1

So it looks like pkgconfig is stripping the sysroot from any variables it returns, while pkgconf doesn't.

The reason this came up is that I was trying to build libp11 using pkgconf , but it resulted in placing the .so in the wrong folder. See https://github.com/OpenSC/libp11/blob/master/configure.ac#L131

Is this a bug in pkgconf, or should libp11 change to strip the current SYSROOT from anything returned from pkgconf --variable=XX?

This is what the libcrypto.pc file looks like:

$ cat /build/arm64-generic/usr/lib64/pkgconfig/libcrypto.pc 
prefix=/usr
exec_prefix=${prefix}
libdir=${exec_prefix}/lib64
includedir=${prefix}/include
enginesdir=${libdir}/engines-1.1

Name: OpenSSL-libcrypto
Description: OpenSSL cryptography library
Version: 1.1.1u
Libs: -L${libdir} -lcrypto
Libs.private: -ldl -pthread 
Cflags: -I${includedir}

Thanks

Hrmm, this seems to be a problem with svgrlib as well: https://gitlab.gnome.org/GNOME/librsvg/-/blob/2.40.21/configure.ac#L97

This is a long standing deviation from pkg-config and is well documented. It will not be changed.

Could you mention where it's documented? If I have documentation I can point projects to, I can more easily get them to adjust their build systems.

What's the recommended way for build systems to support both pkgconf and pkg-config? Should they be probing for pkgconf and manually be stripping the sysroot suffix?

I should clarify:

The original motivation for pkgconf was that a lot of .pc files did not understand sysroot. So, pkgconf will adjust the ${prefix} in order to be consistent with regards to sysroot. If it detects that ${pc_sysrootdir} is used correctly, then it will not make any adjustments.

This handling of ${prefix} is done consistently at load time of the .pc file.

However, as noted here, there are cases where this is unwanted. In my opinion, the correct way to solve those cases, is to use the -uninstalled variant of the .pc file. If you use the -uninstalled variant of the .pc file, then we will not try to fix the sysroot. This is what the -uninstalled variants are for, in fact, though admittedly documentation on them is sparse.

You can also set the PKG_CONFIG_FDO_SYSROOT_RULES environmental variable to get the Freedesktop pkg-config behavior, which is documented in pkgconf(1):

kaniini@phoebe build % PKG_CONFIG_SYSROOT_DIR=/example-foo ./pkgconf --with-path=../tests/lib1 foo --variable=prefix
/example-foo/test
kaniini@phoebe build % PKG_CONFIG_SYSROOT_DIR=/example-foo PKG_CONFIG_FDO_SYSROOT_RULES=1 ./pkgconf --with-path=../tests/lib1 foo --variable=prefix
/test