function MplabGetBuildinfo(buildInfo)
% BUILDINFO_DEMO - Demonstrates the Build Info API executed
% during the RTW build process.  This function is invoked as a result of
% set_param(model,'PostCodeGenCommand','get_buildinfo(buildInfo)')

%   Copyright 1994-2006 The MathWorks, Inc.
%   $Revision: 1.1 $


% Get the source and lib files
global mplab_build_info_model;
global mplab_build_info_lib;
global mplab_build_info_libFolders;

src = {};
headers = {};

mplab_build_info_model = '';
mplab_build_info_lib = '';
mplab_build_info_libFolders = '';

% Get all the files in the buildInfo object
%bInfo.allSrcFileList = getFiles(buildInfo, 'all', false, false);

% Get the source files from all groups with path and expanded matlabroot
%bInfo.srcFilesWPathMLRoot = getSourceFiles(buildInfo, true, true, {});

% Get the source files from all groups with path
src = [src getSourceFiles(buildInfo, true, false, {})];

% Get the source files from all groups with path
headers = [headers getIncludeFiles(buildInfo, true, false, {})];

% Get the source files from all groups without path
%bInfo.srcFilesWOPath = getSourceFiles(buildInfo, false, false, {});


% Get the source files associated with S-Functions, exclude everything else
%mplab_build_info = [mplab_build_info, ' ', getSourceFiles(buildInfo, true, true, 'Sfcn', {})];

% Get the source files associated with custom code, exclude everything else
%mplab_build_info = [mplab_build_info, ' ', getSourceFiles(buildInfo, true, true, 'CustomCode', {})];

% In order to get access to the rtwmakecfg source file, we have to first
% access the link object buildinfo_rtwmake_lib.
% This provides a handle to the link object buildInfo_rtwmakecfg_lib
lib = findLinkObject(buildInfo, 'buildinfo_rtwmakecfg_lib');

if ~isempty(lib)
    % Get the source files associated with library buildinfo_rtwmakecfg_lib
    %mplab_build_info = [mplab_build_info, ' ', getSourceFiles(lib, true, true)];

    % By default, the path and extension to the source files information
    % are not be included. This can be updated with the following API call
    updateFilePathsAndExtensions(buildInfo, '.c');
    updateFilePathsAndExtensions(buildInfo, '.h');

    % Get the library source files with the paths and extensions
    src = [src getSourceFiles(lib, true, true)];
    % Get the library include files with the paths and extensions
    headers = [headers getSourceFiles(lib, true, true)];

end

for( idx = 1:length(src) )
    %     if(idx == 1)
    %         mplab_build_info = [mplab_build_info '___mplabSourceFiles___'];
    %     end
    mplab_build_info_model = [mplab_build_info_model, char(src{idx}),sprintf('\n')];
end

for( idx = 1:length(headers) )
    %     if(idx == 1)
    %         mplab_build_info = [mplab_build_info ' ___mplabHeaderFiles___'];
    %     end
    mplab_build_info_model = [mplab_build_info_model, char(headers{idx}),sprintf('\n')];
    if( ~isempty(strfind(headers{idx}, 'rtwtypes.h')) )
        mplab_build_info_lib = [mplab_build_info_lib, char(headers{idx}),sprintf('\n')];
    end
end


%add an additional newline for the MPLAB API
mplab_build_info_model = [mplab_build_info_model, sprintf('\n')];
%%{

buildInfo.updateFilePathsAndExtensions
%buildInfo.getViewer
%buildInfo.linkObj
rtlibSrc = buildInfo.linkObj(1).getSourceFiles(true,true);
for( idx = 1:length(rtlibSrc) )
    if( isempty(strfind(rtlibSrc{idx}, 'rt_logging.c')) )
        mplab_build_info_lib = [mplab_build_info_lib, char(rtlibSrc{idx}),sprintf('\n')];
    end
end


%a = buildInfo.linkObj(1).getIncludeFiles(true,true)

libHeaderFolders = buildInfo.linkObj(1).getSourcePaths(true);
for( folderIdx = 1:length(libHeaderFolders) )
    libHeaders = dir(fullfile(libHeaderFolders{folderIdx},'*.h'));
    mplab_build_info_libFolders =  [mplab_build_info_libFolders, fullfile(libHeaderFolders{folderIdx},'*.h'),sprintf('\n')];
    mplab_build_info_libFolders =  [mplab_build_info_libFolders, fullfile(libHeaderFolders{folderIdx},'*.c'),sprintf('\n')];
    for( idx = 1:length(libHeaders) )
        mplab_build_info_lib = [mplab_build_info_lib, fullfile(libHeaderFolders{folderIdx},libHeaders(idx).name),sprintf('\n')];
    end
end

%add an additional newline for the MPLAB API
mplab_build_info_lib = [mplab_build_info_lib, sprintf('\n')];
%%}
