public override string GetBaseLibraryArguments(IStandardProject superProject)
        {
            var    settings = superProject.GetToolchainSettings <GccToolchainSettings>();
            string result   = string.Empty;

            // TODO linked libraries won't make it in on nano... Please fix -L directory placement in compile string.
            switch (settings.LinkSettings.Library)
            {
            case LibraryType.NanoCLib:
                result += "-lm -lc_nano -lsupc++_nano -lstdc++_nano ";
                break;

            case LibraryType.BaseCLib:
                result += "-lm -lc -lstdc++ -lsupc++ ";
                break;

            case LibraryType.SemiHosting:
                result += "-lm -lgcc -lc -lrdimon ";
                break;

            case LibraryType.Retarget:
                result += "-lm -lc -lg -lnosys -lstdc++ -lsupc++ ";
                break;
            }

            return(result);
        }
Beispiel #2
0
        public override string GetLinkerArguments(IStandardProject superProject, IStandardProject project)
        {
            var settings = project.GetToolchainSettings <GccToolchainSettings>();

            if (superProject != null && settings.LinkSettings.UseMemoryLayout && project.Type != ProjectType.StaticLibrary)
            {
                GenerateLinkerScript(superProject);
            }

            var result = string.Empty;

            result += string.Format("{0} ", settings.LinkSettings.MiscLinkerArguments);

            switch (settings.CompileSettings.Fpu)
            {
            case FPUSupport.Soft:
                result += " -mfpu=fpv4-sp-d16 -mfloat-abi=softfp ";
                break;

            case FPUSupport.Hard:
                result += " -mfpu=fpv4-sp-d16 -mfloat-abi=hard ";
                break;
            }

            if (settings.LinkSettings.NotUseStandardStartupFiles)
            {
                result += "-nostartfiles ";
            }

            if (settings.LinkSettings.DiscardUnusedSections)
            {
                result += "-Wl,--gc-sections ";
            }

            switch (settings.CompileSettings.Optimization)
            {
            case OptimizationLevel.None:
                result += " -O0";
                break;

            case OptimizationLevel.Level1:
                result += " -O1";
                break;

            case OptimizationLevel.Level2:
                result += " -O2";
                break;

            case OptimizationLevel.Level3:
                result += " -O3";
                break;
            }

            if (settings.LinkSettings.UseMemoryLayout)
            {
                result += string.Format(" -L{0} -Wl,-T\"{1}\"", project.CurrentDirectory, GetLinkerScriptLocation(project));
            }

            return(result);
        }
        private void GenerateLinkerScript(IStandardProject project)
        {
            var settings = project.GetToolchainSettings <GccToolchainSettings>().LinkSettings;
            var template = new ArmGCCLinkTemplate(settings);

            var linkerScript = GetLinkerScriptLocation(project);

            if (System.IO.File.Exists(linkerScript))
            {
                System.IO.File.Delete(linkerScript);
            }

            using (var sw = System.IO.File.CreateText(linkerScript))
            {
                // sw.Write(template.TransformText());
            }
        }
Beispiel #4
0
        private void GenerateLinkerScript(IStandardProject project)
        {
            var settings = project.GetToolchainSettings <GccToolchainSettings>().LinkSettings;

            var linkerScript = GetLinkerScriptLocation(project);

            if (System.IO.File.Exists(linkerScript))
            {
                System.IO.File.Delete(linkerScript);
            }

            var rendered = Template.Engine.Parse("ArmLinkerScriptTemplate.template", new { InRom1Start = settings.InRom1Start, InRom1Size = settings.InRom1Size, InRam1Start = settings.InRam1Start, InRam1Size = settings.InRam1Size });

            using (var sw = System.IO.File.CreateText(linkerScript))
            {
                sw.Write(rendered);
            }
        }
