public async Task<ProcessResult> ObjCopy(IConsole console, IProject project, LinkResult linkResult, AssemblyFormat format)
{
var result = new ProcessResult();
var commandName = Path.Combine(BinDirectory, $"{SizePrefix}objcopy" + Platform.ExecutableExtension);
if (PlatformSupport.CheckExecutableAvailability(commandName, BinDirectory))
{
string formatArg = "binary";
switch (format)
{
case AssemblyFormat.Binary:
formatArg = "binary";
break;
case AssemblyFormat.IntelHex:
formatArg = "ihex";
break;
}
string outputExtension = ".bin";
switch (format)
{
case AssemblyFormat.Binary:
outputExtension = ".bin";
break;
case AssemblyFormat.IntelHex:
outputExtension = ".hex";
break;
case AssemblyFormat.Elf32:
outputExtension = ".elf";
break;
}
var arguments = $"-O {formatArg} {linkResult.Executable} {Path.GetDirectoryName(linkResult.Executable)}{Platform.DirectorySeperator}{Path.GetFileNameWithoutExtension(linkResult.Executable)}{outputExtension}";
console.WriteLine($"Converting to {format.ToString()}");
result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) => console.WriteLine(e.Data), (s, e) => console.WriteLine(e.Data), false, string.Empty, false);
}
else
{
console.WriteLine("Unable to find tool (" + commandName + ") check project compiler settings.");
result.ExitCode = -1;
}
return result;
}