function choice = getcompilerchoice
% GETCOMPILERCHOICE Return currently selected compiler.
% CHOICE = GETCOMPILERCHOICE returns 1 if mex compiler is LCC, 2 if
%   compiler is Watcom and 0 otherwise.
%
%   Copyright 2009 The MathWorks, Inc.
%   $Revision: 1.1.6.1 $  $Date: 2010/08/30 02:55:00 $

% Note: This function is called from the s-functions using IPP to check for
% compiler compatibility

if ispc
    % only check Windows platform
    compilername = getcompilername;
    if isequal(compilername, 'lcc');
        choice = 1;
    elseif isequal(compilername, 'watc');
        choice = 2;
    else
        choice = 0;
    end
else
    choice = 0;
end
end


% Possible compiler strings are: vc, vcx64, watc, lcc
% -------------------------------------------------------------------------
function compiler = getcompilername

h = get_param(bdroot, 'MakeRTWSettingsObject');

if ~isempty(h.TemplateMakefile)
    tmfContents = rtwprivate('loadTMF', h.TemplateMakefile);
    compiler = lower(rtwprivate('getTMFMacro', tmfContents, 'COMPILER_TOOL_CHAIN'));
    if isempty(compiler)
        make = rtwprivate('getTMFMacro', tmfContents, 'MAKECMD');
        compiler = rtwprivate('getCompilerFromMakeCmd', make, h.TemplateMakefile);
    end
else
   compiler = 'unknown compiler';
end
end
