Class: MTBuild::ToolchainGcc
- Includes:
- DSL
- Defined in:
- lib/mtbuild/toolchains/gcc.rb
Overview
This Toolchain subclass can build using GCC
Direct Known Subclasses
Instance Attribute Summary collapse
-
#asflags ⇒ Object
Returns the value of attribute asflags.
-
#cflags ⇒ Object
Returns the value of attribute cflags.
-
#cppflags ⇒ Object
Returns the value of attribute cppflags.
-
#cxxflags ⇒ Object
Returns the value of attribute cxxflags.
-
#ldflags ⇒ Object
Returns the value of attribute ldflags.
-
#linker_script ⇒ Object
Returns the value of attribute linker_script.
Attributes inherited from Toolchain
#output_decorator, #output_folder, #parent_configuration, #project_folder
Instance Method Summary collapse
-
#create_application_tasks(objects, executable_name) ⇒ Object
Create Rake tasks for linking.
-
#create_compile_tasks(source_files) ⇒ Object
Create Rake tasks for compilation.
-
#create_static_library_tasks(objects, library_name) ⇒ Object
Create Rake tasks for archival.
-
#initialize(parent_configuration, toolchain_configuration) ⇒ ToolchainGcc
constructor
A new instance of ToolchainGcc.
- #scan_sources(source_files) ⇒ Object
Methods included from DSL
#application_project, #framework_project, #mtfile, #static_library_project, #test_application_project, #toolchain, #workspace
Methods inherited from Toolchain
#add_include_objects, #add_include_paths, #add_library_paths, #get_include_objects, #get_include_paths, #get_library_paths
Methods included from Rake::DSL
#application_task, #framework_task, #static_library_task, #test_application_task
Constructor Details
#initialize(parent_configuration, toolchain_configuration) ⇒ ToolchainGcc
Returns a new instance of ToolchainGcc.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 14 def initialize(parent_configuration, toolchain_configuration) super @tracked_folders = [] begin toolchain_test_output=%x{#{compiler_c} --version 2>&1} toolchain_test_passed=$?.success? rescue toolchain_test_passed = false end fail "Toolchain component #{compiler_c} not found." unless toolchain_test_passed @compiler_is_LLVM_gcc = toolchain_test_output.include?'LLVM' @link_as_cpp = false @cppflags = Utils.ensure_array(toolchain_configuration.fetch(:cppflags, '')).to_a.flatten.join(' ') @cflags = Utils.ensure_array(toolchain_configuration.fetch(:cflags, '')).to_a.flatten.join(' ') @cxxflags = Utils.ensure_array(toolchain_configuration.fetch(:cxxflags, '')).to_a.flatten.join(' ') @asflags = Utils.ensure_array(toolchain_configuration.fetch(:asflags, '')).to_a.flatten.join(' ') @ldflags = Utils.ensure_array(toolchain_configuration.fetch(:ldflags, '')).to_a.flatten.join(' ') @linker_script = toolchain_configuration.fetch(:linker_script, '') end |
Instance Attribute Details
#asflags ⇒ Object
Returns the value of attribute asflags.
12 13 14 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 12 def asflags @asflags end |
#cflags ⇒ Object
Returns the value of attribute cflags.
12 13 14 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 12 def cflags @cflags end |
#cppflags ⇒ Object
Returns the value of attribute cppflags.
12 13 14 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 12 def cppflags @cppflags end |
#cxxflags ⇒ Object
Returns the value of attribute cxxflags.
12 13 14 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 12 def cxxflags @cxxflags end |
#ldflags ⇒ Object
Returns the value of attribute ldflags.
12 13 14 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 12 def ldflags @ldflags end |
#linker_script ⇒ Object
Returns the value of attribute linker_script.
12 13 14 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 12 def linker_script @linker_script end |
Instance Method Details
#create_application_tasks(objects, executable_name) ⇒ Object
Create Rake tasks for linking
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 101 def create_application_tasks(objects, executable_name) elf_file = File.join(@output_folder, "#{executable_name}#{@output_decorator}") map_file = File.join(@output_folder, "#{executable_name}#{@output_decorator}.map") executable_folder = @output_folder unless @tracked_folders.include?executable_folder @tracked_folders << executable_folder directory executable_folder @parent_configuration.parent_project.add_files_to_clean(executable_folder) end @parent_configuration.parent_project.add_files_to_clean(map_file, elf_file) all_objects = objects+get_include_objects file elf_file => all_objects do |t| command_line = construct_link_command(all_objects, t.name, get_include_paths, get_library_paths, map_file) sh command_line end file map_file => elf_file return [elf_file], [map_file], [executable_folder] end |
#create_compile_tasks(source_files) ⇒ Object
Create Rake tasks for compilation
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 42 def create_compile_tasks(source_files) object_files = [] object_folders = [] source_files.each do |source_file| relative_source_location = Utils::path_difference(@project_folder, File.dirname(source_file)) fail "Source file #{source_file} must be within #{@project_folder}." if relative_source_location.nil? output_folder = File.join(@output_folder, relative_source_location) object_folders << output_folder unless object_folders.include?output_folder unless @tracked_folders.include?output_folder @tracked_folders << output_folder directory output_folder @parent_configuration.parent_project.add_files_to_clean(output_folder) end object_file = File.join(output_folder, source_file.pathmap('%n.o')) dependency_file = File.join(output_folder, source_file.pathmap('%n.d')) object_files << object_file @parent_configuration.parent_project.add_files_to_clean(object_file, dependency_file) file_type = get_file_type(source_file) mtfile object_file => [source_file] do |t| command_line = construct_compile_command(file_type, [source_file], get_include_paths, t.name) sh command_line end # Load dependencies if the dependencies file exists and the object file is not already scheduled to be rebuilt if File.file?(dependency_file) and not Rake::Task[object_file].needed? Rake::Task[object_file].force_needed() if not MTBuild::MakefileLoader.new.load(dependency_file) end end return object_files, object_folders end |
#create_static_library_tasks(objects, library_name) ⇒ Object
Create Rake tasks for archival
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 81 def create_static_library_tasks(objects, library_name) library_file = File.join(@output_folder, "lib#{library_name}#{@output_decorator}.a") library_folder = @output_folder unless @tracked_folders.include?library_folder @tracked_folders << library_folder directory library_folder @parent_configuration.parent_project.add_files_to_clean(library_folder) end @parent_configuration.parent_project.add_files_to_clean(library_file) file library_file => objects do |t| command_line = construct_archive_command(objects, t.name) sh command_line end return [library_file], [library_folder] end |
#scan_sources(source_files) ⇒ Object
37 38 39 |
# File 'lib/mtbuild/toolchains/gcc.rb', line 37 def scan_sources(source_files) @link_as_cpp = source_files.any? { |s| get_file_type(s)==:cplusplus } end |