Bug 62018 - Document ${pcfiledir} variable
Summary: Document ${pcfiledir} variable
Status: RESOLVED FIXED
Alias: None
Product: pkg-config
Classification: Unclassified
Component: src (show other bugs)
Version: unspecified
Hardware: All All
: medium normal
Assignee: Dan Nicholson
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2013-03-08 11:03 UTC by Behdad Esfahbod
Modified: 2013-05-17 12:33 UTC (History)
1 user (show)

See Also:
i915 platform:
i915 features:


Attachments

Description Behdad Esfahbod 2013-03-08 11:03:40 UTC
This may already be possible, don't know.  But would be useful to allow prefix to be defined relative to the .pc file itself.

Normally I encounter this whenever I download prebuilt dev packages for Windows.  They have a full hierarchy, so you can for example unzip them in ~/.local/x86_64-w64-mingw32 and everything will be in place.  Except that the .pc file will have a c:\... in prefix, which is from where it was built.

Would be nice if we could somehow get prefix=${cwd}/../.. or something.
Comment 1 Dan Nicholson 2013-04-06 19:03:20 UTC
Currently pkg-config on Windows does a little trick where it rewrites the ${prefix} variable at runtime based on the location of the .pc file. This works well enough, so long as the other path variables in the .pc file derive from ${prefix}. It's pretty magical, though.

However, I like this relative path feature a lot since it would be more general. It would be pretty easy to handle by just having pkg-config define a variable for each .pc file. ${cwd} implies the current working directory rather than the directory of the .pc file. We could borrow some parlance from ld.so and make the variable ${ORIGIN} like it uses when following rpath.
Comment 2 Behdad Esfahbod 2013-04-06 19:25:24 UTC
Thanks for the information.  Didn't know about the magic on Windows.  For me, I'm cross-compiling, so I have this issue on Linux.  I agree that "cwd" isn't the right name.
Comment 3 Dan Nicholson 2013-04-06 19:34:36 UTC
Yay for undocumented features! While having a quick look around for where to insert this magic variable, I found out pkg-config already had one. pcfiledir is defined from the location it was found at.

$ cat /tmp/lib/pkgconfig/relpath.pc
prefix=${pcfiledir}/../..
exec_prefix=${prefix}
libdir=${exec_prefix}/lib
includedir=${prefix}/include

Name: Simple test
Description: Dummy pkgconfig test package for testing pkgconfig
Version: 1.0.0
Requires:
Libs: -L${libdir} -lfoo
Cflags: -I${includedir}
$ PKG_CONFIG_PATH=/tmp/lib/pkgconfig pkg-config --cflags relpath
-I/tmp/lib/pkgconfig/../../include

This looks to have been there at least since pkg-config-0.21. I'm going to change this bug to be about documenting pcfiledir.
Comment 4 Behdad Esfahbod 2013-04-06 19:42:01 UTC
Fantastic!  Ok.  Then perhaps the harder thing to do would be to change every project to default to ${pcfiledir}/.. instead of ${prefix} when creating their .pc files?
Comment 5 Dan Nicholson 2013-04-16 12:38:39 UTC
(In reply to comment #4)
> Fantastic!  Ok.  Then perhaps the harder thing to do would be to change
> every project to default to ${pcfiledir}/.. instead of ${prefix} when
> creating their .pc files?

Yeah, that would be the issue. I remember thinking the same thing about the magic prefix mangling on Windows: in order for the feature to work, you're dependent on people writing well formed .pc files. It turns out, though, that the magic prefix feature as written by tml actually handles the case where the variables are already expanded by keeping track of the original value of prefix and replacing that path if it finds it anywhere.

So, there may actually be 2 ways to make a relocatable .pc file: use ${pcfiledir}, use --define-prefix behavior. I actually was working to make that --define-prefix feature available everywhere, if only for the reason that I could actually test the code without having to get on Windows. This just gives a little more motivation. I'm going to open a separate bug to keep track of that and keep this about documenting pcfiledir.
Comment 6 Dan Nicholson 2013-05-17 12:33:59 UTC
Fixed in 925119c.

What could be useful to help with getting every project to use ${pcfiledir} would be to have the newer PKG_INSTALLDIR m4 module calculate where prefix is relative to ${pcfiledir} and then substitute it as @pkgrel_prefix@ or something. Then fixing your .pc file would be as simple as changing thing @prefix@ substitution. Another day...


Use of freedesktop.org services, including Bugzilla, is subject to our Code of Conduct. How we collect and use information is described in our Privacy Policy.