Henry,
This option to build Matlab bindings is pretty rarely used. You're out in the wild west here.
I thought there were some instructions on this, but I can't even find those now.
You have to start with a fork of the Swig project modified to work with Matlab. I believe this project hasn't been touched since about 2016.
My gut says that MathWorks changed something from the time this stuff was put together and today. The Swig bindings are expecting 'mexFunction' to be defined a certain way -- but today it is in fact defined differently.
The main Swig project is never going to include the Matlab modifications because they don't have free licenses to use on automated build servers to build, test, and package every new release of Swig. Without continuous integration capabilities, maintaining and developing Swig (with a ton of abandoned bindings) is untenable. A few years back, the Swig devs went through and culled a bunch of bindings that were no longer active.
So, I would look into the swig/Matlab community -- see if anyone has updates to Matlab 2021. Or, I would see if I could go back to an old version of Matlab -- perhaps you can find access to Matlab 2016 and see if it can build there.
Otherwise, I'm not sure what to tell you. I have never actually done this myself. I don't know that anyone who has is still around.
Rob