comparison m-toolbox/makeToolbox.m @ 0:f0afece42f48

Import.
author Daniele Nicolodi <nicolodi@science.unitn.it>
date Wed, 23 Nov 2011 19:22:13 +0100
parents
children e22b091498e4
comparison
equal deleted inserted replaced
-1:000000000000 0:f0afece42f48
1 % MAKETOOLBOX Create the toolbox 'ltpda'.
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 %
4 % DESCRIPTION: MAKETOOLBOX Create the toolbox 'ltpda'.
5 % This script will package together all files into a toolbox that
6 % can be distributed for various OS's.
7 %
8 % CALL: makeToolbox
9 %
10 % VERSION: $Id: makeToolbox.m,v 1.182 2011/05/18 06:48:07 hewitson Exp $
11 %
12 % HISTORY: 30-01-07 M Hewitson
13 % Creation
14 %
15 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
16
17 function varargout = makeToolbox(varargin)
18
19 %% Some clearing
20
21 % remove the user preferences
22 setappdata(0, 'LTPDApreferences', '');
23 % now clear everything
24 evalin('base', 'clear');
25
26 %% Settings
27
28 % install toolbox to this directory
29 if nargin == 1
30 rootdir = varargin{1};
31 else
32 rootdir = '/Users/hewitson/working/matlab';
33 end
34
35 % compile options
36 closedSource = 0; % 1 => compile all .m files to .p files
37 read_only = 0; % Make all installed files read-only? (except ltpda_startup.m)
38
39 % copy the help files to the installed toolbox
40 install_help = true;
41 % install the examples and tests
42 install_examples = true;
43
44 % Run the python script to build the html help
45 build_help = false;
46 % build the documentation search database
47 build_doc_search = false;
48 % build the page of functions by category,
49 build_functions_by_category = false;
50
51 % rebuild workbench library
52 rebuild_workbench_library = false;
53
54 % set version for the Contents.m and for packaging
55 ltpda_ver = '2.4.dev';
56
57 %% ------------------------------------------------------------------------
58 % -------------------------------------------------------------------------
59 % -------------------------------------------------------------------------
60 % -------------------------------------------------------------------------
61 % Should not need to edit below here
62 % -------------------------------------------------------------------------
63 % -------------------------------------------------------------------------
64 % -------------------------------------------------------------------------
65 % -------------------------------------------------------------------------
66
67 mpipelineSrc = 'MPipeline2';
68 makeDoc = 0; % make html doc for all m files using m2html, ref: http://www.artefact.tk/software/matlab/m2html/
69
70 % build version string
71 mver = ver('MATLAB');
72 ltpda_version = sprintf('%s %s %s', ltpda_ver, mver.Release, datestr(now, 'dd-mm-yy'));
73
74 % build OS target directory
75 toolboxRoot = fullfile(rootdir, 'ltpda_toolbox');
76
77 % remove toolbox from matlab path
78 rmpath(genpath(toolboxRoot));
79 savepath;
80 rehash toolboxcache;
81
82 % delete old toolbox
83 if exist(toolboxRoot, 'dir')
84 rmdir(toolboxRoot, 's');
85 end
86
87 % create toolbox root
88 mkdir(toolboxRoot);
89
90 % create toolbox dir
91 toolboxDir = fullfile(rootdir, sprintf('ltpda_toolbox'), 'ltpda');
92 mkdir(toolboxDir);
93
94 %% Install latest jar files
95
96 % MPipeline
97 copyfile(fullfile('..', 'src', mpipelineSrc, 'dist', [mpipelineSrc '.jar']), fullfile('jar', 'MPipeline.jar'));
98 ddir = fullfile('jar', 'lib');
99 if ~exist(ddir, 'dir')
100 mkdir(ddir);
101 end
102 copyfile(fullfile('..','src',mpipelineSrc,'dist','lib'), ddir, 'f');
103
104 % login dialog
105 copyfile(fullfile('..', 'src', 'LoginDialog', 'dist', 'LoginDialog.jar'), fullfile('jar', 'LoginDialog.jar'));
106
107 mkdir(toolboxDir, 'jar');
108 jars = dir('jar');
109 for c = 1:numel(jars)
110 s = jars(c);
111 [path, name, ext] = fileparts(s.name);
112 if strcmp(ext, '.jar')
113 copyfile(fullfile('jar', s.name), fullfile(toolboxDir, 'jar'), 'f');
114 end
115 end
116
117 % Also the lib dir for MPipeline
118 mkdir(toolboxDir, fullfile('jar', 'lib'));
119 copyfile(fullfile('jar', 'lib'), fullfile(toolboxDir, 'jar', 'lib'), 'f');
120
121 %% copy m files
122
123 srcs = {'m/etc/', ...
124 'm/gui', ...
125 'm/helper', ...
126 'm/sigproc',...
127 'm/built_in_models'};
128
129 mkdir(toolboxDir, 'm');
130
131 for s=srcs
132 copyfile(char(s), fullfile(toolboxDir, char(s)), 'f');
133 end
134
135 % Copy some other files
136 copyfile('m/MakeContents.m', toolboxDir, 'f');
137
138 %% install classes
139
140 classes = {'ltpda_obj', 'ltpda_nuo', 'ltpda_uo', 'ltpda_uoh', ...
141 'minfo', 'unit', ...
142 'pz', 'pzmodel', 'rational', 'parfrac',...
143 'ltpda_tf', 'ltpda_filter', 'miir', 'mfir', 'filterbank', ...
144 'ltpda_data', 'data2D', 'data3D', 'tsdata', 'cdata', 'xydata', 'fsdata', 'xyzdata', ...
145 'provenance', 'history', 'param', 'paramValue', 'plist',...
146 'ao', 'specwin', 'time', 'timespan',...
147 'pest', ...
148 'ssm', 'ssmport', 'ssmblock', ...
149 'smodel', 'msym', ...
150 'sigBuilder', 'constructor', 'specwinViewer', ...
151 'LTPDAprefs', 'LTPDAworkbench', 'LTPDARepositoryManager', 'workspaceBrowser', ...
152 'LTPDAModelBrowser', ...
153 'matrix', 'collection', ...
154 };
155
156 % 'LTPDAHelper'
157 % 'stattest', ...
158 % 'plotter', 'plotterFactory', ...
159 % 'aoplotter', 'tsplotter' ...
160
161 for c = classes
162 cdir = fullfile('classes', sprintf('@%s', char(c)));
163 mkdir(toolboxDir, cdir);
164 copyfile(cdir, fullfile(toolboxDir, cdir), 'f');
165 end
166
167 %% install unit tests
168
169 cdir = fullfile('classes', 'tests');
170 mkdir(toolboxDir, cdir);
171 copyfile(cdir, fullfile(toolboxDir, cdir), 'f');
172
173
174 %% install packages
175
176 pkgs = { 'utils'};
177 for c = pkgs
178 cdir = fullfile('classes', sprintf('+%s', char(c)));
179 mkdir(toolboxDir, cdir);
180 copyfile(cdir, fullfile(toolboxDir, cdir), 'f');
181 end
182
183 %% Install mex src files
184
185 srcs = {'c_sources', 'ltpda_dft', 'ltpda_smoother', 'ltpda_polyreg', 'ltpda_ssmsim'};
186 for c = srcs
187 cdir = fullfile('src', char(c));
188 mkdir(toolboxDir, cdir);
189 copyfile(fullfile('../', cdir), fullfile(toolboxDir, cdir), 'f');
190 end
191 % Copy compileAll.m
192 copyfile('../src/compileAll.m', fullfile(toolboxDir, 'src'), 'f')
193 copyfile('../src/vcredist_x86.exe', fullfile(toolboxDir, 'src'), 'f')
194 copyfile('../src/vcredist_x64.exe', fullfile(toolboxDir, 'src'), 'f')
195
196
197 %% Now build examples directory in toolbox
198
199 if install_examples
200 % load list of tests to install
201 run 'test/test_list.m';
202
203 mkdir(toolboxDir, 'examples');
204 installPoint = fullfile(toolboxDir, 'examples');
205 for f = 1:length(test_struct)
206 if test_struct(f).example
207 disp(sprintf(' - installing %s', test_struct(f).name));
208 copyfile(fullfile('test', [test_struct(f).name '.m']), installPoint);
209 end
210 end
211
212 % Some additional files
213 copyfile(fullfile('test', 'test_list.m'), installPoint);
214 copyfile(fullfile('test', 'run_tests.m'), installPoint);
215 copyfile(fullfile('test', 'make_test_ascii_file.m'), installPoint);
216
217 mkdir(installPoint, 'pipelines');
218 copyfile(fullfile('test', 'pipelines'), fullfile(installPoint, 'pipelines'), 'f');
219 end
220
221 %% Clean up
222 % Remove recursive the CVS directories in toolboxDir
223 rm_cvs_dir(toolboxRoot, 'CVS');
224 rm_cvs_dir(toolboxRoot, '*.m~');
225 rm_cvs_dir(toolboxRoot, '.#ltpda*');
226
227 % add toolbox to matlab path
228 addpath(genpath(toolboxRoot));
229
230 %% Now build Contents.m files and documentation
231
232 cdir = pwd;
233 cd(toolboxDir);
234 MakeContents('LTPDA', ltpda_version);
235 cd(cdir);
236
237 if makeDoc
238 % Build doc list
239 docs = [];
240 for jj = 1:length(classes)
241 docs = [docs cellstr(['classes/@' classes{jj}])];
242 end
243 for jj = 1:length(srcs)
244 if ~strcmp(srcs{j}, 'mex')
245 docs = [docs cellstr(srcs{jj})];
246 end
247 end
248
249 % build documentation
250 m2html('mfiles', docs,...
251 'htmldir', 'html_help/help/ug',...
252 'recursive', 'on',...
253 'template', 'docstyle',...
254 'indexFile', 'mindex');
255 end
256
257 if build_help
258 % Make on-line html TOC
259 cd html_help/help
260 convertTOC
261 % try to generate html codes
262 try
263 [temp pythonVer] = system('python -V');
264 pythonVer = strtok(pythonVer,'Python ');
265 if numel(pythonVer)>3, pythonVer(4:end)=[]; end
266 pythonVer = str2double(pythonVer);
267 if isnan(pythonVer)
268 error('*** Failed check of Python version');
269 elseif pythonVer > 2.6
270 !python ./mkhelpfiles_v3.py -i helptoc.xml
271 else
272 !python ./mkhelpfiles.py -i helptoc.xml
273 end
274 catch ME
275 warning('!!! Couldn''t run mkhelpfiles.py. Do you have python installed?');
276 end
277 cd(cdir)
278
279 end
280
281 % Now copy the help files
282 if install_help
283 status = copyfile('html_help/help', fullfile(toolboxDir,'help'), 'f')
284 copyfile('html_help/info.xml', toolboxDir, 'f');
285 addpath(fullfile(toolboxDir, 'help', 'ug'));
286 delete(fullfile(toolboxDir,'help','ug', '*_content.html'))
287 end
288
289 % Now build search index
290 if build_doc_search
291 builddocsearchdb(fullfile(toolboxDir, 'help'))
292 end
293
294 % Now everything is copied so we can save the path.
295 savepath;
296 rehash toolboxcache;
297
298
299 %% Build functions by category
300 if build_functions_by_category
301 disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
302 disp('%% running mk_functions_by_category %%');
303 disp('%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%');
304 mk_functions_by_category;
305 end
306
307 %% Make all files read-only
308 if read_only
309 files = mtfilescan(toolboxRoot);
310 for jj = 1:length(files)
311 fi = files{jj};
312 [path,name,ext] = fileparts(fi);
313 if ~strcmp(name, 'ltpda_startup')
314 if ispc
315 [success, message, messageid] = fileattrib(fi, '-w');
316 else
317 [success, message, messageid] = fileattrib(fi, '-w', 'a');
318 end
319 if ~success
320 warning('!!! Failed to set attributes for %s', fi);
321 end
322 end
323 end
324 end
325
326 %% Now compile all .m files and remove if necessary
327 if closedSource
328 mfiles = mtfilescan(toolboxDir, '.m');
329 for ii = 1:length(mfiles)
330 f = char(mfiles(ii));
331 pcode(f, '-inplace');
332 writeHelpMfile(f)
333 end
334 end
335
336 %% Now clean up
337
338 % Remove recursive the CVS directories in toolboxDir
339 rm_cvs_dir(toolboxRoot, 'CVS');
340 rm_cvs_dir(toolboxRoot, '*.m~');
341 rm_cvs_dir(toolboxRoot, '.#ltpda*');
342
343 rehash;
344 rehash toolboxcache;
345 ltpda_startup;
346
347 if rebuild_workbench_library
348 lib = LTPDAworkbench.rebuildLibrary;
349 save(fullfile(toolboxRoot, 'ltpda', 'classes', '@LTPDAworkbench', 'lib.mat'), 'lib')
350 end
351
352 end
353
354
355 function writeHelpMfile(mfile)
356 % This replaces an m-file with another m-file that contains only the help
357 % of the original one
358
359
360 % get the help
361 [pathstr,name,ext] = fileparts(mfile);
362 h = help(name);
363 disp(sprintf('** Writing help m-file for %s', name));
364
365 fd = fopen(mfile, 'w+');
366 fprintf(fd, '%s', h);
367 fclose(fd);
368 end
369
370 function files = mtfilescan(root_dir, ext)
371 % Recursively scans the given directory for files that end in
372 % 'ext' and returns a list of the full paths.
373
374 if nargin < 2
375 ext = '';
376 end
377
378 files = getfiles(root_dir, ext, []);
379 end
380
381
382 function ofiles = getfiles(root_dir, iext, ofiles)
383 % Recursive function for getting file lists
384
385 files = dir(root_dir);
386
387 for jj = 1:length(files)
388 f = files(jj);
389 if f.isdir
390 if ~strcmp(f.name,'.') && ~strcmp(f.name,'..')
391 ofiles = getfiles([root_dir '/' f.name], iext, ofiles);
392 end
393 else
394 [pathstr,name,ext] = fileparts(f.name);
395 if ~isempty(iext)
396 if any(strcmp(ext, iext))
397 ofiles = [ofiles; cellstr([root_dir '/' f.name])];
398 end
399 else
400 ofiles = [ofiles; cellstr([root_dir '/' f.name])];
401 end
402 end
403 end
404 end
405
406 % END