classdef StandaloneSharedWriter < compiler.internal.mcc.MccDependencyWriter
    %STANDALONESHAREDWRITER Writes the mcc command for all Standalone
    %Application Targets

%   Copyright 2020-2021 The MathWorks, Inc.
    
    % define abstract
    properties(Constant,Access = protected)
        OptionsClass = 'compiler.build.StandaloneApplicationOptions'
    end
    
    % abstract
    properties(Abstract,Constant,Access = protected)
        WrapperType
    end
    
    properties(Access = private)
        IconFile
    end
    
    methods
        function obj = StandaloneSharedWriter(options)
            obj = obj@compiler.internal.mcc.MccDependencyWriter(options);
        end
    end
    
    methods(Access=protected)
        function addTargetCommands(obj)
            obj.addCommand("-o")
            obj.addCommand(obj.Options.ExecutableName)
            
            if(obj.Options.TreatInputsAsNumeric)
                obj.addCommand("-n")
            end
            
            if(~obj.Options.EmbedArchive)
               obj.addCommand("-C");
            end
            
            if(~isempty(obj.Options.CustomHelpTextFile))
                %we will expect a file rather than the help string
                %UI would probably only create a temp file at build time
                obj.addCommand("-h")
                obj.addCommand(obj.Options.CustomHelpTextFile)
            end
            
            obj.writeIconDetails
        end
        
        function writeIconDetails(obj)
            
            % Linux should ignore this
            obj.IconFile = fullfile(tempname,'icon.ico');
            if ispc
                obj.addCommand("-r")
                obj.addCommand(obj.IconFile)
            end
        end
        
        function addPostDashWCommands(obj)
            
            %Using Executable name for the W flag as well
            dashWString = strcat(obj.WrapperType, ":", obj.Options.getName);
            
            if ispc || ismac
                dashWString = strcat(dashWString, ",version=");
                %version specific to the executable 
                dashWString = strcat(dashWString, obj.Options.ExecutableVersion);
            end
            
            obj.addCommand(dashWString)
        end
        
        function addDashTCommands(obj)
            obj.addCommand("-T")
            obj.addCommand("link:exe")
        end
        
        function writeCommandForFiles(obj)
            appFile = obj.Options.AppFile;
            obj.addCommand(string(appFile))
        end
        
        function mccInputInfo = addAdditionalInfo(obj,mccInputInfo)
            mccInputInfo.IconFile = obj.IconFile;
        end
    end
end
