From 638077181a79bb974494bce8355e49a11b22d242 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?I=C3=B1igo=20Mart=C3=ADnez?= Date: Thu, 16 Nov 2017 15:14:41 +0100 Subject: [PATCH] pkgconfig: Handle prefix in library path The install_dir parameter of the libraries can also contain the prefix path, which creates wrong library paths in the .pc file. This patch detects if prefix is contained in the library path and creates a relative path. Fixes #2469 --- mesonbuild/modules/pkgconfig.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py index 52f3a502e..f96332377 100644 --- a/mesonbuild/modules/pkgconfig.py +++ b/mesonbuild/modules/pkgconfig.py @@ -55,6 +55,15 @@ class PkgConfigModule(ExtensionModule): value = value.as_posix() return value.replace(' ', '\ ') + def _make_relative(self, prefix, subdir): + if isinstance(prefix, PurePath): + prefix = prefix.as_posix() + if isinstance(subdir, PurePath): + subdir = subdir.as_posix() + if subdir.startswith(prefix): + subdir = subdir.replace(prefix, '') + return subdir + def generate_pkgconfig_file(self, state, libraries, subdirs, name, description, url, version, pcfile, pub_reqs, priv_reqs, conflicts, priv_libs, extra_cflags, variables): @@ -98,7 +107,7 @@ class PkgConfigModule(ExtensionModule): if install_dir is False: continue if isinstance(install_dir, str): - yield '-L${prefix}/%s ' % self._escape(install_dir) + yield '-L${prefix}/%s ' % self._escape(self._make_relative(prefix, install_dir)) else: # install_dir is True yield '-L${libdir}' lname = self._get_lname(l, msg, pcfile)