From a8ecac3ff8ba05bf76a0abf99be92db84dd6f13b Mon Sep 17 00:00:00 2001
From: Sergey Fedorov <barracuda@macos-powerpc.org>
Date: Sun, 10 Nov 2024 15:55:00 +0800
Subject: [PATCH] Use legacysupport manually for strnlen

---
 scipy/io/meson.build                          |  6 +++++-
 scipy/optimize/meson.build                    | 12 ++++++++++--
 scipy/sparse/linalg/_eigen/arpack/meson.build |  6 +++++-
 scipy/sparse/linalg/_propack/meson.build      |  6 +++++-
 4 files changed, 25 insertions(+), 5 deletions(-)

diff --git scipy/io/meson.build scipy/io/meson.build
index 60f71c696..bbe5c0159 100644
--- scipy/io/meson.build
+++ scipy/io/meson.build
@@ -4,8 +4,12 @@ py3.extension_module('_test_fortran',
     '_test_fortran.f'
   ],
   c_args: [Wno_unused_variable],
+  include_directories: ['@PREFIX@/include/LegacySupport'],
   fortran_args: fortran_ignore_warnings,
-  link_args: version_link_args,
+  link_args: [
+    version_link_args,
+    '-Wl,-lMacportsLegacySupport'
+  ],
   dependencies: [lapack_dep, fortranobject_dep],
   install: true,
   link_language: 'fortran',
diff --git scipy/optimize/meson.build scipy/optimize/meson.build
index d6c20d3d5..9e682eca1 100644
--- scipy/optimize/meson.build
+++ scipy/optimize/meson.build
@@ -134,7 +138,11 @@ py3.extension_module('_cobyla',
 py3.extension_module('_minpack2',
   [f2py_gen.process('minpack2/minpack2.pyf'), 'minpack2/dcsrch.f', 'minpack2/dcstep.f'],
   fortran_args: fortran_ignore_warnings,
-  link_args: version_link_args,
+  include_directories: ['@PREFIX@/include/LegacySupport'],
+  link_args: [
+    version_link_args,
+    '-Wl,-lMacportsLegacySupport'
+  ],
   dependencies: [fortranobject_dep],
   override_options: ['b_lto=false'],
   install: true,
diff --git scipy/sparse/linalg/_eigen/arpack/meson.build scipy/sparse/linalg/_eigen/arpack/meson.build
index 08a7b83d1..6fc610e5c 100644
--- scipy/sparse/linalg/_eigen/arpack/meson.build
+++ scipy/sparse/linalg/_eigen/arpack/meson.build
@@ -102,7 +102,11 @@ arpack_module = custom_target('arpack_module',
 _arpack = py3.extension_module('_arpack',
   arpack_module,
   link_with: arpack_lib,
-  link_args: version_link_args,
+  link_args: [
+    version_link_args,
+    '-Wl,-lMacportsLegacySupport'
+  ],
+  include_directories: ['@PREFIX@/include/LegacySupport'],
   dependencies: [lapack_dep, blas_dep, fortranobject_dep],
   install: true,
   link_language: 'fortran',
diff --git scipy/sparse/linalg/_propack/meson.build scipy/sparse/linalg/_propack/meson.build
index 671472495..9e42b48de 100644
--- scipy/sparse/linalg/_propack/meson.build
+++ scipy/sparse/linalg/_propack/meson.build
@@ -101,9 +101,13 @@ foreach ele: elements
     f2py_gen.process(ele[2]),
     link_with: propack_lib,
     c_args: ['-U_OPENMP', _cpp_Wno_cpp],
+    include_directories: ['@PREFIX@/include/LegacySupport'],
     fortran_args: _fflag_Wno_maybe_uninitialized,
     dependencies: [lapack_dep, blas_dep, fortranobject_dep],
-    link_args: version_link_args,
+    link_args: [
+      version_link_args,
+      '-Wl,-lMacportsLegacySupport'
+    ],
     install: true,
     link_language: 'fortran',
     subdir: 'scipy/sparse/linalg/_propack'