Beispiel #5
0
        /*public override IEnumerable<string> GetToolchainIncludes(ISourceFile file)
         * {
         *  return new List<string>
         *  {
         *      Path.Combine(ContentDirectory, "arm-none-eabi", "include", "c++", "6.3.1"),
         *      Path.Combine(ContentDirectory, "arm-none-eabi", "include", "c++", "6.3.1", "arm-none-eabi"),
         *      Path.Combine(ContentDirectory, "arm-none-eabi", "include", "c++", "6.3.1", "backward"),
         *      Path.Combine(ContentDirectory, "arm-none-eabi", "include"),
         *      Path.Combine(ContentDirectory, "lib", "gcc", "arm-none-eabi", "6.3.1", "include"),
         *      Path.Combine(ContentDirectory, "lib", "gcc", "arm-none-eabi", "6.3.1", "include-fixed"),
         *      Path.Combine(ContentDirectory, "arm-none-eabi", "include")
         *  };
         * }*/

        private void GenerateLinkerScript(IStandardProject project)
        {
            var settings = project.GetToolchainSettings <GccToolchainSettings>().LinkSettings;

            var linkerScript = GetLinkerScriptLocation(project);

            if (System.IO.File.Exists(linkerScript))
            {
                System.IO.File.Delete(linkerScript);
            }

            throw new NotImplementedException();
            //var rendered = Template.Engine.CompileRenderAsync("ArmLinkerScriptTemplate.template", new { InRom1Start = settings.InRom1Start, InRom1Size = settings.InRom1Size, InRam1Start = settings.InRam1Start, InRam1Size = settings.InRam1Size }).GetAwaiter().GetResult();

            //using (var sw = System.IO.File.CreateText(linkerScript))
            //{
            //    sw.Write(rendered);
            //}
        }
