Class: Shog::CC

Inherits:
Object show all
Defined in:
lib/rule/cc.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCC

Returns a new instance of CC.



11
12
13
14
15
# File 'lib/rule/cc.rb', line 11

def initialize
  @cflags = []
  @includes = PathSet.new
  @implicit_input = PathSet.new
end

Instance Attribute Details

#binObject

Returns the value of attribute bin.



5
6
7
# File 'lib/rule/cc.rb', line 5

def bin
  @bin
end

#cflagsObject

Returns the value of attribute cflags.



5
6
7
# File 'lib/rule/cc.rb', line 5

def cflags
  @cflags
end

#implicit_inputObject

Returns the value of attribute implicit_input.



5
6
7
# File 'lib/rule/cc.rb', line 5

def implicit_input
  @implicit_input
end

#includesObject

Returns the value of attribute includes.



5
6
7
# File 'lib/rule/cc.rb', line 5

def includes
  @includes
end

Instance Method Details

#idObject



7
8
9
# File 'lib/rule/cc.rb', line 7

def id
  :cc
end

#ruleObject



17
18
19
20
21
22
23
24
# File 'lib/rule/cc.rb', line 17

def rule
  {
    "command" => "$bin $cflags -MMD -MQ $out -MF $out.d -c $in -o $out",
    "description" => "Compile $in",
    "deps" => "gcc",
    "depfile" => "$out.d",
  }
end

#target(params) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rule/cc.rb', line 26

def target(params)
  input = PathSet.new
  input << params[:input]

  output = PathSet.new
  if params[:output]
    output << Path.make(params[:output], :outoftree => true)
  else
    output << Path.make(params[:input].single_path, :outoftree => true).with_suffix(".o")
  end

  cflags = @cflags.dup
  cflags << params[:cflags] if params[:cflags]
  cflags += @includes.map { |i| "-I" + i }
  includes = params[:includes]
  if includes
    includes = PathSet.make(includes)
    cflags += includes.map { |i| "-I" + i }
  end

  variables = {
    "cflags" => cflags.join(" "),
    "bin" => params[:bin] || @bin || "gcc",
  }
  implicit_input = @implicit_input.dup
  implicit_input += params[:implicit_input] if params[:implicit_input]
  {:rule => "cc", :input => input, :implicit_input => implicit_input, :output => output, :variables => variables}
end