Handle LD_RUN_PATH like LIBRARY_PATH, to also strip RPATH flags (-Wl,-R -Wl,-rpath=)
I noticed that pkg-config drops -L/foo/lib from the flags if LIBRARY_PATH contains /foo/lib. Similar for -I/foo/include.
I think it should also drop RPATH-related flags if LD_RUN_PATH is set.
The context is pkgsrc, which adds -Wl,-R$prefix/lib into its .pc files. This normally is sensible, but in our case of an HPC installation that manages user's access to software and build environments via environment modules, it creates some conflict.
With the environment modules, we manage PATH, CPATH/C_INCLUDE_PATH, LIBRARY_PATH as well as LD_RUN_PATH to make builds do the right thing to use the currently chosen tools and libraries, also with correct RPATH written to the binaries. We avoid using LD_LIBRARY_PATH.
The peculiar nature of LD_RUN_PATH is that any present -Wl,-R completely neuters LD_RUN_PATH. So, it would be nice if pkg-config stripped those too if they are in LD_RUN_PATH. If they're not, then my LD_RUN_PATH will be useless but it's my fault for not including some needed path in it and I can fix that. One could decide to make pkg-config drop all RPATH-related flags in the presence of any LD_RUN_PATH in the environment, though. The intention of the user is not totally obvious in that case.
Any of those two solutions would be fine by me. What's your take? I could have prepared a patch, but it would be rather direct copy and paste from the -L flag handling (so some refactoring might be more useful). I'd like to have the general idea settled first, anyway.
So, shall pkg-config also handle LD_RUN_PATH and filter RPATH-related linker flags?