-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmccdeploy.m
executable file
·97 lines (89 loc) · 2.19 KB
/
mccdeploy.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
%MCCDEPLOY Invoke MATLAB to C/C++ Compiler.
%
% MCCDEPLOY('fun','destination',{'file 1','file 2',...},'args')
%
% Prepare fun.m for deployment outside of the MATLAB environment.
% Generate wrapper files in C or C++ and build standalone binary files.
% The created application won't contain information of the MATLAB prefdir.
%
% Write any resulting files into the 'destination' directory.
%
% Add {'file 1','file 2',...} to the CTF archive. If the specified files are
% m, mex or p files, these functions will not be exported in the resulting
% target.
%
% The compilation search path will be cleared of all directories except the
% following core directories:
% <matlabroot>/toolbox/matlab
% <matlabroot>/toolbox/local
% <matlabroot>/toolbox/compiler
% It will also retains all subdirectories of the above list that appear on
% the MATLAB path at compile time.
%
% See also MCC.
% Created by Léa Strobino.
% Copyright 2017 hepia. All rights reserved.
function mccdeploy(file,dest,dependencies,args)
if nargin < 2 || isempty(dest)
dest = '.';
end
if nargin < 3
dependencies = {};
end
if nargin < 4
args = '';
end
% Copy all files
build = tempname();
mkdir(build);
try
copyfile(file,build);
for i = 1:length(dependencies)
copyfile(dependencies{i},build);
end
catch e
rmdir(build,'s');
rethrow(e);
end
[~,f,e] = fileparts(file);
file = [f e];
% Clear functions, startup & prefdir
clear functions %#ok<*CLFUNC>
f = inmem();
for i = 1:length(f)
if mislocked(f{i})
munlock(f{i});
end
end
clear functions
try %#ok<TRYNC>
startup = which('startup');
movefile(startup,[startup '_'],'f');
movefile(prefdir,[prefdir '_'],'f');
end
% mcc
wd = cd();
cd(build);
mccerror = [];
try
[~,~] = mkdir([wd '/' dest]);
eval(['mcc -v -e ' file ' -a . -d ''' wd '/' dest ''' -N ' args]);
catch e
mccerror = e;
end
% Delete temporary files
try %#ok<TRYNC>
[~] = rmdir(prefdir,'s');
movefile([startup '_'],startup,'f');
movefile([prefdir '_'],prefdir,'f');
end
cd(wd);
delete(...
[dest '/mccExcludedFiles.log'],...
[dest '/readme.txt'],...
[dest '/requiredMCRProducts.txt'],...
[dest '/run_*.sh']);
rmdir(build,'s');
if ~isempty(mccerror)
rethrow(mccerror);
end