class Makefile::Rule
The Rule
class defines a single Makefile
rule.
@see www.gnu.org/software/make/manual/make.html#Rule-Introduction
Attributes
dependencies[RW]
@!attribute [rw] dependencies
@return [Array<String>] A list of dependencies that this rule depends on.
recipe[RW]
@!attribute [rw] recipe
@return [Array<String>] A list of commands to execute upon invocation of this rule.
target[RW]
@!attribute [rw] target
@return [String] The target generated by this rule.
Public Class Methods
new(target, dependencies: [], recipe: []) { |self| ... }
click to toggle source
Create a new Makefile
rule. When a block is provided then it is called and passed the newly created Rule
object.
@overload initialize(target, dependencies: [], recipe: [])
@param target [String] target @param dependencies [Array<String>]] @param recipe [Array<String>]
@overload initialize(target, dependencies: [], recipe: [], &block)
@param target [String] target @param dependencies [Array<String>]] @param recipe [Array<String>] @yieldparam rule [Makefile::Rule] @example Providing a block to #initialize newrule = Makefile::Rule.new("test", dependencies: ["all"]) do |rule| rule.recipe = [ "make test", "make cpplint", ] end
# File lib/makefile.rb, line 39 def initialize(target, dependencies: [], recipe: [], &block) @target = target @dependencies = dependencies @recipe = recipe yield(self) if block end
Public Instance Methods
base_target()
click to toggle source
compounded_recipe()
click to toggle source
# File lib/makefile.rb, line 60 def compounded_recipe Array(recipe) .compact .map { |line| "\t#{line.gsub("\n", "\n\t")}\n" } .join end
flatten_dependencies()
click to toggle source
@return [String, Nil] the name of all dependencies for a given rule,
flattened and joined for a Makefule target
# File lib/makefile.rb, line 49 def flatten_dependencies return nil if dependencies.empty? dependencies.flatten.join("\s") end
format()
click to toggle source
Format this rule as a Makefile
rule.
Recipes that have multiline statements will have tabs inserted after each newline to ensure that the recipe is parsed as part of a single makefile rule.
@return [String]
# File lib/makefile.rb, line 73 def format [base_target, compounded_recipe].flatten.join("\n") end
Also aliased as: to_s