1

In the first phase of testing my code has to run in a Matlab Simulink environment (2010b 32bits) compiled as S-function. The compiler is the one that comes with Visual Studio 2010.

I currently have a script that compiles my code that looks like this:

mex -c -v foo_main.c
mex -c -v foo_1.c
mex -c -v foo_2.c
% etc...


mex -v foo_wrapper.c foo_main.obj foo_1.obj foo_2.obj % etc...

During the years the number of files has greatly increased, to the extent that compilation takes quite some time.

My question is: does it exists a method to check if an *.obj does not correspond to its *.c counterpart and recompile it only when necessary?

I am wary of creating special scripts because I would have to change them on a case-by-case basis and I see this as a road prone to errors and unnecessary risks.


EDIT:

My current solution is to take the date property of the files and compare them:

c_file = dir(fullfile(pwd,'\\foo.c'));
obj_file = dir(fullfile(pwd,'\\foo.obj'));

if (datenum(c_file.date) > datenum(obj_file.date))
    mex -c -v foo.c
end

I understand that this is not the cleanest solution and, in the comments, m.s. suggests to use a nmake file. I never created one and I do not know how to use it from a Matlab script.

Can it be done? Which steps should I follow to create and use it?

Community
  • 1
  • 1
Federico
  • 1,092
  • 3
  • 16
  • 36
  • how about using a [makefile with patterns](http://stackoverflow.com/a/1633553/678093)? – m.s. May 19 '15 at 13:38
  • @m.s. should do fine, as I already use a special `mexopts.bat` (I understand that you are proposing to change this file, correct?). – Federico May 19 '15 at 13:41
  • Well, I propose to use GNU make or similiar which can be used to automatically determine if a certain obj file is "outdated" and needs to be recompiled. – m.s. May 19 '15 at 13:48
  • @m.s. that I am not sure I can do, I have to compile through VS2010. – Federico May 19 '15 at 13:50
  • 1
    looks like Microsoft `nmake` can do similiar things: http://www.mathworks.com/matlabcentral/answers/5006-makefile-for-mex#comment_10280 – m.s. May 19 '15 at 13:59
  • @m.s. that looks promising! any chances you could write a full answer? – Federico May 19 '15 at 14:04
  • Sorry, I don't know `nmake`, you might want to update your question, add the `nmake` tag and hope for someone with specific knowledge to answer your question. – m.s. May 19 '15 at 14:13

0 Answers0