public override LinkResult Link(IConsole console, IStandardProject superProject, IStandardProject project,
CompileResult assemblies, string outputDirectory)
{
var result = new LinkResult();
var startInfo = new ProcessStartInfo();
startInfo.FileName = Path.Combine(BaseDirectory, "GCC\\bin", "arm-none-eabi-gcc.exe");
if (project.Type == ProjectType.StaticLibrary)
{
startInfo.FileName = Path.Combine(BaseDirectory, "GCC\\bin", "arm-none-eabi-ar.exe");
}
startInfo.WorkingDirectory = project.Solution.CurrentDirectory;
if (Path.IsPathRooted(startInfo.FileName) && !System.IO.File.Exists(startInfo.FileName))
{
result.ExitCode = -1;
console.WriteLine("Unable to find linker executable (" + startInfo.FileName + ") Check project compiler settings.");
return result;
}
// GenerateLinkerScript(project);
var objectArguments = string.Empty;
foreach (var obj in assemblies.ObjectLocations)
{
objectArguments += obj + " ";
}
var libs = string.Empty;
foreach (var lib in assemblies.LibraryLocations)
{
libs += lib + " ";
}
if (!Directory.Exists(outputDirectory))
{
Directory.CreateDirectory(outputDirectory);
}
var outputName = Path.GetFileNameWithoutExtension(project.Location) + ".elf";
if (project.Type == ProjectType.StaticLibrary)
{
outputName = "lib" + Path.GetFileNameWithoutExtension(project.Name) + ".a";
}
var executable = Path.Combine(outputDirectory, outputName);
var linkedLibraries = string.Empty;
foreach (var libraryPath in project.StaticLibraries)
{
var relativePath = project.CurrentDirectory;
var libName = Path.GetFileNameWithoutExtension(libraryPath).Substring(3);
linkedLibraries += string.Format(" -L\"{0}\" -l{1} ", relativePath, libName);
}
foreach (var lib in project.BuiltinLibraries)
{
linkedLibraries += string.Format("-l{0} ", lib);
}
// Hide console window
startInfo.UseShellExecute = false;
startInfo.RedirectStandardOutput = true;
startInfo.RedirectStandardError = true;
startInfo.RedirectStandardInput = true;
startInfo.CreateNoWindow = true;
startInfo.Arguments = string.Format("{0} -o{1} {2} -Wl,--start-group {3} {4} -Wl,--end-group",
GetLinkerArguments(superProject, project), executable, objectArguments, linkedLibraries, libs);
if (project.Type == ProjectType.StaticLibrary)
{
startInfo.Arguments = string.Format("rvs {0} {1}", executable, objectArguments);
}
//console.WriteLine(Path.GetFileNameWithoutExtension(startInfo.FileName) + " " + startInfo.Arguments);
//console.WriteLine ("[LL] - " + startInfo.Arguments);
using (var process = Process.Start(startInfo))
{
process.OutputDataReceived += (sender, e) =>
{
//console.WriteLine(e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
if (e.Data != null && !e.Data.Contains("creating"))
{
console.WriteLine(e.Data);
}
};
process.BeginOutputReadLine();
process.BeginErrorReadLine();
process.WaitForExit();
result.ExitCode = process.ExitCode;
if (result.ExitCode == 0)
{
result.Executable = executable;
}
}
return result;
}