Class: Makefile

Inherits:
Object
  • Object
show all
Defined in:
lib/makefile.rb

Instance Method Summary collapse

Constructor Details

#initialize(include_makefile) ⇒ Makefile

Returns a new instance of Makefile.



4
5
6
7
8
9
# File 'lib/makefile.rb', line 4

def initialize(include_makefile)
  @include_makefile = include_makefile
  @file = Tempfile.new('makefile')

  write
end

Instance Method Details

#contentsObject



33
34
35
36
37
38
39
# File 'lib/makefile.rb', line 33

def contents
  ".PHONY: print-%\nprint-%:\n\\t@echo '$*=$($*)'\n  contents\nend\n"

#parse(output) ⇒ Object



26
27
28
29
30
31
# File 'lib/makefile.rb', line 26

def parse(output)
  match = output.match /^(\w+)=(.+)/
  if match
    [match[1], match[2]]
  end
end

#run(variable) ⇒ Object



16
17
18
# File 'lib/makefile.rb', line 16

def run(variable)
  `make -f #{@file.path} -f #{@include_makefile} print-#{variable.upcase}`
end

#value(variable) ⇒ Object



20
21
22
23
24
# File 'lib/makefile.rb', line 20

def value(variable)
  output = run variable
  _, value = parse output
  value
end

#writeObject



11
12
13
14
# File 'lib/makefile.rb', line 11

def write
  @file.write contents
  @file.close
end