function code_msvc_make_file(fileNameInfo,buildInfo,modelName)
% CODE_MSVC_MAKE_FILE(FILENAMEINFO)

%   Copyright 1995-2023 The MathWorks, Inc.
%     

    global gMachineInfo gTargetInfo %#ok<GVMIS>
    
    code_machine_objlist_file(fileNameInfo, buildInfo);

    fileName = fullfile(fileNameInfo.targetDirName,fileNameInfo.makeBatchFile);
  sf_echo_generating('Coder',fileName);
    file = fopen(fileName,'Wt');
    if file<3
        construct_coder_error([],getString(message('Stateflow:sfprivate:error_FailedToCreateFile',fileName)),1);
    end
    create_mexopts_caller_bat_file(file,fileNameInfo);
if gTargetInfo.codingGPU
addCudaPath = ['"' fileNameInfo.matlabRoot '\sys\cuda\win64\cuda\bin";"' fileNameInfo.matlabRoot '\sys\cuda\win64\cuda\nvvm\bin";%PATH%'];
fprintf(file,'set PATH=%s\n',addCudaPath);
end
fprintf(file,'nmake -f %s\n',fileNameInfo.msvcMakeFile);
    fclose(file);

    fileName = fullfile(fileNameInfo.targetDirName,fileNameInfo.msvcMakeFile);
  sf_echo_generating('Coder',fileName);
    file = fopen(fileName,'Wt');
    if file<3
        construct_coder_error([],getString(message('Stateflow:sfprivate:error_FailedToCreateFile',fileName)),1);
    end


    DOLLAR = '$';
fprintf(file,'# ------------------- Required for MSVC nmake ---------------------------------\n');
fprintf(file,'# This file should be included at the top of a MAKEFILE as follows:\n');
fprintf(file,'\n');
fprintf(file,'\n');
    if(~isempty(fileNameInfo.userMakefiles))
        for i=1:length(fileNameInfo.userMakefiles)
fprintf(file,'!include "%s"\n',fileNameInfo.userMakefiles{i});
        end
    end
        if(strcmp(computer,'PCWIN64'))
fprintf(file,'CPU = AMD64\n');
        end
    msCompilersWithWin32mak = { 'msvc100', 'msvcpp100', ...
                                'msvc90' , 'msvcpp90' , ...
                                'msvc80' , 'msvcpp80' , ...
                                'mssdk71', 'mssdk71cpp'};
    if ismember(gTargetInfo.compilerName, msCompilersWithWin32mak)
    % MSVC2012 and later no longer ships "Win32.Mak".
fprintf(file,'!include <ntwin32.mak>\n');
    end
fprintf(file,'\n');
fprintf(file,'MODEL     = %s\n',gMachineInfo.machineName);
fprintf(file,'TARGET      = %s\n',gMachineInfo.targetName);
    moduleSrcs = getCatString(buildInfo.getSourceFiles(false,true,'MODULE_SRCS'));
fprintf(file,'MODULE_SRCS   = %s\n',moduleSrcs);
    modelSrc = getCatString(buildInfo.getSourceFiles(false,true,'MODEL_SRC'));
fprintf(file,'MODEL_SRC  = %s\n',modelSrc);
    modelReg = getCatString(buildInfo.getSourceFiles(false,true,'MODEL_REG'));
fprintf(file,'MODEL_REG = %s\n',modelReg);

fprintf(file,'MAKEFILE    = %s\n',fileNameInfo.msvcMakeFile);

fprintf(file,'MATLAB_ROOT  = %s\n',fileNameInfo.matlabRoot);
fprintf(file,'BUILDARGS   =\n');

fprintf(file,'\n');
fprintf(file,'#--------------------------- Tool Specifications ------------------------------\n');
fprintf(file,'#\n');
fprintf(file,'#\n');
fprintf(file,'MSVC_ROOT1 = %s(MSDEVDIR:SharedIDE=vc)\n',DOLLAR);
fprintf(file,'MSVC_ROOT2 = %s(MSVC_ROOT1:SHAREDIDE=vc)\n',DOLLAR);
fprintf(file,'MSVC_ROOT  = %s(MSVC_ROOT2:sharedide=vc)\n',DOLLAR);
fprintf(file,'\n');
fprintf(file,'# Compiler tool locations, CC, LD, LIBCMD:\n');
fprintf(file,'CC     = cl.exe\n');
if gTargetInfo.codingGPU
    if gTargetInfo.codingLibrary
