diff --git a/Source/Modules/matlab.cxx b/Source/Modules/matlab.cxx index e9efae37d71..bc990464071 100644 --- a/Source/Modules/matlab.cxx +++ b/Source/Modules/matlab.cxx @@ -20,6 +20,7 @@ static const char *usage = (char *) "\ Matlab Options (available with -matlab)\n\ -opprefix - Prefix for global operator functions [default: 'op_']\n\ -pkgname - Prefix for package name ' [default: '']\n\ + -mexname - Specify mex function name ' [default: 'MEX']\n\ \n"; class MATLAB : public Language { @@ -276,6 +277,11 @@ int MATLAB::top(Node *n) { if (!pkg_name && Getattr(options, "package")) { pkg_name = Getattr(options, "package"); } + // Set mex name via module option if not set via command-line + // Otherwise use module name as default (see below) + if (!mex_name && Getattr(options, "mexname")) { + mex_name = Getattr(options, "mexname"); + } } } } @@ -731,10 +737,19 @@ int MATLAB::importDirective(Node *n) { String *modname = Getattr(n, "module"); if (modname) { - // Construct name of intermediary layer - // TODO: If option mexname set for module, use instead - String *import_mexname = Copy(modname); - Append(import_mexname, "MEX"); + // Find the module node for this imported module. It should be the + // first child but search just in case. + Node *mod = firstChild(n); + while (mod && Strcmp(nodeType(mod), "module") != 0) + mod = nextSibling(mod); + + // If option mexname set for module, use instead + Node *options = Getattr(mod, "options"); + String *import_mexname = options ? Getattr(options, "mexname") : 0; + if (import_mexname == 0) { + import_mexname = Copy(modname); + Append(import_mexname, "MEX"); + } /* Add to list of modules to be imported */ Append(l_modules, import_mexname);