% RPP_BUILD_DEMOS Builds all or selected demos in the demo folder
%     RPP_BUILD_DEMOS builds all demos in the demo directory.
%
%     RPP_BUILD_DEMOS DEMO1 DEMO2 ... builds only the demos
%     mentioned on the command line.
%
%     RPP_BUILD_DEMOS(CELLSTR) builds demos specified in the cell
%     array of strings CELLSTR.

% Copyright (C) 2013-2015 Czech Technical University in Prague
%
% Authors:
%     - Michal Sojka <sojkam1@fel.cvut.cz>
%
% 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 : compile_blocks.m
% Abstract:
%     Build all demos in the demo folder
%

function rpp_build_demos(varargin)
    d = fullfile(getpref('rpp', 'TargetRoot'), '..', 'demos');
    cd(d)

    if nargin == 1 && iscell(varargin{1}),
        for i=1:length(varargin{1}),
            build_demo(varargin{1}{i})
        end
    elseif nargin > 0,
        for i=1:nargin,
            build_demo(varargin{i});
        end
    else
        for i=dir('*.slx')',
            build_demo(i.name);
        end
    end

function build_demo(file)
    [p, n, e] = fileparts(file);
    disp(['Building ', file]);
    slbuild(n, 'StandaloneRTWTarget', 'ForceTopModelBuild', true);