fprintf(file,'LD     = link.exe\n');
    else
fprintf(file,'LD     = nvcc\n');
    end
fprintf(file,'NVCC   = nvcc\n');
fprintf(file,'.SUFFIXES: .cu\n');
else
fprintf(file,'LD     = link.exe\n');
end
fprintf(file,'LIBCMD = lib.exe\n');

%
% g2680582: this fix allows the use of $(START_DIR) to represent the local anchor directory
% where source (or header) file directories may reside when using coder.updateBuildInfo
% (path expansion methods use this setting to expand the START_DIR macro)
%
if gTargetInfo.codingSFunction
    buildInfo.Settings.LocalAnchorDir = fileNameInfo.projectDirArray{1};
end

fprintf(file,'#------------------------------ Include/Lib Path ------------------------------\n');
fprintf(file,'\n');
    userIncludeDirString = '';
    userIncludeDirs = buildInfo.getIncludePaths(true,'USER_INCLUDES');
    for i = 1:length(userIncludeDirs)
        thisIncDir = userIncludeDirs{i};
        if ~isempty(regexp(thisIncDir, '^[a-zA-Z]+:$', 'once'))
            % G602058: MSVC has a bug that a drive root represented by
            % "c:" is not recognized. The workaround is to use "c:\."
            thisIncDir = [thisIncDir '\.'];  %#ok<AGROW>
        end
        userIncludeDirString    = [userIncludeDirString,' /I "',thisIncDir,'"']; %#ok<AGROW>
    end
fprintf(file,'USER_INCLUDES   = %s\n',userIncludeDirString);
    
auxIncludeDirString = '';
auxincludePaths = buildInfo.getIncludePaths(true,'AUX_INCLUDES');
for i = 1:length(auxincludePaths)
    auxIncludeDirString = [auxIncludeDirString,' /I "',auxincludePaths{i},'"']; %#ok<AGROW>
end

fprintf(file,'AUX_INCLUDES   = %s\n',auxIncludeDirString);
 
% All file Inlcudes
mlslsfInclude = buildInfo.getIncludePaths(true,{'ML_INCLUDES','SL_INCLUDES','SF_INCLUDES'});
fprintf(file,'MLSLSF_INCLUDES = \\\n');
if gTargetInfo.codingGPU
cudaInclude = '$(MATLAB_ROOT)\sys\cuda\win64\cuda\include';
gpucoderCudaUtilInclude = '$(MATLAB_ROOT)/toolbox/shared/gpucoder/src/cuda/export/include/cuda';
gpucoderThrustUtilInclude = '$(MATLAB_ROOT)/toolbox/gpucoder/gpucoder/src/cuda/thrust';
fprintf(file,'    /I "%s" \\\n',cudaInclude);
fprintf(file,'    /I "%s" \\\n',gpucoderCudaUtilInclude);
fprintf(file,'    /I "%s" \\\n',gpucoderThrustUtilInclude);
end
for i = 1:numel(mlslsfInclude)-1
fprintf(file,'    /I "%s" \\\n',mlslsfInclude{i});
end
fprintf(file,'    /I "%s" \n',mlslsfInclude{end});

fprintf(file,'\n');
fprintf(file,'COMPILER_INCLUDES = /I "%s(MSVC_ROOT)\\include"\n',DOLLAR);
fprintf(file,'\n');

    thirdPartyIncludeString = '';
    thirdPartyincludePaths = buildInfo.getIncludePaths(true,{},{'USER_INCLUDES',...
        'AUX_INCLUDES','ML_INCLUDES','SL_INCLUDES','SF_INCLUDES'});
    thirdPartyincludePaths = CGXE.Utils.fix_windows_paths_for_make_file(thirdPartyincludePaths);
    for i = 1:length(thirdPartyincludePaths)
        if coder.make.internal.isRelativePath(thirdPartyincludePaths{i})
            thirdPartyincludePaths{i} = [fileNameInfo.projectDirArray{1}, filesep, thirdPartyincludePaths{i}];
        end
        thirdPartyIncludeString = [thirdPartyIncludeString,' /I "',thirdPartyincludePaths{i},'"']; %#ok<AGROW>
    end
fprintf(file,'THIRD_PARTY_INCLUDES   = %s\n',thirdPartyIncludeString);
    
