Repository: mesonbuild/meson

Issue:
Meson generates a build.ninja file with incorrect dependencies
**Describe the bug**
(Regression in 0.64.0) Meson generates a `build.ninja` file with incorrect dependencies if all these three situations are present in the `meson.build`:
* The `project()` function has language `fortran` , either as unique language or secondary
* A target depends on objects extracted from another target
* The first target contains source and header files

**To Reproduce**
meson.build:
```
project('test_project', 'c',
  'fortran',
)

sources_tmp = [
  't1.c',
  't1.h',
]

libtmp = static_library(
  'tmp', sources_tmp,
  install: false,
)

tmp_objects = libtmp.extract_all_objects(recursive : true)

sources = [
  't2.c',
]

libfinal = library(
  'final', sources,
  objects : tmp_objects,
)
```

Source and headers may be empty (`touch t1.c t1.h t2.c`). After a `meson setup`, the command `ninja`returns:
```
ninja: error: 'libfinal.so.p/libtmp.a', needed by 'libfinal.so.p/t2.c.o', missing and no known rule to make it
```
Either commeting line 2 (`fortran`) or line 7 (`'t1.h',`) makes the error to  disappear.


**system parameters**
* plain native build
* O.S.: Arch Linux
* `python --version`: 3.10.8
* `meson --version`: 0.64.0
* `ninja --version`: 1.11.1



Discussion:

Resolving patch:
diff --git a/mesonbuild/backend/ninjabackend.py b/mesonbuild/backend/ninjabackend.py
--- a/mesonbuild/backend/ninjabackend.py
+++ b/mesonbuild/backend/ninjabackend.py
@@ -380,7 +380,8 @@ def write(self, outfile):
         if len(self.deps) > 0:
             line += ' | ' + ' '.join([ninja_quote(x, True) for x in sorted(self.deps)])
         if len(self.orderdeps) > 0:
-            line += ' || ' + ' '.join([ninja_quote(x, True) for x in sorted(self.orderdeps)])
+            orderdeps = [str(x) for x in self.orderdeps]
+            line += ' || ' + ' '.join([ninja_quote(x, True) for x in sorted(orderdeps)])
         line += '\n'
         # This is the only way I could find to make this work on all
         # platforms including Windows command shell. Slash is a dir separator
@@ -956,7 +957,7 @@ def generate_target(self, target):
         obj_targets = [t for t in od if t.uses_fortran()]
         obj_list.extend(o)
 
-        fortran_order_deps = [self.get_target_filename(t) for t in obj_targets]
+        fortran_order_deps = [File(True, *os.path.split(self.get_target_filename(t))) for t in obj_targets]
         fortran_inc_args: T.List[str] = []
         if target.uses_fortran():
             fortran_inc_args = mesonlib.listify([target.compilers['fortran'].get_include_args(
@@ -1049,7 +1050,7 @@ def should_use_dyndeps_for_target(self, target: 'build.BuildTarget') -> bool:
         return True
 
     def generate_dependency_scan_target(self, target, compiled_sources, source2object, generated_source_files: T.List[mesonlib.File],
-                                        object_deps: T.List[str]) -> None:
+                                        object_deps: T.List['mesonlib.FileOrString']) -> None:
         if not self.should_use_dyndeps_for_target(target):
             return
         depscan_file = self.get_dep_scan_file_for(target)
@@ -2836,7 +2837,7 @@ def _generate_single_compile_target_args(self, target: build.BuildTarget, compil
 
     def generate_single_compile(self, target: build.BuildTarget, src,
                                 is_generated=False, header_deps=None,
-                                order_deps: T.Optional[T.List[str]] = None,
+                                order_deps: T.Optional[T.List['mesonlib.FileOrString']] = None,
                                 extra_args: T.Optional[T.List[str]] = None,
                                 unity_sources: T.Optional[T.List[mesonlib.FileOrString]] = None) -> None:
         """


Test patch:
diff --git a/test cases/fortran/22 extract_objects/bar.f90 b/test cases/fortran/22 extract_objects/bar.f90
new file mode 100644
diff --git a/test cases/fortran/22 extract_objects/foo1.f90 b/test cases/fortran/22 extract_objects/foo1.f90
new file mode 100644
diff --git a/test cases/fortran/22 extract_objects/foo2.f90 b/test cases/fortran/22 extract_objects/foo2.f90
new file mode 100644
diff --git a/test cases/fortran/22 extract_objects/meson.build b/test cases/fortran/22 extract_objects/meson.build
new file mode 100644
--- /dev/null
+++ b/test cases/fortran/22 extract_objects/meson.build	
@@ -0,0 +1,17 @@
+project('test_project', 'fortran')
+
+if get_option('unity') == 'on'
+  error('MESON_SKIP_TEST: extract_objects does not work in unity builds')
+endif
+
+libfoo = static_library(
+  'foo',
+  sources : ['foo1.f90', 'foo2.f90'])
+
+foo1_object = libfoo.extract_objects('foo1.f90')
+
+libfinal = library(
+  'final',
+  sources : 'bar.f90',
+  objects : foo1_object,
+)