Class: Magica::Command::Linker
- Inherits:
-
Magica::Command
- Object
- Magica::Command
- Magica::Command::Linker
- Defined in:
- lib/magica/commands/linker.rb
Instance Attribute Summary collapse
-
#flags ⇒ Object
Returns the value of attribute flags.
Attributes inherited from Magica::Command
Instance Method Summary collapse
- #combine_flags(_library_paths = [], _flags = []) ⇒ Object
-
#initialize(build) ⇒ Linker
constructor
A new instance of Linker.
- #run(outfile, objects, _libraries = [], _library_paths = [], _flags = []) ⇒ Object
Constructor Details
#initialize(build) ⇒ Linker
Returns a new instance of Linker.
5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/magica/commands/linker.rb', line 5 def initialize(build) super @command = ENV['LD'] || 'ld' @flags = (ENV['LDFLAGS'] || []) @link_options = "%{flags} -o %{outfile} %{objects} %{libs}" @libraries = [] @library_paths = [] @option_library = "-l%s" @option_library_path = "-L%s" end |
Instance Attribute Details
#flags ⇒ Object
Returns the value of attribute flags.
3 4 5 |
# File 'lib/magica/commands/linker.rb', line 3 def flags @flags end |
Instance Method Details
#combine_flags(_library_paths = [], _flags = []) ⇒ Object
18 19 20 21 |
# File 'lib/magica/commands/linker.rb', line 18 def combine_flags(_library_paths = [], _flags = []) library_paths = [@library_paths, _library_paths].flatten.map { |path| @option_library_path % filename(path) } [flags, library_paths, _flags].flatten.uniq.join(" ") end |
#run(outfile, objects, _libraries = [], _library_paths = [], _flags = []) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/magica/commands/linker.rb', line 23 def run(outfile, objects, _libraries = [], _library_paths = [], _flags = []) FileUtils.mkdir_p File.dirname(outfile) library_flags = [@libraries, _libraries].flatten.map { |library| @option_library % library } puts "LINK\t#{outfile}" _run @link_options, { outfile: outfile, objects: objects.join(" "), libs: library_flags.uniq.join(" "), flags: combine_flags(_library_paths, _flags) } end |