Beispiel #6
0
        public override string GetLinkerArguments(IStandardProject superProject, IStandardProject project)
        {
            var settings = project.GetToolchainSettings <GccToolchainSettings>();

            var result = string.Empty;

            result += string.Format("-static-libgcc -static-libstdc++ -Wl,-Map={0}.map ",
                                    Path.GetFileNameWithoutExtension(project.Name));

            result += string.Format("{0} ", settings.LinkSettings.MiscLinkerArguments);

            if (settings.LinkSettings.DiscardUnusedSections)
            {
                result += "-Wl,--gc-sections ";
            }

            switch (settings.CompileSettings.Optimization)
            {
            case OptimizationLevel.None:
                result += " -O0";
                break;

            case OptimizationLevel.Level1:
                result += " -O1";
                break;

            case OptimizationLevel.Level2:
                result += " -O2";
                break;

            case OptimizationLevel.Level3:
                result += " -O3";
                break;
            }

            return(result);
        }
        public override string GetCompilerArguments(IStandardProject superProject, IStandardProject project, ISourceFile file)
        {
            var result = string.Empty;

            var settings = superProject.GetToolchainSettings <GccToolchainSettings>();

            result += "-Wall -c ";

            if (settings.CompileSettings.DebugInformation)
            {
                result += "-ggdb3 ";
            }

            if (file == null || file.Extension == ".cpp")
            {
                switch (settings.CompileSettings.CppLanguageStandard)
                {
                case CppLanguageStandard.Cpp98:
                    result += "-std=c++98 ";
                    break;

                case CppLanguageStandard.Cpp03:
                    result += "-std=c++03 ";
                    break;

                case CppLanguageStandard.Cpp11:
                    result += "-std=c++11 ";
                    break;

                case CppLanguageStandard.Cpp14:
                    result += "-std=c++14 ";
                    break;

                case CppLanguageStandard.Cpp17:
                    result += "-std=c++17 ";
                    break;

                case CppLanguageStandard.Gnu11:
                    result += "-std=gnu++11 ";
                    break;

                case CppLanguageStandard.Gnu14:
                    result += "-std=gnu++14 ";
                    break;

                default:
                    break;
                }

                if (!settings.CompileSettings.Rtti)
                {
                    result += "-fno-rtti ";
                }

                if (!settings.CompileSettings.Exceptions)
                {
                    result += "-fno-exceptions ";
                }
            }

            if (file == null || file.Extension == ".c")
            {
                switch (settings.CompileSettings.CLanguageStandard)
                {
                case CLanguageStandard.C89:
                    result += "-std=c89 ";
                    break;

                case CLanguageStandard.C99:
                    result += "-std=c99 ";
                    break;

                case CLanguageStandard.C11:
                    result += "-std=c11 ";
                    break;
                }
            }

            switch (settings.CompileSettings.Fpu)
            {
            case FPUSupport.Soft:
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=softfp ";
                break;

            case FPUSupport.Hard:
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=hard ";
                break;
            }

            switch (settings.CompileSettings.Fpu)
            {
            case FPUSupport.Soft:
            {
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=softfp ";
            }
            break;

            case FPUSupport.Hard:
            {
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=hard ";
            }
            break;
            }

            // TODO make this an option.
            result += "-ffunction-sections -fdata-sections ";

            switch (settings.CompileSettings.Optimization)
            {
            case OptimizationLevel.None:
            {
                result += "-O0 ";
            }
            break;

            case OptimizationLevel.Debug:
            {
                result += "-O0 ";
            }
            break;

            case OptimizationLevel.Level1:
            {
                result += "-O1 ";
            }
            break;

            case OptimizationLevel.Level2:
            {
                result += "-O2 ";
            }
            break;

            case OptimizationLevel.Level3:
            {
                result += "-O3 ";
            }
            break;

            case OptimizationLevel.Size:
            {
                result += "-Os ";
            }
            break;

            case OptimizationLevel.Speed:
            {
                result += "-Ofast ";
            }
            break;
            }

            result += settings.CompileSettings.CustomFlags + " ";

            // Referenced includes
            var referencedIncludes = project.GetReferencedIncludes();

            referencedIncludes.Select(s => result += $"-I\"{ Path.Combine(project.CurrentDirectory, s)}\" ").ToList();

            // global includes
            var globalIncludes = superProject.GetGlobalIncludes();

            globalIncludes.Select(s => result += $"-I\"{s}\" ").ToList();

            // includes
            project.Includes.Select(s => result += $"-I\"{ Path.Combine(project.CurrentDirectory, s.Value)}\" ").ToList();

            var referencedDefines = project.GetReferencedDefines();

            referencedDefines.Select(s => result += $"-D{s} ").ToList();

            var toolchainIncludes = GetToolchainIncludes(file);

            toolchainIncludes.Select(s => result += $"-isystem\"{s}\" ").ToList();

            // global includes
            var globalDefines = superProject.GetGlobalDefines();

            globalDefines.Select(s => result += $"-D{s} ").ToList();

            project.Defines.Select(s => result += $"-D{s.Value} ").ToList();

            superProject.ToolChainArguments.Select(s => result += $" {s}").ToList();

            superProject.CompilerArguments.Select(s => result += $" {s}").ToList();

            // TODO factor out this code from here!
            if (file != null)
            {
                switch (file.Extension)
                {
                case ".c":
                {
                    superProject.CCompilerArguments.Select(s => result += $" {s}");
                }
                break;

                case ".cpp":
                {
                    superProject.CppCompilerArguments.Select(s => result += $" {s}");
                }
                break;
                }
            }

            return(result);
        }
