function ret = commonLinkerFileSelect(hObj)
%COMMONLINKERFILESELECT Select the common linker command file for the
%selected device based on user settings.

% Copyright 2017-2022 The MathWorks, Inc.

ret = '';
if codertarget.target.isCoderTarget(hObj.getConfigSet())
    if codertarget.data.isValidParameter(hObj.getConfigSet(), 'TargetLinkObj')
        targetLinkObjData = codertarget.data.getParameterValue(hObj.getConfigSet(), 'TargetLinkObj');
        useCustomLinker = targetLinkObjData.UseCustomLinker;
    else
        useCustomLinker = false;
    end
    targetHardware = codertarget.targethardware.getTargetHardware(hObj.getConfigSet());
    
    if (~useCustomLinker)
        if isequal(targetHardware.SubFamily, '2807x')
            ret = fullfile('$(TARGET_ROOT)', 'src', 'c28075.cmd');
        elseif isequal(targetHardware.SubFamily, '2837xS')
            ret = fullfile('$(TARGET_ROOT)', 'src', 'c28377S.cmd');
        elseif isequal(targetHardware.SubFamily, '2837xD')
            ret = fullfile('$(TARGET_ROOT)', 'src', 'c28377D.cmd');
        elseif isequal(targetHardware.SubFamily, '28004x')
            ret = fullfile('$(TARGET_ROOT)', 'src', 'c280049M.cmd');
        elseif isequal(targetHardware.Name, 'TI F2838x') && contains(codertarget.data.getParameterValue(hObj.getConfigSet(), 'ESB.ProcessingUnit'), 'CortexM4')
            ret = fullfile('$(TARGET_ROOT)', 'src', 'c2838x_CM.cmd');
        else
            ret = fullfile('$(TARGET_ROOT)', 'src', ['c' targetHardware.SubFamily '.cmd']);            
        end
    else
        ret = targetLinkObjData.Name;
    end
end
end