PKG_CONFIG_SYSROOT_DIR get also prepended to libraries outside of SYSROOT #213

Closed
opened 2021-02-24 11:34:28 +00:00 by coldtobi · 6 comments
coldtobi commented 2021-02-24 11:34:28 +00:00 (Migrated from github.com)

I've got a problem when employing PKG_CONFIG_SYSROOT_DIR:

Not all of my libraries are contained in the sysroot, but there are other libraries built outside of the sysroot. (The sysroot is provided to me, so it is not so easily changed)

A concrete example:
my project needs libssh2, (which is not in the sysroot) is configured with prefix=/home/tobi/libs/libssh2/usr and it creates libssh2.pc with said prefix (libssh2.pc quoted in full at the bottom)

However, when PKG_CONFIG_SYSROOT_DIR is defined, for example to
PKG_CONFIG_SYSROOT=/home/tobi/sysroot, the generated path

pkgconf --cflags libssh2

will get me:
/home/tobi/sysroot/home/tobi/libs/libssh/usr/include

which of course is not a valid path.

Should PKG_CONFIG_SYSROOT_DIR only be applied if the pc was coming from the sysroot?

TIA for any hints!

prefix=/home/EU.BSHG.COM/tobi/libs/libssh2/usr
exec_prefix=/home/EU.BSHG.COM/tobi/libs/libssh2/usr
libdir=${prefix}/lib
includedir=${prefix}/include

Name: libssh2
URL: https://www.libssh2.org/
Description: Library for SSH-based communication
Version: 1.9.0
Requires.private: libssl libcrypto zlib
Libs: -L${libdir} -lssh2
Libs.private:  -lgpg-error
Cflags: -I${includedir}

(note I've sent basically the same text also to pkg-config [1] and after I checked that pkgconf unfortunatly could not help me here, I thought it might be a good idea to post it here too.
On pkg-config. there is a PR pending with an another approach idea to us a new env map ( PKG_CONFIG_SYSROOT_MAP) to map pathes between several sysroots. Maybe interesting approach as well… [2]

[1] https://gitlab.freedesktop.org/pkg-config/pkg-config/-/issues/52
[2] https://gitlab.freedesktop.org/pkg-config/pkg-config/-/merge_requests/7

Cheers,
tobi

I've got a problem when employing `PKG_CONFIG_SYSROOT_DIR`: Not all of my libraries are contained in the sysroot, but there are other libraries built outside of the sysroot. (The sysroot is provided to me, so it is not so easily changed) A concrete example: my project needs libssh2, (which is not in the sysroot) is configured with `prefix=/home/tobi/libs/libssh2/usr `and it creates libssh2.pc with said prefix (libssh2.pc quoted in full at the bottom) However, when `PKG_CONFIG_SYSROOT_DIR` is defined, for example to `PKG_CONFIG_SYSROOT=/home/tobi/sysroot`, the generated path `pkgconf --cflags libssh2` will get me: `/home/tobi/sysroot/home/tobi/libs/libssh/usr/include` which of course is not a valid path. Should PKG_CONFIG_SYSROOT_DIR only be applied if the pc was coming from the sysroot? TIA for any hints! ``` prefix=/home/EU.BSHG.COM/tobi/libs/libssh2/usr exec_prefix=/home/EU.BSHG.COM/tobi/libs/libssh2/usr libdir=${prefix}/lib includedir=${prefix}/include Name: libssh2 URL: https://www.libssh2.org/ Description: Library for SSH-based communication Version: 1.9.0 Requires.private: libssl libcrypto zlib Libs: -L${libdir} -lssh2 Libs.private: -lgpg-error Cflags: -I${includedir} ``` (note I've sent basically the same text also to pkg-config [1] and after I checked that pkgconf unfortunatly could not help me here, I thought it might be a good idea to post it here too. On pkg-config. there is a PR pending with an another approach idea to us a new env map ( PKG_CONFIG_SYSROOT_MAP) to map pathes between several sysroots. Maybe interesting approach as well… [2] [1] https://gitlab.freedesktop.org/pkg-config/pkg-config/-/issues/52 [2] https://gitlab.freedesktop.org/pkg-config/pkg-config/-/merge_requests/7 Cheers, tobi

the PKG_CONFIG_SYSROOT_MAP proposal is flawed and pending reimplementation. it will be part of pkgconf 2.0.

the `PKG_CONFIG_SYSROOT_MAP` proposal is flawed and pending reimplementation. it will be part of pkgconf 2.0.
coldtobi commented 2021-02-24 17:18:26 +00:00 (Migrated from github.com)

@kaniini thaks for the feedback
I wrote myself a wrapper script removing PKG_CONFIG_SYSROOT_DIR from the generated path if the generated path is not resolving to a file system object. Would that be a possible solution to pick up solving my problem?

@kaniini thaks for the feedback I wrote myself a wrapper script removing PKG_CONFIG_SYSROOT_DIR from the generated path if the generated path is not resolving to a file system object. Would that be a possible solution to pick up solving my problem?

That seems like a reasonable workaround for now that could be documented.

I'm not enthusiastic about implementing workarounds in pkgconf itself code-wise, but I am hoping that we can implement the revised PKG_CONFIG_SYSROOT_MAP in the current development cycle.

That seems like a reasonable workaround for now that could be documented. I'm not enthusiastic about implementing workarounds in pkgconf itself code-wise, but I am hoping that we can implement the revised `PKG_CONFIG_SYSROOT_MAP` in the current development cycle.
coldtobi commented 2021-02-25 13:41:58 +00:00 (Migrated from github.com)

FWIIW, here is my wrapper script; note that I only implemented enough for my usage; YMMV.

#!/bin/bash

set -e

mangle_pkg_config_result() {

    local OPTIND o a neednewline
    while getopts ":l:L:I:D:W" o; do
        case "${o}" in
             L | I )
                if [[ -e "${OPTARG}" ]] 
                then 
                  echo -n "-${o}${OPTARG} " 
                else
                  echo -n "-${o}${OPTARG##$PKG_CONFIG_SYSROOT_DIR} "
                fi
                neednewline=1
                ;;
            l | D | W )
                echo -n "-${o}${OPTARG} "
                neednewline=1
                ;;
            *)
                echo -n "-${o}"
                neednewline=1
        esac
    done
    shift $((OPTIND-1))
    if [[ $neednewline -ne 0 ]] ; then echo ; fi
}

