From da81586a5b026fcce1b11a3505b380dfd61e6a2c Mon Sep 17 00:00:00 2001 From: Eli Schwartz Date: Sun, 26 Sep 2021 18:52:58 -0400 Subject: pkgconfig module: correctly generate Libs search path with absolute install_dir For example the OpenRC build files install libraries to install_dir: '/lib' and this works, but causes the generated pkg-config to say: prefix=/usr Libs: -L${prefix}//lib which is both ugly (double //) and resolves to /usr/lib which is exactly what does not work. --- mesonbuild/modules/pkgconfig.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index e865110..001d3ca 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -318,9 +318,11 @@ class PkgConfigModule(ExtensionModule): prefix = PurePath(prefix) subdir = PurePath(subdir) try: - return subdir.relative_to(prefix).as_posix() + libdir = subdir.relative_to(prefix) except ValueError: - return subdir.as_posix() + libdir = subdir + # pathlib joining makes sure absolute libdir is not appended to '${prefix}' + return ('${prefix}' / libdir).as_posix() def _generate_pkgconfig_file(self, state, deps, subdirs, name, description, url, version, pcfile, conflicts, variables, @@ -387,12 +389,12 @@ class PkgConfigModule(ExtensionModule): is_custom_target = isinstance(l, (build.CustomTarget, build.CustomTargetIndex)) if not is_custom_target and 'cs' in l.compilers: if isinstance(install_dir, str): - Lflag = '-r${{prefix}}/{}/{}'.format(self._escape(self._make_relative(prefix, install_dir)), l.filename) + Lflag = '-r{}/{}'.format(self._escape(self._make_relative(prefix, install_dir)), l.filename) else: # install_dir is True Lflag = '-r${libdir}/%s' % l.filename else: if isinstance(install_dir, str): - Lflag = '-L${prefix}/%s' % self._escape(self._make_relative(prefix, install_dir)) + Lflag = '-L{}'.format(self._escape(self._make_relative(prefix, install_dir))) else: # install_dir is True Lflag = '-L${libdir}' if Lflag not in Lflags: -- cgit v1.1