Writing platform- and version- portable Makefiles for MEX compilation

3 views (last 30 days)
Short version: I am looking for suggestions on how to set up and maintain Makefile-driven MEX compilation process. It should be portable across unix-like shell interfaces and across a range of Matlab releases, starting with R2012, but continuing beyond R2014a which introduced substantial changes in command line MEX configuration files and shell mex command syntax and interface.
Long version: I am one of maintainers of a MATLAB toolbox ( braidlab ) which contains a substantial amount of MEX functions that act as interfaces to various C and C++ libraries, distributed with the code, as well as original C++ code which is then made available to Matlab via MEX interface.
Our users run Linux, and Mac OS X (and potentially Windows) Matlab, with releases ranging from R2014a back to R2012b (as far as we can tell). Compiling of MEX files is currently performed by a host of Makefile scripts that determine user's compiler parameters by running "mex -v" (as it worked on R2013 versions, or legacy-mode R2014a), which outputs compiler and linker parameters that are parsed out and then used to compile the included libraries, in order to make sure they interface well with the compiler and (standard) libraries versions that user's Matlab supports.
Since R2014a came out, it became clear that Mathworks is moving towards XML-based configuration of the compiler, instead of mexopts.sh based configuration, with shell mex command changing as well (e.g., see discussion ). At this point, R2014a allows for mexopts.sh to be used, which puts it into 2013b-like legacy mode, but this seems to be on its way out. Even so, we cannot force our users to use the legacy mode, but we are not sure how to extract the same information as "mex -v" gets us in the new XML-style mode.
I am asking for suggestions and/or best-practices on how to re-design the Makefile-driven generation of MEX files, in a fashion portable between pre-R2014a and R2014a+ versions, and across platforms. Things we would like to know inside Makefile:
  • numeric Matlab version, like one output by "ver" inside Matlab, but without starting the engine
  • compiler and linker commands that Matlab has currently configured to use in MEX process
  • flags, includes, libraries, etc. used by MEX process
If you are interested, here is a current Makefile example.

Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!