function generateDependencies(h, buildInfo)
%

%   Copyright 2014-2020 The MathWorks, Inc.

h.Components.Dependencies = h.createNewOrderedList( 'Dependencies' );

% Always have a dependency on this file
dependencies = h.BuilderArgs.MakefileDependencies;

% In some cases, a change in the makefile must not trigger any
if h.BuilderArgs.MakefileSelfDependency
    
    % Determine if compiler command file is in use
    lUseCompilerCommandFile = coder.make.useCompilerCommandFile...
        (h.ToolchainInfo);
    
    if lUseCompilerCommandFile
        % Object file dependency compiler command file
        dependencies{end+1} = h.getMacroToken('COMPILER_COMMAND_FILE');
    end        
    
    dependencies{end+1} = h.getMacroToken('MAKEFILE');
end

% For MEX_FILE build variants, there might be no source files 
% for the makefile to compile (and therefore no MODELLIB static 
% library). In this case, do not generate a rule like 
% 
%     $(ALL_OBJS) : rtw_proj.tmw $(COMPILER_COMMAND_FILE) $(MAKEFILE)
%
% In the above case ALL_OBJS is empty because source files are 
% compiled directly by mex. The nmake tool does not allow a rule with
% empty target.

if ~isempty(getSourceFiles(buildInfo, false, false))
    % $(ALL_OBJS) : rtw_proj.tmw $(COMPILER_COMMAND_FILE) $(MAKEFILE)
    h.quickAppend( h.Components.Dependencies, ...
                   h.getMacroToken(h.getMacroOf('all object files')), dependencies );
end