fprintf(file,'INCLUDE_PATH = %s(USER_INCLUDES) %s(AUX_INCLUDES) %s(MLSLSF_INCLUDES)\\\n',DOLLAR,DOLLAR,DOLLAR);
fprintf(file,' %s(THIRD_PARTY_INCLUDES)\n',DOLLAR);

fprintf(file,'LIB_PATH     = "%s(MSVC_ROOT)\\lib"\n',DOLLAR);

fprintf(file,'\n');

fprintf(file,'CFLAGS = %s %s\n',getCatString(buildInfo.getCompileFlags),getCatString(buildInfo.getDefines));
fprintf(file,'LDFLAGS = %s\n',getCatString(buildInfo.getLinkFlags));
if  gTargetInfo.codingGPU
if ~isempty(gTargetInfo.gpuCustomComputeCapability)
    gpuFlags = gTargetInfo.gpuCustomComputeCapability;
    ptxVersion = '500';
else
    ccVals = regexp(gTargetInfo.gpuComputeCapability,'\.','split');
    gpuFlags = ['-arch sm_' ccVals{1} ccVals{2}];
    ptxVersion = [ccVals{1} ccVals{2} '0'];
end
gpuFlags = [gpuFlags ' -DMW_CUDA_ARCH=' ptxVersion];
if ~isempty(gTargetInfo.gpuCompilerFlags)
    gpuFlags = [gpuFlags ' ' gTargetInfo.gpuCompilerFlags];
end

% Replace "/I" with "-I" in the include path for nvcc.
fprintf(file,'NVCC_INCLUDE_PATH = %s(INCLUDE_PATH:/I=-I)\n',DOLLAR);
cudaFlagNoRdc = ['-c ' gpuFlags ' -noprof -ldir "$(MATLAB_ROOT)/bin/win64"'];
fprintf(file,'CUFLAGS_NO_RDC = %s\n',cudaFlagNoRdc);
fprintf(file,'CUFLAGS = %s(CUFLAGS_NO_RDC) -rdc=true\n',DOLLAR);
gpucoderCudaUtilLib = '$(MATLAB_ROOT)/bin/win64/gpucoder_cuda.lib';
fprintf(file,'GPUCODER_CUDA_UTIL_LIB = "%s"\n',gpucoderCudaUtilLib);
cudaLd = [gpuFlags ' -Xlinker /NODEFAULTLIB:libcmt.lib -I"$(MATLAB_ROOT)\sys\cuda\win64\cuda\include" -L"$(MATLAB_ROOT)\sys\cuda\win64\cuda\lib\x64" -L"$(MATLAB_ROOT)\bin\win64" cudart.lib cublas.lib cusolver.lib cufft.lib cusparse.lib curand.lib'];
fprintf(file,'CULDFLAGS = %s\n',cudaLd);
end

fprintf(file,'#----------------------------- Source Files -----------------------------------\n');
fprintf(file,'\n');
fprintf(file,'REQ_SRCS  =  %s(MODEL_SRC) %s(MODEL_REG) %s(MODULE_SRCS)\n',DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'\n');
userSources = buildInfo.getSourceFiles(true,true,'USER_SRCS');
    if(~isempty(userSources))
fprintf(file,'USER_OBJS    = \\\n');
        for i=1:length(userSources)
            [~, nameStr] = fileparts(userSources{i});
            objStr = [nameStr '.obj'];
fprintf(file,'     "%s" \\\n',objStr);
        end
    else
fprintf(file,'USER_OBJS =\n');
    end
fprintf(file,'\n');
% All other source files
auxSourceFiles  =  buildInfo.getSourceFiles(true,true,'AUX_SRCS');
if ~isempty(auxSourceFiles)
fprintf(file,'AUX_ABS_OBJS = \\\n');
    for i=1:numel(auxSourceFiles)
        [~, nameStr] = fileparts(auxSourceFiles{i});
        objStr = [nameStr '.obj'];
fprintf(file,'     "%s" \\\n',objStr);
    end
else
fprintf(file,'AUX_ABS_OBJS =\n');
end
fprintf(file,'\n');
    
thirdPartyExcludeGroups = {'MODULE_SRCS','MODEL_SRC','MODEL_REG', ...
    'AUX_SRCS','USER_SRCS'};
