1 % Copyright (C) 2013-2014 Czech Technical University in Prague
4 % - Michal Horn <hornmich@fel.cvut.cz>
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.
11 % File : rpp_generate_lib.m
13 % Generates library rpp_lib.slx for targets
16 % http://www.mathworks.com/help/matlab/ref/mex.html
17 % http://www.mathworks.com/help/matlab/matlab_external/custom-building-mex-files.html
19 function rpp_generate_lib(varargin)
20 d = fullfile(getpref('rpp', 'TargetRoot'), '..', 'blocks');
24 resultLibName = 'rpp_lib';
25 generate_lib(resultLibName, varargin{1}, varargin);
27 error('Not enough arguments for the function.');
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});
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);
54 close_system(blockFilePath, 0);
56 disp(['Closing and saving file ', libFilePath]);
57 set_param(resultLibName, 'Lock', 'on');
58 close_system(libFilePath, 1);