function clean_code_gen_dir(dirName,objectsOnly)

   if(nargin<2)
      objectsOnly = 0;
   end
         
   [prevErrMsg, prevErrId] = lasterr;
   [prevWarnMsg, prevWarnId] = lastwarn;
   warnFlag = warning;
   warning('off'); 
   currDir = pwd;
   try,
       cd(dirName);
       if(~isempty(strfind(pwd,'sfprj')) && ~isempty(strfind(pwd,'build')))
          % simple sanity check that this is a project directory.
          if(~objectsOnly)
             sf('Private', 'sf_delete_file', '*.*');
             infoMatDir = fullfile(pwd,'..','info');
             if(exist(infoMatDir,'dir'))
                 cd(infoMatDir);
                 sf('Private', 'sf_delete_file', '*.*');
             end
          else
            if(ispc)
               sf('Private', 'sf_delete_file', '*.obj');
            else
               sf('Private', 'sf_delete_file', '*.o');
            end               
          end
       else
         disp('Skipping clean target directory as it doesnt appear to be an autogenerated project dir');
       end
   catch,
       lasterr(prevErrMsg, prevErrId);
   end
   cd(currDir);
   lastwarn(prevWarnMsg, prevWarnId);
   warning(warnFlag);
  
   