From f6d2525d15aa9d78edd0a6f8ffd8b64b46da08e7 Mon Sep 17 00:00:00 2001
From: Willi Mutschler <willi@mutschler.eu>
Date: Mon, 23 May 2022 10:22:57 +0200
Subject: [PATCH] :apple: provisions for Apple Silicon package

---
 src/ModelTree.cc | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/src/ModelTree.cc b/src/ModelTree.cc
index 66ba7f9c..8e6ad0ba 100644
--- a/src/ModelTree.cc
+++ b/src/ModelTree.cc
@@ -1784,13 +1784,15 @@ ModelTree::matlab_arch(const string &mexext)
     return "win32";
   else if (mexext == "mexw64")
     return "win64";
-  else if (mexext == "mexmaci")
+  else if (mexext == "mexmaci" || mexext == "mexmaca")
     {
       cerr << "32-bit MATLAB not supported on macOS" << endl;
       exit(EXIT_FAILURE);
     }
   else if (mexext == "mexmaci64")
     return "maci64";
+  else if (mexext == "mexmaca64")
+    return "maca64";
   else
     {
       cerr << "ERROR: 'mexext' option to preprocessor incorrectly set, needed with 'use_dll'" << endl;
@@ -1818,6 +1820,9 @@ ModelTree::findGccOnMacos()
   else if (string global_gcc_path = "/usr/local/bin/gcc-" + macos_gcc_version;
            filesystem::exists(global_gcc_path))
     return global_gcc_path;
+  else if (string global_gcc_path = "/opt/homebrew/bin/gcc-" + macos_gcc_version;
+           filesystem::exists(global_gcc_path))
+    return global_gcc_path;
   else
     {
       cerr << "ERROR: You must install gcc-" << macos_gcc_version
@@ -1900,7 +1905,7 @@ ModelTree::compileMEX(const string &basename, const string &funcname, const stri
             }
         }
 #ifdef __APPLE__
-      else if (mexext == "mexmaci64")
+      else if (mexext == "mexmaca64" || mexext == "mexmaci64")
         {
           compiler = findGccOnMacos();
           flags << " -fno-common -Wl,-twolevel_namespace -undefined error -bundle";
-- 
GitLab