-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathspm_make_standalone_local.m
124 lines (113 loc) · 4.09 KB
/
spm_make_standalone_local.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
function spm_make_standalone_local( ...
spmdir, ...
outdir, ...
extradir ...
)
% Compile SPM as a standalone executable using the MATLAB compiler
% http://www.mathworks.com/products/compiler/
%
% This will generate a standalone application, which can be run outside
% MATLAB, and therefore does not require a MATLAB licence.
%
% On Windows:
% spm12.exe <modality>
% spm12.exe run <batch.m(at)>
%
% On Linux/Mac:
% ./run_spm12.sh <MCRroot> <modality>
% ./run_spm12.sh <MCRroot> run <batch.m(at)>
%
% The first command starts SPM in interactive mode with GUI. The second
% executes a batch file or starts the Batch Editor if none is provided.
%
% Full list of options is accessible from:
% ./run_spm12.sh <MCRroot> --help
%
% When deployed, compiled applications will require the MATLAB Runtime:
% http://www.mathworks.com/products/compiler/mcr/
%
% See spm_standalone.m
%__________________________________________________________________________
% Copyright (C) 2010-2017 Wellcome Trust Centre for Neuroimaging
% Guillaume Flandin
% $Id: spm_make_standalone.m 7483 2018-11-12 13:19:31Z guillaume $
%-Check startup.m
%--------------------------------------------------------------------------
if exist('startup','file')
warning('A startup.m has been detected in %s.\n',...
fileparts(which('startup')));
end
%-Input arguments
%--------------------------------------------------------------------------
% We need SPM in the path, and also need to trigger it's auto-add of config
% paths
addpath(spmdir);
spm_jobman('initcfg');
if ~exist(outdir,'dir'), mkdir(outdir); end
gateway = 'spm_standalone.m';
contentsver = '';
%==========================================================================
%-Static listing of SPM toolboxes
%==========================================================================
fid = fopen(fullfile(spm('Dir'),'config','spm_cfg_static_tools.m'),'wt');
fprintf(fid,'function values = spm_cfg_static_tools\n');
fprintf(fid,...
'%% Static listing of all batch configuration files in the SPM toolbox folder\n');
%-Get the list of toolbox directories
tbxdir = fullfile(spm('Dir'),'toolbox');
d = [tbxdir; cellstr(spm_select('FPList',tbxdir,'dir'))];
ft = {};
%-Look for '*_cfg_*.m' files in these directories
for i=1:numel(d)
fi = spm_select('List',d{i},'.*_cfg_.*\.m$');
if ~isempty(fi)
ft = [ft(:); cellstr(fi)];
end
end
%-Create code to insert toolbox config
if isempty(ft)
ftstr = '';
else
ft = spm_file(ft,'basename');
ftstr = sprintf('%s ', ft{:});
end
fprintf(fid,'values = {%s};\n', ftstr);
fclose(fid);
%==========================================================================
%-Static listing of batch application initialisation files
%==========================================================================
cfg_util('dumpcfg');
%==========================================================================
%-Duplicate Contents.m in Contents.txt for use in spm('Ver')
%==========================================================================
sts = copyfile(fullfile(spm('Dir'),'Contents.m'),...
fullfile(spm('Dir'),'Contents.txt'));
if ~sts, warning('Copy of Contents.m failed.'); end
if ~isempty(contentsver)
% Format: 'xxxx (SPMx) dd-mmm-yyyy'
f = fileread(fullfile(spm('Dir'),'Contents.txt'));
f = regexprep(f,'% Version \S+ \S+ \S+',['% Version ' contentsver]);
fid = fopen(fullfile(spm('Dir'),'Contents.txt'),'w');
fprintf(fid,'%s',f);
fclose(fid);
end
%==========================================================================
%-Compilation
%==========================================================================
Nopts1 = {'-p',fullfile(matlabroot,'toolbox','signal')};
Nopts2 = {'-p',fullfile(matlabroot,'toolbox','stats')};
Nopts3 = {'-p',fullfile(matlabroot,'toolbox','images')};
Ropts = {'-R','-singleCompThread'} ;
if spm_check_version('matlab','8.4') >= 0
Ropts = [Ropts, {'-R','-softwareopengl'}];
end
mcc('-m', '-C', '-v',...
'-o',lower(spm('Ver')),...
'-d',outdir,...
'-N',Nopts1{:},...
'-N',Nopts2{:},...
'-N',Nopts3{:},...
Ropts{:},...
'-a',spm('Dir'),...
'-a',extradir,...
gateway);