function ret = tgtLibAddSrc(fname, modelName)
%   TGTLIBADDSRC - Adds a source file to the build process

%   Copyright 2007-2012 The MathWorks, Inc.

ret = 0;
if (nargin < 2)
    modelName = bdroot;
end

if ~isempty(fname)
    if ~iscell(fname)
        fileName = {fname};
    else
        fileName = fname;
    end
    hPM = linkfoundation.pjtgenerator.getProjectManager(modelName);
    if ~isempty(hPM) && ~isempty(hPM.mProjectBuildInfo)
        % do not manipulate the project unless mProjectBuildInfo has been
        % established (not empty)
        [fpath,~,ext] = fileparts(fileName{:});
        % Exclude *.cmd files        
        if strcmpi(ext, '.cmd')
            if (~isempty(fpath))
                hPM.mProjectBuildInfo.markForRemovalFromLibPjt(fileName{:});
                hPM.mProjectBuildInfo.markForPILPjt(fileName{:});
            end
        end
        ret = hPM.addToProject('Src', fileName);
    end
end
