Repository: mesonbuild/meson

Issue:
Wrong linker flags with default paths
Since [0.40.0](http://mesonbuild.com/Release-notes-for-0-40-0.html#multiple-install-directories), meson is able to use multiple directories, and this feature is also used for `valac`.

In this case, if `true` is used it is installed in the default location. However, if a library is created with `true` and the `Pkgconfig`'s `generate` functions is used, the `True` string is used as part of the link flag. For example, the following code is used to generate a shared library and the correspondant `pkg-config` file:

```
libgitg = shared_library(
  lib_api_name,
  name_prefix: '',
  sources: sources,
  version: libversion,
  soversion: soversion,
  include_directories: top_inc,
  dependencies: deps,
  c_args: cflags,
  vala_header: lib_name + '.h',
  vala_vapi: lib_api_name + '.vapi',
  vala_gir: gir_name,
  link_args: ldflags,
  link_depends: symbol_map,
  install: true,
  install_dir: [
    true,
    join_paths(gitg_includedir, lib_api_name, lib_name),
    true,
    true
  ]
)

pkg.generate(
  libraries: libgitg,
  version: gitg_version,
  name: meson.project_name(),
  description: meson.project_name() + ' library',
  filebase: lib_api_name,
  subdirs: lib_api_name,
  requires: [
    'gio-2.0',
    'glib-2.0',
    'gmodule-2.0',
    'gobject-2.0',
    'gthread-2.0',
    'gtk+-3.0',
    'libgit2-glib-1.0',
    gio_system_pkg
  ],
  variables: 'exec_prefix=' + gitg_prefix,
  install_dir: join_paths(gitg_libdir, 'pkgconfig')
)
```

It produces the following `pc` file:

```
prefix=/tmp/gitg
libdir=${prefix}/lib
includedir=${prefix}/include
exec_prefix=/tmp/gitg

Name: gitg
Description: gitg library
Version: 3.26.0
Requires: gio-2.0 glib-2.0 gmodule-2.0 gobject-2.0 gthread-2.0 gtk+-3.0 libgit2-glib-1.0 gio-unix-2.0
Libs: -L${prefix}/True  -lgitg-1.0
Cflags: -I${includedir}/libgitg-1.0
```


Discussion:
This problem also extends to the installation path of the libraries. If the `install_dir` parameter is pointing to an absolute path, the parameter will be included as `-L${prefix}/abs_path`, which is wrong because the absolute path also holds `$prefix`.

Resolving patch:
diff --git a/mesonbuild/modules/pkgconfig.py b/mesonbuild/modules/pkgconfig.py
--- a/mesonbuild/modules/pkgconfig.py
+++ b/mesonbuild/modules/pkgconfig.py
@@ -55,6 +55,15 @@ def _escape(self, value):
             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 @@ def generate_libs_flags(libs):
                         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)


Test patch: