-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathcompile.m
48 lines (39 loc) · 1.11 KB
/
compile.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
% Compile files only if needed
function compile(cpp_file, out_file, sources, extra_arguments)
% Process
my_name = mfilename('fullpath');
my_path = fileparts(my_name);
mex_file_name = [my_path filesep out_file '.' mexext];
cpp_file_name = [my_path filesep cpp_file];
mex_file = dir(mex_file_name);
cpp_file = dir(cpp_file_name);
if length(mex_file) == 1
mex_modified = mex_file.datenum;
else
mex_modified = 0;
end
cpp_modified = cpp_file.datenum;
% If modified or not existant compile
compile_file = false;
if ~exist(mex_file_name, 'file')
compile_file = true;
elseif mex_modified < cpp_modified
compile_file = true;
end
% Append current folder to sources
for i = 1 : length(sources);
include_folders{i} = ['-I' my_path filesep fileparts(sources{i}) filesep];
sources{i} = [my_path filesep sources{i}];
end
% Check all dependend files
for i = 1 : length(sources)
cpp_file = dir(sources{i});
cpp_modified = cpp_file.datenum;
if mex_modified < cpp_modified
compile_file = true;
end
end
if compile_file
mex(cpp_file_name,'-outdir',my_path, extra_arguments{:}, ...
include_folders{:}, sources{:});
end