Beispiel #8
0
        public override string GetCompilerArguments(IStandardProject superProject, IStandardProject project, ISourceFile file)
        {
            var result = string.Empty;

            var settings = superProject.GetToolchainSettings <GccToolchainSettings>();

            result += "-Wall -c -fshort-enums ";

            if (settings.CompileSettings.DebugInformation)
            {
                result += "-g ";
            }

            if (file == null || file.Extension == ".cpp")
            {
                switch (settings.CompileSettings.CppLanguageStandard)
                {
                case CppLanguageStandard.Cpp98:
                    result += "-std=c++98 ";
                    break;

                case CppLanguageStandard.Cpp03:
                    result += "-std=c++03 ";
                    break;

                case CppLanguageStandard.Cpp11:
                    result += "-std=c++11 ";
                    break;

                case CppLanguageStandard.Cpp14:
                    result += "-std=c++14 ";
                    break;

                case CppLanguageStandard.Cpp17:
                    result += "-std=c++17 ";
                    break;

                case CppLanguageStandard.Gnu11:
                    result += "-std=gnu++11 ";
                    break;

                case CppLanguageStandard.Gnu14:
                    result += "-std=gnu++14 ";
                    break;

                default:
                    break;
                }
            }

            if (file == null || file.Extension == ".c")
            {
                switch (settings.CompileSettings.CLanguageStandard)
                {
                case CLanguageStandard.C89:
                    result += "-std=c89 ";
                    break;

                case CLanguageStandard.C99:
                    result += "-std=c99 ";
                    break;

                case CLanguageStandard.C11:
                    result += "-std=c11 ";
                    break;
                }
            }

            switch (settings.CompileSettings.Fpu)
            {
            case FPUSupport.Soft:
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=soft ";
                break;

            case FPUSupport.Hard:
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=hard ";
                break;
            }

            // TODO remove dependency on file?
            if (file != null)
            {
                if (file.Extension == ".cpp")
                {
                    if (!settings.CompileSettings.Rtti)
                    {
                        result += "-fno-rtti ";
                    }

                    if (!settings.CompileSettings.Exceptions)
                    {
                        result += "-fno-exceptions ";
                    }
                }
            }

            switch (settings.CompileSettings.Fpu)
            {
            case FPUSupport.Soft:
            {
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=soft ";
            }
            break;

            case FPUSupport.Hard:
            {
                result += "-mfpu=fpv4-sp-d16 -mfloat-abi=hard ";
            }
            break;
            }

            // TODO make this an option.
            result += "-ffunction-sections -fdata-sections ";

            switch (settings.CompileSettings.Optimization)
            {
            case OptimizationLevel.None:
            {
                result += "-O0 ";
            }
            break;

            case OptimizationLevel.Debug:
            {
                result += "-Og ";
            }
            break;

            case OptimizationLevel.Level1:
            {
                result += "-O1 ";
            }
            break;

            case OptimizationLevel.Level2:
            {
                result += "-O2 ";
            }
            break;

            case OptimizationLevel.Level3:
            {
                result += "-O3 ";
            }
            break;

            case OptimizationLevel.Size:
            {
                result += "-Os ";
            }
            break;

            case OptimizationLevel.Speed:
            {
                result += "-Ofast ";
            }
            break;
            }

            result += settings.CompileSettings.CustomFlags + " ";

            // toolchain includes

            // Referenced includes
            var referencedIncludes = project.GetReferencedIncludes();

            foreach (var include in referencedIncludes)
            {
                result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include));
            }

            // global includes
            var globalIncludes = superProject.GetGlobalIncludes();

            foreach (var include in globalIncludes)
            {
                result += string.Format("-I\"{0}\" ", include);
            }

            // includes
            foreach (var include in project.Includes)
            {
                result += string.Format("-I\"{0}\" ", Path.Combine(project.CurrentDirectory, include.Value));
            }

            var referencedDefines = project.GetReferencedDefines();

            foreach (var define in referencedDefines)
            {
                result += string.Format("-D{0} ", define);
            }

            // global includes
            var globalDefines = superProject.GetGlobalDefines();

            foreach (var define in globalDefines)
            {
                result += string.Format("-D{0} ", define);
            }

            foreach (var define in project.Defines)
            {
                result += string.Format("-D{0} ", define.Value);
            }

            foreach (var arg in superProject.ToolChainArguments)
            {
                result += string.Format(" {0}", arg);
            }

            foreach (var arg in superProject.CompilerArguments)
            {
                result += string.Format(" {0}", arg);
            }

            // TODO factor out this code from here!
            if (file != null)
            {
                switch (file.Extension)
                {
                case ".c":
                {
                    foreach (var arg in superProject.CCompilerArguments)
                    {
                        result += string.Format(" {0}", arg);
                    }
                }
                break;

                case ".cpp":
                {
                    foreach (var arg in superProject.CppCompilerArguments)
                    {
                        result += string.Format(" {0}", arg);
                    }
                }
                break;
                }
            }

            return(result);
        }
