]> rtime.felk.cvut.cz Git - pes-rpp/rpp-simulink.git/blobdiff - rpp/rpp/rpp_setup.m
Change license to MIT
[pes-rpp/rpp-simulink.git] / rpp / rpp / rpp_setup.m
index 2ea66f1a9c8d89f80b9cc3219a68a5be41b10309..5045a7378a8a9fd5a22dffce8de6217ce3b2d49c 100644 (file)
-% Copyright (C) 2013 Czech Technical University in Prague
+% Copyright (C) 2013, 2014, 2015 Czech Technical University in Prague
 %
 % Authors:
 %     - Carlos Jenkins <carlos@jenkins.co.cr>
 %
-% This program is free software; you can redistribute it and/or modify
-% it under the terms of the GNU General Public License as published by
-% the Free Software Foundation; either version 2 of the License, or
-% (at your option) any later version.
-%
-% This program is distributed in the hope that it will be useful,
-% but WITHOUT ANY WARRANTY; without even the implied warranty of
-% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-% GNU General Public License for more details.
-%
-% You should have received a copy of the GNU General Public License
-% along with this program.  If not, see <http://www.gnu.org/licenses/>.
+% Permission is hereby granted, free of charge, to any person
+% obtaining a copy of this software and associated documentation
+% files (the "Software"), to deal in the Software without
+% restriction, including without limitation the rights to use,
+% copy, modify, merge, publish, distribute, sublicense, and/or sell
+% copies of the Software, and to permit persons to whom the
+% Software is furnished to do so, subject to the following
+% conditions:
+
+% The above copyright notice and this permission notice shall be
+% included in all copies or substantial portions of the Software.
+
+% THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+% EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
+% OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+% NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
+% HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
+% WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+% FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
+% OTHER DEALINGS IN THE SOFTWARE.
 %
 % File : rpp_setup.m
 % Abstract:
-%     This file script adds paths for RPP target to the MATLAB path.
-%     IMPORTANT: This script _MUST_ be run by user after installing before
-%     using the target. To do so:
-%         1. Extract target package.
+%     RPP Target install script.
+%
+%        This script configures RPP target for use. It stores the location of
+%        armcl compiler and other location of other directories needed for
+%        proper function of the target. Finally, it compiles S-Function
+%        for RPP target blocks.
+%
+%        RPP_SETUP  RPP Target install script
+%        RPP_SETUP asks for the path to the Code Composer Studio's compiler.
+%        RPP_SETUP(PATH) uses the PATH argument as the path to the
+%        compiler.
+%
+%
+%     IMPORTANT: This script _MUST_ be run by user after extracting the target
+%                package and before using the target. To execute:
+%
+%         1. Start Matlab.
 %         2. Change directory (cd) to this file folder.
-%         3. Execute rpp_setup();
+%         3. Execute rpp_setup on command window.
 %
 % References:
 %     rtw_ug.pdf p. 1137
 
-
-% Install target on user's environment
-function rpp_setup()
-
+function rpp_setup(varargin)
     % Get current target path in user's filesystem
-    curpath = pwd();
-    tgtpath = curpath(1:end-length('/rpp'));
+    currentPath = pwd();
+    targetPath = currentPath(1:end-length('/rpp'));
 
-    % Add target system folders to Matlab path
-    addpath(fullfile(tgtpath, 'rpp'));
-    addpath(fullfile(tgtpath, 'demos'));
-    addpath(fullfile(tgtpath, 'blocks'));
-    %addpath(fullfile(tgtpath, 'help'));
-    savepath();
+    if ~exist(fullfile(targetPath, 'rpp', 'rpp_setup.m'), 'file'),
+        error('rpp:wrong_setup_dir', ['rpp_setup called from directory ' ...
+                            'other than .../rpp/rpp']);
+    end
 
-    % Ask user setup variables
-    PossiblePath = '/usr/local/ti/ccsv5/tools/compiler/arm_5.0.1';
+    if nargin == 0,
+        % Ask user setup variables
+        if ispref('rpp', 'CompilerRoot')
+            possiblePath = getpref('rpp', 'CompilerRoot');
+        else
+            if isunix, prefix='/usr/local'; else prefix='C:'; end
+            possiblePath = [prefix, '/ti/ccsv5/tools/compiler/arm_5.1.1'];
+        end
 
-    CompilerRoot = fix_slash(uigetdir(PossiblePath, ...
-        'CCS Compiler root directory: (<ccs_root>/tools/compiler/arm_5.X.X)'));
-    CCSRoot      = fileparts(fileparts(fileparts(CompilerRoot)));
-    TargetRoot   = fix_slash(curpath);
+        CompilerRoot = fix_slash(uigetdir(possiblePath, ...
+                                          ['CCS Compiler root ' ...
+                            'directory: (<ccs_root>/tools/compiler/arm_5.X.X)']));
+    else
+        CompilerRoot = fix_slash(varargin{1});
+    end
+    CCSRoot      = fullfile(fileparts(fileparts(fileparts(CompilerRoot))));
+    TargetRoot   = fix_slash(currentPath);
     RppLibRoot   = fullfile(fileparts(TargetRoot), 'lib');
 
-    % Save preferences
+    if ispc, ext='.exe'; else ext=''; end
+    armcl = fullfile(CompilerRoot, 'bin', ['armcl' ext]);
+    if ~exist(armcl, 'file'),
+        fprintf('Error: "%s" does not exist!\n', armcl);
+        return;
+    end
+
+    % Remove old paths and preferences (if any)
     if ispref('rpp')
+        oldTargetPath = getpref('rpp', 'TargetRoot');
+        rmpath(fullfile(oldTargetPath, '..', 'rpp'));
+        rmpath(fullfile(oldTargetPath, '..', 'demos'));
+        rmpath(fullfile(oldTargetPath, '..', 'blocks'));
         rmpref('rpp');
     end
+
+    % Add target system folders to Matlab path
+    addpath(fullfile(targetPath, 'rpp'));
+    addpath(fullfile(targetPath, 'demos'));
+    addpath(fullfile(targetPath, 'blocks'));
+    savepath();
+
+    % Save preferences
     addpref('rpp', 'CompilerRoot', CompilerRoot);
     addpref('rpp', 'CCSRoot'     , CCSRoot);
     addpref('rpp', 'TargetRoot'  , TargetRoot);
     addpref('rpp', 'RppLibRoot'  , RppLibRoot);
 
 
-    % Generate blocks
-    % FIXME: Implement blocks autobuild
-    %cd('../blocks');
-    %lct_genblocks();
-    %cd(curpath);
+    % Generate blocks and library
+    cd('../blocks');
+    compile_blocks();
+    rpp_generate_lib();
+    cd(currentPath);
 
     % Generate help
     % FIXME: Write and generate help
     %cd('../help/source');
-    %genhelp();
-    %cd(curpath);
+    %genenerate_help();
+    %cd(currentPath);
 
     % Apply changes and finish
     sl_refresh_customizations();
@@ -82,6 +127,7 @@ function rpp_setup()
     disp(['        CCSRoot      : ', CCSRoot]);
     disp(['        TargetRoot   : ', TargetRoot]);
     disp(['        RppLibRoot   : ', RppLibRoot]);
+    disp(['        Hardware     : ', rpp_get_target]);
     disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory.');
     %disp('Explore <a href="matlab:cd([getpref(''rpp'',''TargetRoot''),''/../demos''])">demos</a> directory and access <a href="matlab:doc -classic">documentation</a>');
 end