-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathGenerateMyMex.m
96 lines (87 loc) · 3.22 KB
/
GenerateMyMex.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
function GenerateMyMex(include_fftw)
if(nargin < 1)
include_fftw = false;
end
GROPTCBase=pwd;
fprintf('Generate MyMex.m file...\n',GROPTCBase);
onestringpath = genpath(GROPTCBase);
if(length(strfind(onestringpath, ';')) > 0)
paths = mystrsplit(onestringpath, ';');
elseif(length(strfind(onestringpath, ':')) > 0)
paths = mystrsplit(onestringpath, ':');
end
paths = paths(~cellfun('isempty', paths));
if(length(strfind(GROPTCBase, '\')) > 0)
separate = '\';
else
separate = '/';
end
for i = 1 : length(paths)
% paths{i} = strrep(paths{i}, pwd, '.');
paths{i} = [paths{i} separate];
end
fid = fopen([pwd separate 'MyMex.m'], 'wt');
fprintf(fid, 'function MyMex(filename)\n');
fprintf(fid, 'addpath(genpath(pwd));\n');
fprintf(fid, 'if(nargin == 0)\n');
fprintf(fid, '\tfilename = ''TestStieBrockett'';\n');
fprintf(fid, 'end\n');
fprintf(fid, 'mex(''-R2018a'', ');
for i = 1 : length(paths)
path = ['-I' paths{i}];
fprintf(fid, '''%s'', ...\n', ['-I' paths{i}]);
end
str = ['[''.' separate 'test' separate ''' filename ''.cpp''], ...'];
fprintf(fid, ['%s\n'], str);
for i = 1 : length(paths)
if(isempty(findstr(paths{i}, [separate 'test' separate])))
allcpps = dir(fullfile(paths{i}, '*.cpp'));
for j = 1 : length(allcpps)
fprintf(fid, ['''%s' allcpps(j).name ''', '], paths{i});
end
if(length(allcpps) ~= 0)
fprintf(fid, '...\n');
end
end
end
if(length(findstr(lower(computer('arch')), 'mac')) > 0)
blaslib = '''-lmwblas''';
lapacklib = '''-lmwlapack''';
fftwlib = '''-lfftw3''';
end
if(length(findstr(lower(computer('arch')), 'lnx')) > 0)
blaslib = '''-lmwblas''';
lapacklib = '''-lmwlapack''';
fftwlib = '''-lfftw3''';
end
if(length(findstr(lower(computer('arch')), 'win')) > 0)
blaslib = ['''', fullfile(matlabroot,'extern','lib',computer('arch'),'microsoft','libmwblas.lib'), ''''];
lapacklib = ['''', fullfile(matlabroot,'extern','lib',computer('arch'),'microsoft','libmwlapack.lib'), ''''];
fftwlib = ['''-L.\BinaryFiles\'', ''-llibfftw3-3'', ''-llibfftw3f-3'', ''-llibfftw3l-3'''];
end
if(~include_fftw)
%''-largeArrayDims'',
str = ['[''-D'' upper(filename)], ', blaslib, ', ', lapacklib, ', ''-output'', [''.' separate 'BinaryFiles' separate ''' filename ]);'];
else
%, ''-largeArrayDims''
str = ['[''-D'' upper(filename)], ', '''-DROPTLIB_WITH_FFTW'', ', fftwlib, ', ', blaslib, ', ', lapacklib, ', ''-output'', [''.' separate 'BinaryFiles' separate ''' filename ]);'];
end
fprintf(fid, ['%s\n'], str);
fprintf(fid, 'end');
fclose(fid);
end
%% this function is for old matlab which does not have "strsplit".
function output = mystrsplit(str, flag)
s = 1;
idx = 1;
for i = 1 : length(str)
if(str(i) == flag)
output{idx} = str(s : i - 1);
idx = idx + 1;
s = i + 1;
end
end
if(s <= length(str))
output{idx} = str(s : end);
end
end