forked from acp29/iboot
-
Notifications
You must be signed in to change notification settings - Fork 1
/
make.m
executable file
·143 lines (138 loc) · 5.43 KB
/
make.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
% Script to make select the appropriate precompiled binaries for installation or make the mex files from source
% Check if running in Octave (else assume Matlab)
info = ver;
isoctave = any (ismember ({info.Name}, 'Octave'));
% Initialise
errflag = false;
clear mexext
% Create cell array of paths to add
arch = computer ('arch');
[comp, maxsize, endian] = computer ();
try
switch endian
case 'L'
if isoctave
arch_idx = regexpi (arch, {'mingw32-i686', ...
'mingw32-x86_64', ...
'^darwin.*x86_64$', ...
'gnu-linux-x86_64'});
binary_paths = {'mex\octave\win\win32\', ...
'mex\octave\win\win64\', ...
'mex/octave/mac/maci64/', ...
'mex/octave/linux/glnxa64/'};
else
arch_idx = regexpi (arch, {'win32', ...
'win64', ...
'maci64', ...
'maca64', ...
'glnxa64'});
binary_paths = {'mex\matlab\win\win32\', ...
'mex\matlab\win\win64\', ...
'mex/matlab/mac/maci64/', ...
'mex/matlab/mac/maca64/', ...
'mex/matlab/linux/glnxa64/'};
end
if ( ~ all (cellfun (@isempty,arch_idx)))
retval = '0';
while ~ismember (retval,{'1','2',''})
retval = input (sprintf(['Potentially compatible precompiled mex files found. ', ...
'Please select an option:\n', ...
' 1) Use the precompiled mex files (default).\n', ...
' 2) Compile new mex files from source.\n', ...
'Answer (1 or 2): ']), 's');
end
if isempty(retval)
retval = '1';
end
if (strcmpi (retval,'1'))
copyfile (sprintf (repmat ('%s',1,3), binary_paths{~cellfun (@isempty, arch_idx)}, 'boot.', mexext),...
sprintf (repmat ('%s',1,6), '.', filesep, 'inst', filesep, 'boot.', mexext), 'f');
copyfile (sprintf (repmat ('%s',1,3), binary_paths{~cellfun (@isempty, arch_idx)}, 'smoothmedian.', mexext),...
sprintf (repmat ('%s',1,8), '.', filesep, 'inst', filesep, 'smoothmedian.', mexext), 'f');
% Perform basic tests
% If tests fail, try compiling source code instead
clear boot smoothmedian
cd inst
boot (1, 1);
smoothmedian (1);
binary = true;
cd ..
else
error ('Break from try-catch statement')
end
else
binary = false;
end
case 'B'
binary = false;
end
catch
binary = false;
if (~ exist ('./install.m', 'file'))
% In case test of binary fails, we need to go back to the root directory of
% the package
cd ..
end
end
% Attemt to compile binaries from source code automatically if no suitable binaries can be found
if binary
fprintf ('The following suitable binaries were detected and copied over to the inst directory: ');
fprintf ('\n%s%s%s%s%s', '.', filesep, binary_paths{~cellfun(@isempty,arch_idx)}, 'boot.', mexext);
fprintf ('\n%s%s%s%s%s', '.', filesep, binary_paths{~cellfun(@isempty,arch_idx)}, 'smoothmedian.', mexext);
else
disp ('Either you chose to compile from source, or no binaries are suitable.');
disp ('Attempting to compile the source code...');
if isoctave
try
mkoctfile -std=c++11 --mex --output ./inst/boot ./src/boot.cpp
catch
errflag = true;
err = lasterror();
disp (err.message);
warning ('Could not compile boot.%s. Falling back to the (slower) boot.m file.', mexext)
end
try
mkoctfile -std=c++11 --mex --output ./inst/smoothmedian ./src/smoothmedian.cpp
catch
errflag = true;
err = lasterror();
disp(err.message);
warning ('Could not compile smoothmedian.%s. Falling back to the (slower) smoothmedian.m file.', mexext)
end
else
try
mex -setup c++
catch
errflag = true;
err = lasterror ();
disp(err.message);
end
try
mex CXXFLAGS="$CXXFLAGS -std=c++11" -output ./inst/boot ./src/boot.cpp
catch
errflag = true;
err = lasterror ();
disp (err.message);
warning ('Could not compile boot.%s. Falling back to the (slower) boot.m file.', mexext)
end
try
mex CXXFLAGS="$CXXFLAGS -std=c++11" -output ./inst/smoothmedian ./src/smoothmedian.cpp
catch
errflag = true;
err = lasterror();
disp (err.message);
warning ('Could not compile smoothmedian.%s. Falling back to the (slower) smoothmedian.m file.', mexext)
end
end
end
if errflag
fprintf ('\nmake completed with errors. Please review the details in the errors in the above output. \n')
fprintf ('It is possible that a suitable c++ compiler is not installed or been configured properly. \n')
if (~ isoctave)
fprintf ('Try running ''mex -setup c++'' and following the instructions. \n')
end
fprintf ('If you now execute ''install'', .m files equivalent to the mex files will be used instead. \n')
else
fprintf ('\n''make'' completed successfully. \nPlease now run the ''install'' command if you haven''t done so already. \n')
end
clear arch arch_idx binary binary_paths comp endian info isoctave maxsize errflag retval