Class: Comet::Rules::Link

Inherits:
Object
  • Object
show all
Defined in:
lib/comet/rules/link.rb

Instance Method Summary collapse

Constructor Details

#initialize(linker, dependency, libraries, native_sources) ⇒ Link

Returns a new instance of Link.



4
5
6
7
8
9
# File 'lib/comet/rules/link.rb', line 4

def initialize(linker, dependency, libraries, native_sources)
  @linker = linker
  @dependency = dependency
  @libraries = libraries
  @native_sources = native_sources
end

Instance Method Details

#commandsObject



41
42
43
# File 'lib/comet/rules/link.rb', line 41

def commands
  { COMET_LD: 'clang' }
end

#contentsObject



28
29
30
31
32
33
34
35
# File 'lib/comet/rules/link.rb', line 28

def contents
  obj_dependencies = "#{@dependency.target} #{@native_sources.join ' '}"

  [
    "#{target}: #{obj_dependencies} #{@linker.script_ || ''} | #{Comet::TMPDIR}",
    "\t#{clang_link} #{formatted_script} #{formatted_flags.join ' '} -Wl,-Map=#{map_file} -o $@ #{obj_dependencies} #{formatted_libraries}"
  ]
end

#map_fileObject



24
25
26
# File 'lib/comet/rules/link.rb', line 24

def map_file
  target.gsub(/.elf$/, '.map')
end

#rulesObject



37
38
39
# File 'lib/comet/rules/link.rb', line 37

def rules
  [@dependency]
end

#targetObject



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/comet/rules/link.rb', line 11

def target
  @target ||= Comet::Makefile.fingerprint Hash[
    dependency: @dependency.target,
    triple: @linker.triple,
    isa: @linker.isa,
    cpu: @linker.cpu,
    script: @linker.script_,
    libraries: formatted_libraries,
    native_sources: @native_sources,
    flags: formatted_flags
  ], extension: :elf
end