function fixRTOneStep()
% fixRTOneStep
% Copyright 2015 - 2016 The MathWorks, Inc.

    here = fileparts(mfilename('fullpath'));
    
    srcRoot = fullfile(fileparts(fileparts(here)), 'cpp_patch');
    dstRoot = 'C:\MATLAB\SupportPackages\R2016a\toolbox\target\supportpackages\arduinotarget\scheduler';
    fileList = { ...
        fullfile('include', 'arduinoARMScheduler.h'), ...
        fullfile('include', 'arduinoAVRScheduler.h'), ...
        fullfile('src', 'arduinoARMScheduler.cpp'), ...
        fullfile('src', 'arduinoAVRScheduler.cpp') ...
        };
    
    for k=1:length(fileList)
        F = fileList{k};
        srcFile = fullfile(srcRoot, F);
        dstFile = fullfile(dstRoot, F);
        bakFile = [dstFile, '_orig'];
        patchIt(srcFile, dstFile, bakFile)
    end
    
end

function patchIt(srcFile, dstFile, bakFile)
   if ~exist(bakFile, 'file')
      movefile(dstFile, bakFile);
      copyfile(srcFile, dstFile);
   end
end