% 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>
%
% This document contains proprietary information belonging to Czech
% Technical University in Prague. Passing on and copying of this
% document, and communication of its contents is not permitted
% without prior written authorization.
%
% 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);