if [[ "x$1" == "x--version" ]] ; then exec pkg-config "$@"; fi

string=$(pkg-config "$@")
ret=$?
if [[ $ret -ne 0 ]] ; then echo $string; exit $ret ; fi

mangle_pkg_config_result $string

(saved to a script and export PKG_CONFIG='filename' should do the trick for most buildsystem generators like autotools and cmake)

FWIIW, here is my wrapper script; note that I only implemented enough for my usage; YMMV. ``` #!/bin/bash set -e mangle_pkg_config_result() { local OPTIND o a neednewline while getopts ":l:L:I:D:W" o; do case "${o}" in L | I ) if [[ -e "${OPTARG}" ]] then echo -n "-${o}${OPTARG} " else echo -n "-${o}${OPTARG##$PKG_CONFIG_SYSROOT_DIR} " fi neednewline=1 ;; l | D | W ) echo -n "-${o}${OPTARG} " neednewline=1 ;; *) echo -n "-${o}" neednewline=1 esac done shift $((OPTIND-1)) if [[ $neednewline -ne 0 ]] ; then echo ; fi } if [[ "x$1" == "x--version" ]] ; then exec pkg-config "$@"; fi string=$(pkg-config "$@") ret=$? if [[ $ret -ne 0 ]] ; then echo $string; exit $ret ; fi mangle_pkg_config_result $string ``` (saved to a script and export PKG_CONFIG='filename' should do the trick for most buildsystem generators like autotools and cmake)

So, the purpose of PKG_CONFIG_SYSROOT_DIR is to enable building a sysroot where you use make install DESTDIR=$PKG_CONFIG_SYSROOT_DIR on everything (or equivalent for Meson).

So I agree with you that we should only mangle .pc files inside the sysroot itself.

So, the purpose of `PKG_CONFIG_SYSROOT_DIR` is to enable building a sysroot where you use `make install DESTDIR=$PKG_CONFIG_SYSROOT_DIR` on everything (or equivalent for Meson). So I agree with you that we should only mangle `.pc` files inside the sysroot itself.

However this is going to require a bit of rework to accomplish, so it won't make 1.7.4.

However this is going to require a bit of rework to accomplish, so it won't make 1.7.4.
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: ariadne/pkgconf#213
There is no content yet.