function lUserSrcs = getUserSrcs(lBuildInfo)
%getUserSrcs extracts USER_SRCS from make options and determines file paths

% Copyright 2019-2020 The MathWorks, Inc.

if ~contains(lBuildInfo.MakeArgs, 'USER_SRCS')
    lUserSrcs = {};
    return
end

% Extract USER_SRCS from make options
lUserSrcs = coder.make.internal.parsestrforvar(lBuildInfo.MakeArgs, 'USER_SRCS');

% Convert the space separated filenames into cell array
lUserSrcs = strtrim(lUserSrcs);
lUserSrcs = regexp(lUserSrcs, '\s+', 'split');

[lUserSrcPaths, f, e] = coder.make.internal.fileparts(lUserSrcs, lBuildInfo.Settings.FileSep);
lUserSrcNames = strcat(f, e);

% It is optional for USER_SRCS to include a path; use buildInfo to resolve the path.
addSourceFiles(lBuildInfo, lUserSrcNames, lUserSrcPaths, 'USER_SRCS_TEMPORARY');
updateFilePathsAndExtensions(lBuildInfo);
lUserSrcs = getSourceFiles(lBuildInfo, true, false, 'USER_SRCS_TEMPORARY');

% Now that we've resolved the paths, remove these files from buildInfo
removeSourceFiles(lBuildInfo, lUserSrcNames);

