Class: MRuby::Command::Linker

Inherits:
MRuby::Command show all
Defined in:
ext/enterprise_script_service/mruby/lib/mruby/build/command.rb

Constant Summary

Constants inherited from MRuby::Command

NotFoundCommands

Instance Attribute Summary collapse

Attributes inherited from MRuby::Command

#build, #command

Instance Method Summary collapse

Methods inherited from MRuby::Command

#clone, #shellquote

Constructor Details

#initialize(build) ⇒ Linker

Returns a new instance of Linker.

[View source]

171
172
173
174
175
176
177
178
179
180
181
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 171

def initialize(build)
  super
  @command = ENV['LD'] || 'ld'
  @flags = (ENV['LDFLAGS'] || [])
  @flags_before_libraries, @flags_after_libraries = [], []
  @libraries = []
  @library_paths = []
  @option_library = %q[-l"%s"]
  @option_library_path = %q[-L"%s"]
  @link_options = %Q[%{flags} -o "%{outfile}" %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}]
end

Instance Attribute Details

#flagsObject

Returns the value of attribute flags.


168
169
170
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 168

def flags
  @flags
end

#flags_after_librariesObject

Returns the value of attribute flags_after_libraries.


168
169
170
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 168

def flags_after_libraries
  @flags_after_libraries
end

#flags_before_librariesObject

Returns the value of attribute flags_before_libraries.


168
169
170
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 168

def flags_before_libraries
  @flags_before_libraries
end

#librariesObject

Returns the value of attribute libraries.


168
169
170
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 168

def libraries
  @libraries
end

#library_pathsObject

Returns the value of attribute library_paths.


168
169
170
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 168

def library_paths
  @library_paths
end

Returns the value of attribute link_options.


169
170
171
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 169

def link_options
  @link_options
end

#option_libraryObject

Returns the value of attribute option_library.


169
170
171
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 169

def option_library
  @option_library
end

#option_library_pathObject

Returns the value of attribute option_library_path.


169
170
171
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 169

def option_library_path
  @option_library_path
end

Instance Method Details

#all_flags(_library_paths = [], _flags = []) ⇒ Object

[View source]

183
184
185
186
187
188
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 183

def all_flags(_library_paths=[], _flags=[])
  library_path_flags = [library_paths, _library_paths].flatten.map do |f|
    option_library_path % filename(f)
  end
  [flags, library_path_flags, _flags].flatten.join(' ')
end

#library_flags(_libraries) ⇒ Object

[View source]

190
191
192
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 190

def library_flags(_libraries)
  [libraries, _libraries].flatten.map{ |d| option_library % d }.join(' ')
end

#run(outfile, objfiles, _libraries = [], _library_paths = [], _flags = [], _flags_before_libraries = [], _flags_after_libraries = []) ⇒ Object

[View source]

194
195
196
197
198
199
200
201
202
203
204
# File 'ext/enterprise_script_service/mruby/lib/mruby/build/command.rb', line 194

def run(outfile, objfiles, _libraries=[], _library_paths=[], _flags=[], _flags_before_libraries=[], _flags_after_libraries=[])
  mkdir_p File.dirname(outfile)
  library_flags = [libraries, _libraries].flatten.map { |d| option_library % d }

  _pp "LD", outfile.relative_path
  _run link_options, { :flags => all_flags(_library_paths, _flags),
                        :outfile => filename(outfile) , :objs => filename(objfiles).map{|f| %Q["#{f}"]}.join(' '),
                        :flags_before_libraries => [flags_before_libraries, _flags_before_libraries].flatten.join(' '),
                        :flags_after_libraries => [flags_after_libraries, _flags_after_libraries].flatten.join(' '),
                        :libs => library_flags.join(' ') }
end