]> rtime.felk.cvut.cz Git - jenkicar/rpp-simulink.git/blob - rpp/blocks/rpp_generate_lib.m
Make library generation script better usable by Makefile
[jenkicar/rpp-simulink.git] / rpp / blocks / rpp_generate_lib.m
1 % Copyright (C) 2013-2014 Czech Technical University in Prague
2 %
3 % Authors:
4 %     - Michal Horn <hornmich@fel.cvut.cz>
5 %
6 % This document contains proprietary information belonging to Czech
7 % Technical University in Prague. Passing on and copying of this
8 % document, and communication of its contents is not permitted
9 % without prior written authorization.
10 %
11 % File : rpp_generate_lib.m
12 % Abstract:
13 %     Generates library rpp_lib.slx for targets
14 %
15 % References:
16 %     http://www.mathworks.com/help/matlab/ref/mex.html
17 %     http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
18
19 function rpp_generate_lib(varargin)
20         d = fullfile(getpref('rpp', 'TargetRoot'), '..', 'blocks');
21         cd(d)
22         
23         if nargin > 1,
24                 resultLibName = 'rpp_lib';
25                 generate_lib(resultLibName, varargin{1}, varargin);
26         else
27                 error('Not enough arguments for the function.');
28         end
29 end
30
31 function generate_lib(resultLibName, target, blocks)
32         disp(['Generating library for target: ', target]);
33         libFilePath=[target, '/', resultLibName, '.slx'];
34         load_system(libFilePath);
35         set_param(resultLibName, 'Lock', 'off');
36         oldBlocks = find_system(resultLibName, 'Type', 'block');
37         disp('Removing old blocks:');
38         for j=1:length(oldBlocks),
39                 disp(['    ', oldBlocks{j}]);
40                 delete_block(oldBlocks{j});
41         end
42         disp('Adding new blocks:');
43         for j=2:length(blocks),
44                 blockFilePath=[blocks{j}, '.slx'];
45                 disp(['    from: ', blockFilePath, ':']);
46                 load_system(blockFilePath)
47                 newBlocks = find_system(blocks{j}, 'Type', 'block');
48                 for k=1:length(newBlocks),
49                         [tok, blockName] = strtok(newBlocks{k}, '/');
50                         blockName = [resultLibName, blockName];
51                         disp(['        ', newBlocks{k}, ' as ', blockName]);
52                         add_block(newBlocks{k}, blockName);
53                 end
54                 close_system(blockFilePath, 0);
55         end
56         disp(['Closing and saving file ', libFilePath]);
57         set_param(resultLibName, 'Lock', 'on');
58         close_system(libFilePath, 1);
59 end