function macros = getAllMacros(h)
% Declared Macros

%   Copyright 2014 The MathWorks, Inc.

macros = h.Macros.keys;
% Macros from toolchain files
% macros = horzcat(macros, ...
%     {h.getIncludePathsName(), h.getLibraryFilesName(), h.getSourceFilesName()});
% Macros from Build Tools
toolsets = { 'BuildTools', 'PrebuildTools', 'PostbuildTools', 'BuilderApplication' };
for i = 1:numel( toolsets )
    if strcmp( toolsets{ i }, 'BuilderApplication' )
        tools = { h.BuilderApplication };
    else
        toolset = h.(toolsets{ i });
        tools = toolset.values;
    end
    for z = 1:numel( tools )
        tool = tools{ z };
        % Command & Path
        macros = horzcat( macros, tool.Command.getMacro(), tool.Path.getMacro() );  %#ok<AGROW>
        % Lists
        lists = { 'FileExtensions', 'Directives' };
        for j = 1:numel( lists )
            list = lists{ j };
            buildItems = tool.(list).values;
            thisMacros = cell( 1, numel( buildItems ) );
            for k = 1:numel( buildItems )
                thisMacros{ k } = buildItems{ k }.getMacro();
            end
            macros = horzcat( macros, thisMacros );  %#ok<AGROW>
        end
    end
end
% Macros from Build Configuration
bc = h.getBuildConfiguration();
buildItems = bc.Options.values;
bcMacros = cell( 1, numel( buildItems ) );
for i = 1:numel( buildItems )
    bcMacros{ i } = buildItems{ i }.getMacro();
end
macros = horzcat( macros, bcMacros );
% Remove duplicates and empty entries
macros = unique( macros );
if isempty( macros{ 1 } )
    macros = macros( 2:end );
end
end
