Repository: mesonbuild/meson

Issue:
rpath contains paths to static libs
Create a project with ninja backend and mirror layout:
```meson
# subdir_1
my_st_lib = static_library('my_st_lib', ...)
# subdir_2
my_sh_lib = shared_library('my_sh_lib', link_with: my_st_lib, ...)
```
`my_sh_lib`'s rpath will contain path to `subdir_1` (e.g. `$ORIGIN/../subdir_1`), which AFAIK is pointless.


Discussion:
**Code causing the problem:**
https://github.com/mesonbuild/meson/blob/6253bbc6cc18f2850d924eac690338dcdf45a23b/mesonbuild/backend/ninjabackend.py#L2555

**Possible fix:**
Add the same check as in https://github.com/mesonbuild/meson/blob/6253bbc6cc18f2850d924eac690338dcdf45a23b/mesonbuild/backend/ninjabackend.py#L1245

If this is not an intended behaviour, I can make a PR that fixes it.
Quite annoying staff in some cases. My scenario - Im building EFI app under linux. With using clang it is finnally becomes as simple as set the right triplet:

```
boot_x86_64_exe = executable(
  'boot.x86_64.efi', boot_x86_64_sources,
  include_directories: boot_headers,
  link_with: [lib_elc, boot_libs_crypto, boot_libs_compress],

  c_args: ['-target','x86_64-pc-win32-coff','-fno-stack-protector','-fshort-wchar','-mno-red-zone','-D__LIB_ENV_EFI=1'],
  link_args: ['-target','x86_64-pc-win32-coff','-fuse-ld=lld','-nodefaultlibs','-nostartfiles','-Wl,-subsystem:efi_application','-Wl,-entry:efi_main']
)
```

However meson messes up flags adding rlink staff even if all libraries are ```static```. Also it makes no sens to add ```rlink``` flags with ```x86_64-pc-win32-coff``` and ```-fuse-ld=lld``` you will get output:
```
lld-link: warning: ignoring unknown argument '-rpath'
lld-link: warning: ignoring unknown argument '-rpath-link'
lld-link: warning: ignoring /lib since it's not the first argument
lld-link: error: could not open '$ORIGIN/': No such file or directory
....
```
After a bit of grep i've made a little patch in Backends class:
```
    @lru_cache(maxsize=None)
    def get_link_dep_subdirs(self):
        result = OrderedSet()
        for i in self.link_targets:
            if isinstance(i, StaticLibrary): continue # here is it, skip static libs
            result.add(i.get_subdir())
            result.update(i.get_link_dep_subdirs())
        return result
```
However something tells me it is not a really proper way to fix the issue :(

Resolving patch:
diff --git a/mesonbuild/build.py b/mesonbuild/build.py
--- a/mesonbuild/build.py
+++ b/mesonbuild/build.py
@@ -819,7 +819,8 @@ def get_transitive_link_deps_mapping(self, prefix, environment):
     def get_link_dep_subdirs(self):
         result = OrderedSet()
         for i in self.link_targets:
-            result.add(i.get_subdir())
+            if not isinstance(i, StaticLibrary):
+                result.add(i.get_subdir())
             result.update(i.get_link_dep_subdirs())
         return result
 
diff --git a/run_unittests.py b/run_unittests.py
--- a/run_unittests.py
+++ b/run_unittests.py
@@ -7030,6 +7030,13 @@ def test_wrap_with_file_url(self):
         windows_proof_rmtree(os.path.join(testdir, 'subprojects', 'foo'))
         os.unlink(wrap_filename)
 
+    def test_no_rpath_for_static(self):
+        testdir = os.path.join(self.common_test_dir, '5 linkstatic')
+        self.init(testdir)
+        self.build()
+        build_rpath = get_rpath(os.path.join(self.builddir, 'prog'))
+        self.assertIsNone(build_rpath)
+
 
 class BaseLinuxCrossTests(BasePlatformTests):
     # Don't pass --libdir when cross-compiling. We have tests that


Test patch: