function [pass,message,recommendation] = validateSpecialLinkerProperties(h)

%   Copyright 2014-2020 The MathWorks, Inc.

pass = true;
recommendation = '';
message = '';
% ---------------------------------------
% If the BuildTool is a Single Pass Linker
% - We must check for the existence of both the StartLibraryGroup and EndLibraryGroup Directives
% ---------------------------------------
linkerTool = h.BuildTools.getValue( 'Linker' );
checkGrouping( linkerTool )
% Determine if a problem exists with the C++ Linker (added a part of the
% default build tools only in R2013b).
[missingCppLinker,uninitializedCppLinker,supportsCpp] = h.locateCppLinker();
if ~missingCppLinker && ~uninitializedCppLinker
    if supportsCpp
        linkerTool = h.BuildTools.getValue( 'C++ Linker' );
        checkGrouping( linkerTool )
    end
    return
end
msg = '### Validation of build tool "C++ Linker"';
% pass = false;
% Get the values of the C Linker - use this to initialize the
% missing or uninitialized C++ Linker.
bt = h.getBuildTool( 'Linker' );
toolName = strrep( bt.Name, 'C Linker', 'C++ Linker' );
if strcmp( bt.Name, toolName )
    toolName = strrep( toolName, 'Linker', 'C++ Linker' );
end
% Give the user instructions on how to proceed next.
msg1 = DAStudio.message( 'coder_compile:toolchain:ProbableCppLinkerBuildError' );
msg2 = DAStudio.message( 'coder_compile:toolchain:StepsToInitializeCppLinker' );
msg3 = DAStudio.message( 'coder_compile:toolchain:VerifyStepsToInitializeCppLinker' );
nl = sprintf( '\n' );
tb = sprintf( '\t' );
if missingCppLinker
    msg0 = DAStudio.message( 'coder_compile:toolchain:MissingCppLinker' );
    recommendation = [ msg, nl, msg0, nl, msg1, nl ];
elseif uninitializedCppLinker
    msg0 = DAStudio.message( 'coder_compile:toolchain:UninitializedCppLinker' );
    % Code snippet for setting the C++ Linker
    codeSnippet = [ tb, '% ------------------------------', nl, tb, '% C++ Linker', nl, tb, '% ------------------------------', nl, nl, tb, 'tool = tc.getBuildTool(''C++ Linker'');', nl, nl, tb, 'tool.setName(         ''', toolName, ''');    % !!! VERIFY THIS VALUE !!!', nl, tb, 'tool.setCommand(      ''', bt.getCommand(), '''); % !!! VERIFY THIS VALUE !!!', nl, tb, 'tool.setPath(         ''', bt.getPath(), ''');    % !!! VERIFY THIS VALUE !!!', nl, nl ];
    keys = bt.Directives.keys();
    values = cellfun( @(x) x.getValue(), bt.Directives.values, 'UniformOutput', false );
    str = '';
    for i = 1:numel( keys )
        str = [ str, tb, 'if tool.Directives.isKey(''', keys{ i }, ''')', nl ];  %#ok<AGROW>
        str = [ str, tb, tb, 'tool.setDirective(''', keys{ i }, ''', ''', values{ i }, ''');', nl ];  %#ok<AGROW>
        str = [ str, tb, 'end', nl ];  %#ok<AGROW>
    end
    codeSnippet = [ codeSnippet, str, nl ];
    keys = bt.FileExtensions.keys();
    values = cellfun( @(x) x.getValue(), bt.FileExtensions.values, 'UniformOutput', false );
    str = '';
    for i = 1:numel( keys )
        str = [ str, tb, 'if tool.FileExtensions.isKey(''', keys{ i }, ''')', nl ];  %#ok<AGROW>
        str = [ str, tb, tb, 'tool.setFileExtension(''', keys{ i }, ''', ''', values{ i }, ''');', nl ];  %#ok<AGROW>
        str = [ str, tb, 'end', nl ];  %#ok<AGROW>
    end
    codeSnippet = [ codeSnippet, str, nl ];
    recommendation = [ msg, nl, msg0, nl, msg1, nl, nl, msg2, nl, nl, codeSnippet, nl, msg3, nl ];
end
    function checkGrouping(linkerTool)
        if ~isequal( linkerTool.Directives.isKey( 'StartLibraryGroup' ), linkerTool.Directives.isKey( 'EndLibraryGroup' ) )
            message = DAStudio.message( 'coder_compile:toolchain:MissingGroupingDirective', linkerTool.Name );
            pass = 0;
            return
        end
    end
end