Beispiel #9
0
        public override LinkResult Link(IConsole console, IStandardProject superProject, IStandardProject project, CompileResult assemblies, string outputPath)
        {
            var result = new LinkResult();

            string commandName = project.Type == ProjectType.StaticLibrary ? ARExecutable : LDExecutable;

            var objectArguments = string.Empty;

            foreach (var obj in assemblies.ObjectLocations)
            {
                objectArguments += obj + " ";
            }

            var libs = string.Empty;

            foreach (var lib in assemblies.LibraryLocations)
            {
                libs += lib + " ";
            }

            var outputDir = Path.GetDirectoryName(outputPath);

            if (!Directory.Exists(outputDir))
            {
                Directory.CreateDirectory(outputDir);
            }

            var outputName = Path.GetFileName(outputPath);

            if (project.Type == ProjectType.StaticLibrary)
            {
                outputName = Path.GetFileName(outputPath);
            }

            var executable = Path.Combine(outputDir, outputName);

            var linkedLibraries = string.Empty;

            foreach (var libraryPath in project.StaticLibraries)
            {
                var relativePath = Path.GetDirectoryName(libraryPath);

                var libName = Path.GetFileNameWithoutExtension(libraryPath).Substring(3);

                linkedLibraries += string.Format("-L\"{0}\" -l{1} ", relativePath, libName);
            }

            string libraryPaths = string.Empty;

            var linkerScripts = string.Empty;

            if (project.Type == ProjectType.Executable)
            {
                var settings = project.GetToolchainSettings <GccToolchainSettings>();

                foreach (var libraryPath in settings.LinkSettings.LinkedLibraries)
                {
                    libraryPaths += $"-Wl,--library-path={Path.Combine(project.CurrentDirectory, Path.GetDirectoryName(libraryPath)).ToPlatformPath()} ";

                    var libName = Path.GetFileName(libraryPath);

                    linkedLibraries += string.Format($"-Wl,--library=:{libName} ");
                }

                foreach (var script in settings.LinkSettings.LinkerScripts)
                {
                    linkerScripts += $"-Wl,-T\"{Path.Combine(project.CurrentDirectory, script)}\" ";
                }

                foreach (var lib in settings.LinkSettings.SystemLibraries)
                {
                    linkedLibraries += $"-l{lib} ";
                }
            }

            foreach (var lib in project.BuiltinLibraries)
            {
                linkedLibraries += $"-l{lib} ";
            }

            linkedLibraries += GetBaseLibraryArguments(superProject);

            string arguments = string.Empty;

            if (project.Type == ProjectType.StaticLibrary)
            {
                arguments = string.Format("rvs {0} {1}", executable, objectArguments);
            }
            else
            {
                var environment = superProject.GetEnvironmentVariables().AppendRange(Platform.EnvironmentVariables);
                arguments = string.Format("{0} {1} -o{2} {3} {4} -Wl,--start-group {5} {6} -Wl,--end-group", GetLinkerArguments(superProject, project).ExpandVariables(environment), linkerScripts, executable, objectArguments, libraryPaths, linkedLibraries, libs);
            }

            result.ExitCode = PlatformSupport.ExecuteShellCommand(commandName, arguments, (s, e) =>
            {
                if (e.Data != null)
                {
                    console.WriteLine(e.Data);
                }
            },
                                                                  (s, e) =>
            {
                if (e.Data != null && !e.Data.Contains("creating"))
                {
                    console.WriteLine(e.Data);
                }
            }, false, project.Solution.CurrentDirectory, false, RunWithSystemPaths);

            if (Shell.DebugMode)
            {
                console.WriteLine(Path.GetFileNameWithoutExtension(commandName) + " " + arguments);
            }

            if (result.ExitCode == 0)
            {
                result.Executable = executable;
            }

            return(result);
        }