function [allLibs,mdlrefLibs,linkLibs] = getLibrariesFromDependencyTree(h)
%

%   Copyright 2014 The MathWorks, Inc.

target = h.Components.FinalProduct.TargetInfo;
mdlRefIdx = strcmpi( 'MdlRef', target.TargetDepsType );
buildInPlaceIdx = strcmpi( 'BuildInPlaceLib', target.TargetDepsType );
otherLibIdx = strcmpi( 'Lib', target.TargetDepsType );
linkLibsIdx = otherLibIdx | buildInPlaceIdx;
allLibsIdx = otherLibIdx | mdlRefIdx | buildInPlaceIdx;
% XXX: Workaround to attach missing library extension to
% build-in-place libraries.
pattern = '\$\((\w*)\)';
for j = 1:numel( buildInPlaceIdx )
    [~,~,fext] = fileparts( target.TargetDeps{ j } );
    if isempty( fext ) && isempty( regexp( target.TargetDeps{ j }, pattern, 'once' ) )
        target.TargetDeps{ j } = [ target.TargetDeps{ j }, h.getBuildTool( 'Archiver' ).getFileExtension( 'Static Library' ) ];
    end
end
allLibs = horzcat( target.TargetDeps( allLibsIdx ) );
mdlrefLibs = horzcat( target.TargetDeps( mdlRefIdx ) );
linkLibs = horzcat( target.TargetDeps( linkLibsIdx ) );
end
