]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blob - rpp/rpp/rpp_setup.m
rpp_setup: Allow non-interactive execution
[pes-rpp/rpp-simulink.git] / rpp / rpp / rpp_setup.m
1 % Copyright (C) 2013 Czech Technical University in Prague
2 %
3 % Authors:
4 %     - Carlos Jenkins <carlos@jenkins.co.cr>
5 %
6 % This program is free software; you can redistribute it and/or modify
7 % it under the terms of the GNU General Public License as published by
8 % the Free Software Foundation; either version 2 of the License, or
9 % (at your option) any later version.
10 %
11 % This program is distributed in the hope that it will be useful,
12 % but WITHOUT ANY WARRANTY; without even the implied warranty of
13 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 % GNU General Public License for more details.
15 %
16 % You should have received a copy of the GNU General Public License
17 % along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 %
19 % File : rpp_setup.m
20 % Abstract:
21 %     RPP Target install script.
22 %
23 %     IMPORTANT: This script _MUST_ be run by user after extracting the target
24 %                package and before using the target. To execute:
25 %
26 %         1. Start Matlab.
27 %         2. Change directory (cd) to this file folder.
28 %         3. Execute rpp_setup() on command window.
29 %
30 % References:
31 %     rtw_ug.pdf p. 1137
32
33
34 function rpp_setup(varargin)
35
36     % Get current target path in user's filesystem
37     currentPath = pwd();
38     targetPath = currentPath(1:end-length('/rpp'));
39
40     % Add target system folders to Matlab path
41     addpath(fullfile(targetPath, 'rpp'));
42     addpath(fullfile(targetPath, 'demos'));
43     addpath(fullfile(targetPath, 'blocks'));
44     %addpath(fullfile(targetPath, 'help'));
45     savepath();
46
47     if nargin == 0,
48         % Ask user setup variables
49         possiblePath = '/usr/local/ti/ccsv5/tools/compiler/arm_5.0.1';
50
51         CompilerRoot = fix_slash(uigetdir(possiblePath, ...
52                                           ['CCS Compiler root ' ...
53                             'directory: (<ccs_root>/tools/compiler/arm_5.X.X)']));
54     else
55         CompilerRoot = fix_slash(varargin{1});
56     end
57     CCSRoot      = fileparts(fileparts(fileparts(CompilerRoot)));
58     TargetRoot   = fix_slash(currentPath);
59     RppLibRoot   = fullfile(fileparts(TargetRoot), 'lib');
60
61     armcl = fullfile(CompilerRoot, 'bin', 'armcl');
62     if ~exist(armcl),
63         disp(sprintf('Error: "%s" does not exist!', armcl));
64         return;
65     end
66
67     % Save preferences
68     if ispref('rpp')
69         rmpref('rpp');
70     end
71     addpref('rpp', 'CompilerRoot', CompilerRoot);
72     addpref('rpp', 'CCSRoot'     , CCSRoot);
73     addpref('rpp', 'TargetRoot'  , TargetRoot);
74     addpref('rpp', 'RppLibRoot'  , RppLibRoot);
75
76
77     % Generate blocks
78     cd('../blocks');
79     compile_blocks();
80     cd(currentPath);
81
82     % Generate help
83     % FIXME: Write and generate help
84     %cd('../help/source');
85     %genenerate_help();
86     %cd(currentPath);
87
88     % Apply changes and finish
89     sl_refresh_customizations();
90     disp('<strong>RPP</strong> Target setup is complete!');
91     disp('    Current configuration:');
92     disp(['        CompilerRoot : ', CompilerRoot]);
93     disp(['        CCSRoot      : ', CCSRoot]);
94     disp(['        TargetRoot   : ', TargetRoot]);
95     disp(['        RppLibRoot   : ', RppLibRoot]);
96     disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory.');
97     %disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory and access <a href="matlab:doc -classic">documentation</a>');
98 end
99
100
101 function path = fix_slash(path0)
102     path = path0;
103     if ispc
104         path(path=='\')='/';
105     end
106 end