thirdPartySources  =  buildInfo.getSourceFiles(true,true,{},thirdPartyExcludeGroups);
% Third Party Source Paths contain only paths specfied in
% coder.ExternalDepedency or coder.Buildable
thirdPartySourcePaths = buildInfo.getSourcePaths(true); 

%
% g2680582: this fix cleans the use of the local anchor dir as it was not originally set
% from with the gTargetInfo
%
if gTargetInfo.codingSFunction
    buildInfo.Settings.LocalAnchorDir = '';
end
    if(~isempty(thirdPartySources))
fprintf(file,'THIRD_PARTY_OBJS     = \\\n');
        for i=1:length(thirdPartySources)
            [~, nameStr] = fileparts(thirdPartySources{i});
            objStr = [nameStr '.obj'];
fprintf(file,'     "%s" \\\n',objStr);
        end
    else
fprintf(file,'THIRD_PARTY_OBJS =\n');
    end

fprintf(file,'\n');
fprintf(file,'REQ_OBJS = %s(REQ_SRCS:.cpp=.obj)\n',DOLLAR);
if gTargetInfo.codingGPU
fprintf(file,'REQ_OBJS2 = %s(REQ_OBJS:.cu=.obj)\n',DOLLAR);
fprintf(file,'REQ_OBJS3 = %s(REQ_OBJS2:.c=.obj)\n',DOLLAR);
fprintf(file,'OBJS = %s(REQ_OBJS3) %s(USER_OBJS) %s(AUX_ABS_OBJS) %s(THIRD_PARTY_OBJS)\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR);
else
fprintf(file,'REQ_OBJS2 = %s(REQ_OBJS:.c=.obj)\n',DOLLAR);
fprintf(file,'OBJS = %s(REQ_OBJS2) %s(USER_OBJS) %s(AUX_ABS_OBJS) %s(THIRD_PARTY_OBJS)\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR);
end
fprintf(file,'OBJLIST_FILE = %s\n',fileNameInfo.objListFile);

fprintf(file,'SFCLIB = %s\n',getLinkObjStringForGroup(buildInfo,'SFCLIB'));

fprintf(file,'AUX_LNK_OBJS = %s    \n',getLinkObjStringForGroup(buildInfo,'AUX_LNK_OBJS'));

fprintf(file,'USER_LIBS = %s\n',getLinkObjStringForGroup(buildInfo,'USER_LIBS'));

excludeGroups = {'SFCLIB', 'AUX_LNK_OBJS','USER_LIBS', ...
    'LINK_MACHINE_LIBS', 'LINK_MACHINE_OBJLIST', 'TMWLIB'};
userGroups ={};
if gTargetInfo.codingLibrary
    libObjListfile = ['lib_' fileNameInfo.objListFile];
    CGXE.Coder.code_append_user_external_link_flags_for_library(libObjListfile,  fileNameInfo.targetDirName, buildInfo);
else
    libObjListfile = fileNameInfo.objListFile;
end

libList = {};
libListTmp0 = code_append_libs_to_objlist_file_msvc(libObjListfile, ...
    fileNameInfo.targetDirName, buildInfo,userGroups,excludeGroups);
libListTmp1 = CGXE.Coder.code_append_syslibs_to_objlist_file(libObjListfile,fileNameInfo.targetDirName, ...
    buildInfo, modelName);  %Third Party Libraries
libList = [libList(:)', libListTmp0(:)', libListTmp1(:)'];
fprintf(file,'#--------------------------------- Rules --------------------------------------\n');
fprintf(file,'\n');
    if gTargetInfo.codingLibrary  
       
fprintf(file,'%s(MODEL)_%s(TARGET).lib : %s(MAKEFILE) %s(OBJS) %s(SFCLIB) %s(AUX_LNK_OBJS) %s(USER_LIBS) %s(THIRD_PARTY_LIBS)\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'	@echo ### Linking ...\n');
fprintf(file,'	%s(LD) -lib /OUT:%s(MODEL)_%s(TARGET).lib @%s(OBJLIST_FILE) %s(USER_LIBS) %s(THIRD_PARTY_LIBS)\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'	@echo ### Created Stateflow library %s@\n',DOLLAR);

    else 
        % Due to g1205457 added the list of libs to the objlist file only for
        % the MEX file's Makefile
        libListTmp0 = code_append_libs_to_objlist_file_msvc(libObjListfile,...
            fileNameInfo.targetDirName, buildInfo, 'LINK_MACHINE_LIBS');
        libListTmp1 = code_append_libs_to_objlist_file_msvc(libObjListfile,...
            fileNameInfo.targetDirName, buildInfo, 'LINK_MACHINE_OBJLIST');
        libListTmp2 = code_append_libs_to_objlist_file_msvc(libObjListfile, ...
            fileNameInfo.targetDirName, buildInfo, 'TMWLIB');
        libList = [libList(:)', libListTmp0(:)', libListTmp1(:)', libListTmp2(:)'];
        if(gTargetInfo.codingMEX && ~isempty(sf('get',gMachineInfo.target,'target.mexFileName')))

fprintf(file,'MEX_FILE_NAME_WO_EXT = %s\n',sf('get',gMachineInfo.target,'target.mexFileName'));
        else
fprintf(file,'MEX_FILE_NAME_WO_EXT = %s(MODEL)_%s(TARGET)\n',DOLLAR,DOLLAR);
        end
fprintf(file,'MEX_FILE_NAME = %s(MEX_FILE_NAME_WO_EXT).%s\n',DOLLAR,mexext);
        mapCsfBinary = '';

        if(~isempty(mapCsfBinary))
fprintf(file,'MEX_FILE_CSF =  %s(MEX_FILE_NAME_WO_EXT).csf\n',DOLLAR);
        else
fprintf(file,'MEX_FILE_CSF =\n');
        end

fprintf(file,'all : %s(MEX_FILE_NAME) %s(MEX_FILE_CSF)\n',DOLLAR,DOLLAR);
fprintf(file,'\n');

if gTargetInfo.codingGPU
systemLibStr = [];
for i = 1:numel(libList)
    systemLibStr = [systemLibStr, ' ', libList{i}]; %#ok<AGROW>
end
% Replace newline with space
systemLibStr = strrep(systemLibStr, newline, ' ');
% Replace /LIBPATH: with space -Xliner /LIBPATH:
systemLibStr = regexprep(systemLibStr, '("?/LIBPATH:)', '-Xlinker $1');
fprintf(file,'SYS_LIBS = %s\n',systemLibStr);
end

fprintf(file,'%s(MEX_FILE_NAME) : %s(MAKEFILE) %s(OBJS) %s(SFCLIB) %s(AUX_LNK_OBJS) %s(USER_LIBS) %s(THIRD_PARTY_LIBS)\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,' @echo ### Linking ...\n');
if gTargetInfo.codingGPU
fprintf(file,' %s(LD) %s(LDFLAGS) %s(CULDFLAGS) %s(GPUCODER_CUDA_UTIL_LIB) -o %s(MEX_FILE_NAME) -Xlinker /map:"%s(MEX_FILE_NAME_WO_EXT).map"\\\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'  %s(USER_LIBS) %s(SFCLIB) %s(AUX_LNK_OBJS)\\\n',DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'  %s(DSP_LIBS) %s(THIRD_PARTY_LIBS)\\\n',DOLLAR,DOLLAR);
fprintf(file,'  %s(SYS_LIBS) %s(OBJS)\n',DOLLAR,DOLLAR);
else
fprintf(file,' %s(LD) %s(LDFLAGS) /OUT:%s(MEX_FILE_NAME) /map:"%s(MEX_FILE_NAME_WO_EXT).map"\\\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'  %s(USER_LIBS) %s(SFCLIB) %s(AUX_LNK_OBJS)\\\n',DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'  %s(DSP_LIBS) %s(THIRD_PARTY_LIBS)\\\n',DOLLAR,DOLLAR);
fprintf(file,'  @%s(OBJLIST_FILE)\n',DOLLAR);
end

fprintf(file,'	@echo ### Created %s@\n',DOLLAR);
fprintf(file,'\n');
        if(~isempty(mapCsfBinary))
fprintf(file,'%s(MEX_FILE_CSF) : %s(MEX_FILE_NAME)\n',DOLLAR,DOLLAR);
fprintf(file,'	"%s" %s(MEX_FILE_NAME)\n',mapCsfBinary,DOLLAR);
        end
    end

%Use nvcc to compile all source files to avoid the complications of passing flags to host compiler and nvcc.
if gTargetInfo.codingGPU
fprintf(file,'.c.obj :\n');
fprintf(file,'	@echo ### Compiling "%s<"\n',DOLLAR);
fprintf(file,'	%s(NVCC) %s(CUFLAGS) %s(CFLAGS) %s(NVCC_INCLUDE_PATH) "%s<"\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'\n');
fprintf(file,'.cpp.obj :\n');
fprintf(file,'	@echo ### Compiling "%s<"\n',DOLLAR);
fprintf(file,'	%s(NVCC) %s(CUFLAGS) %s(CFLAGS) %s(NVCC_INCLUDE_PATH) "%s<"\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'\n');
fprintf(file,'.cu.obj :\n');
fprintf(file,'	@echo ### Compiling "%s<" \n',DOLLAR);
fprintf(file,'	%s(NVCC) %s(CUFLAGS) %s(CFLAGS) %s(NVCC_INCLUDE_PATH) "%s<"\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'\n');
else
fprintf(file,'.c.obj :\n');
fprintf(file,'	@echo ### Compiling "%s<"\n',DOLLAR);
fprintf(file,'	%s(CC) %s(CFLAGS) %s(INCLUDE_PATH) "%s<"\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'\n');
fprintf(file,'.cpp.obj :\n');
fprintf(file,'	@echo ### Compiling "%s<"\n',DOLLAR);
fprintf(file,'	%s(CC) %s(CFLAGS) %s(INCLUDE_PATH) "%s<"\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR);
fprintf(file,'\n');
end

        for i=1:length(userSources)
            [~, nameStr] = fileparts(userSources{i});
            objFileName = [nameStr '.obj'];
fprintf(file,'%s :  "%s"\n',objFileName,userSources{i});
fprintf(file,'	@echo ### Compiling "%s"\n',userSources{i});
        [~,~,ext] = fileparts(userSources{i});
            if gTargetInfo.codingGPU && strcmpi(ext, '.cu')
fprintf(file,'	%s(NVCC) %s(CUFLAGS_NO_RDC) %s(CFLAGS) %s(NVCC_INCLUDE_PATH) %s(CUINCLUDE) "%s"\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,userSources{i});
            else
fprintf(file,'	%s(CC) %s(CFLAGS) %s(INCLUDE_PATH) "%s"\n',DOLLAR,DOLLAR,DOLLAR,userSources{i});
            end
        end
fprintf(file,'\n');
    for i=1:length(thirdPartySourcePaths)
        if coder.make.internal.isRelativePath(thirdPartySourcePaths{i})
            thirdPartySourcePaths{i} = [fileNameInfo.projectDirArray{1}, filesep, thirdPartySourcePaths{i}];
        end
    end

        for i=1:length(thirdPartySources)
            [fullSrcName, srcFileName] = CGXE.Utils.tokenizeFileFromModel(thirdPartySources{i}, modelName, thirdPartySourcePaths);
            objFileName = [srcFileName '.obj'];
fprintf(file,'%s :  "%s"\n',objFileName,fullSrcName);
fprintf(file,'	@echo ### Compiling "%s"\n',fullSrcName);
            if gTargetInfo.codingGPU
fprintf(file,' %s(NVCC) %s(CUFLAGS_NO_RDC) %s(CFLAGS) %s(NVCC_INCLUDE_PATH) %s(CUINCLUDE) "%s"\n',DOLLAR,DOLLAR,DOLLAR,DOLLAR,DOLLAR,fullSrcName);
            else
fprintf(file,'	%s(CC) %s(CFLAGS) %s(INCLUDE_PATH) "%s"\n',DOLLAR,DOLLAR,DOLLAR,fullSrcName);
            end
        end

    fclose(file);

function linkObjStr =  getLinkObjStringForGroup(buildInfo,group,excludeGroups)
%Helper function to create a string that contatenates the Link objects in
%the platform specific format for a given group.
if nargin < 3
    excludeGroups ={};
end
linkObjs = buildInfo.getLinkObjects(group,excludeGroups);
linkObjStr = '';
for iL=  1:numel(linkObjs)
    currLinkObjPath = linkObjs(iL).Path;
    currLinkObjPath = strrep(currLinkObjPath,'$(MATLAB_ROOT)',matlabroot);
    linkObjStr = [linkObjStr '"' fullfile(currLinkObjPath,linkObjs(iL).Name) '" ']; %#ok<AGROW>
end
    
function str = getCatString(incell)
%Conatenate all the strings in cell array of strings.
str = sprintf('%s ',incell{:});
if ~isempty(str)
    str(end) = [];
end
