function removeBuildConfiguration(h,name)

%   Copyright 2014-2020 The MathWorks, Inc.

narginchk( 2, 2 );
name = convertStringsToChars(name);

if ~ischar( name ) && ~iscell( name )  %% ~iscellstr(value)
    error( message( 'coder_compile:toolchain:InvalidBuildConfigurationInput' ) );
end
factoryConfigs = coder.make.internal.getInfo( 'baseline-build-configs' );
isFactoryConfig = ismember( name, factoryConfigs );
if all( isFactoryConfig )
    % Warn about factory configs then return
    nameStr = name;
    if ischar( name )
        nameStr = { name };
    end
    nameStr = coder.make.internal.cell2str( nameStr, ',' );
    warning( message( 'coder_compile:toolchain:CannotRemoveFactoryBuildConfig', nameStr ) );
    return
elseif numel( isFactoryConfig )>1
    % Warn about factory configs, if any
    nameStr = name( isFactoryConfig );
    if ~isempty( nameStr )
        nameStr = coder.make.internal.cell2str( nameStr, ',' );
        warning( message( 'coder_compile:toolchain:CannotRemoveFactoryBuildConfig', nameStr ) );
    end
    % Proceed to remove the others, if any
    name = name( ~isFactoryConfig );
end
if strcmpi( name, 'all' )
    allConfigs = h.getBuildConfigurations()';
    name = setdiff( allConfigs, factoryConfigs );
    if isempty( name )
        return
    end
    % Remove all:
    % h.BuildConfigurations = h.createOrderedList([], 'BuildConfigurations');
end
present = h.checkBuildConfigFor( name );
if any( present==0 )
    if iscell( name )
        nameStr = coder.make.internal.cell2str( name( present==0 ), ',' );
        name = name( present==1 );
    else
        nameStr = name;
    end
    warning( message( 'coder_compile:toolchain:CannotRemoveBuildConfigDoesNotExist', nameStr ) );
    if isempty( name )
        return
    end
end
h.BuildConfigurations.remove( name );
end
