function clean_code_gen_dir(dirName,objectsOnly)

   if(nargin<2)
      objectsOnly = 0;
   end
         
   warnState = warning('off', 'all');
   warnRestore = onCleanup(@() warning(warnState));
   currDir = pwd;
   try
       if(isfolder(dirName))
           cd(dirName);
           if(contains(pwd,'sfprj'))
              % simple sanity check that this is a project directory.
              if ~objectsOnly
                 sfprivate('sf_delete_file', '*.*');
                 jiDir = fullfile(pwd,'ji');
                 if isfolder(jiDir)
                    rmdir(jiDir,'s');
                 end
                 infoMatDir = fullfile(pwd,'..','info');
                 iReportDir = fullfile(pwd,'..','html');
                 if isfolder(infoMatDir) 
                     cd(infoMatDir);
                     sfprivate('sf_delete_file', '*.*');
                  end
                 if sf('Feature', 'EML InferenceReport')
                     if isfolder(iReportDir)
                         cd(iReportDir);
                         dirs = dir(iReportDir);
                         for i=1:numel(dirs)
                             dirname = dirs(i).name;
                             if dirs(i).isdir && dirname(1) == 'c'
                                 rmdir(dirname, 's');
                             end
                         end
                     end
                 end
              else
                if(ispc)
                   sfprivate('sf_delete_file', '*.obj');
                else
                   sfprivate('sf_delete_file', '*.o');
                end               
              end
           else
              disp(getString(message('Stateflow:sfprivate:NotAutoGeneratedCleanSkip'))); 
           end
       end
   catch ME
   end
   cd(currDir);
  
   
