Class: Bake::Blocks::Makefile

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

Constant Summary collapse

MAKE_COMMAND =
"make"
MAKE_FILE_FLAG =
"-f"
MAKE_DIR_FLAG =
"-C"
MAKE_CLEAN =
"clean"

Instance Attribute Summary

Attributes included from HasExecuteCommand

#config

Instance Method Summary collapse

Methods included from HasExecuteCommand

#executeCommand

Constructor Details

#initialize(config, referencedConfigs, block) ⇒ Makefile

Returns a new instance of Makefile.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/blocks/makefile.rb', line 14

def initialize(config, referencedConfigs, block)
  @config = config
  @tcs = block.tcs
  @projectDir = config.get_project_dir
  @path_to = ""
  @flags = adjustFlags("",config.flags) if config.flags
  @makefile = config.name
  @target = config.target != "" ? config.target : "all"
  calcPathTo(referencedConfigs)
  calcCommandLine
  calcCleanLine
  calcEnv

  block.lib_elements << LibElement.new(LibElement::LIB_WITH_PATH, config.lib) if config.lib != ""
end

Instance Method Details

#calcCleanLineObject



64
65
66
67
68
69
70
# File 'lib/blocks/makefile.rb', line 64

def calcCleanLine
  @cleanLine = remove_empty_strings_and_join([
    MAKE_COMMAND, MAKE_CLEAN,
    @flags,
    fileAndDir,
    @path_to])
end

#calcCommandLineObject



56
57
58
59
60
61
62
# File 'lib/blocks/makefile.rb', line 56

def calcCommandLine
  @commandLine = remove_empty_strings_and_join([
    MAKE_COMMAND, @target,
    @flags,
    fileAndDir,
    @path_to])
end

#calcEnvObject



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/blocks/makefile.rb', line 30

def calcEnv
  @envs = {}
  [:CPP, :C, :ASM].each do |type|
    compiler = @tcs[:COMPILER][type]
    defs = compiler[:DEFINES].map {|k| "#{compiler[:DEFINE_FLAG]}#{k}"}.join(" ")
    args = [defs, compiler[:FLAGS]].reject(&:empty?).join(" ")
    @envs["BAKE_#{type.to_s}_FLAGS"] = args
    @envs["BAKE_#{type.to_s}_COMMAND"] = compiler[:COMMAND]
  end
  @envs["BAKE_AR_FLAGS"] = @tcs[:ARCHIVER][:FLAGS]
  @envs["BAKE_LD_FLAGS"] = @tcs[:LINKER][:FLAGS]
  @envs["BAKE_AR_COMMAND"] = @tcs[:ARCHIVER][:COMMAND]
  @envs["BAKE_LD_COMMAND"] = @tcs[:LINKER][:COMMAND]
end

#calcPathTo(referencedConfigs) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/blocks/makefile.rb', line 72

def calcPathTo(referencedConfigs)
  @path_to = ""
  if @config.pathTo != ""
    pathHash = {}
    @config.pathTo.split(",").each do |p|
      nameOfP = p.strip
      dirOfP = nil
      if referencedConfigs.include?nameOfP
        dirOfP = referencedConfigs[nameOfP].first.get_project_dir
      else
        Bake.options.roots.each do |r|
          absIncDir = r.dir+"/"+nameOfP
          if File.exists?(absIncDir)
            dirOfP = absIncDir
            break
          end
        end
      end
      if dirOfP == nil
        Bake.formatter.printError("Project '#{nameOfP}' not found", @config)
        ExitHelper.exit(1)
      end
      pathHash[nameOfP] = File.rel_from_to_project(File.dirname(@projectDir),File.dirname(dirOfP))
    end
    path_to_array = []
    pathHash.each { |k,v| path_to_array << "PATH_TO_#{k}=#{v}" }
    @path_to = path_to_array.join(" ")
  end

end

#cleanObject



127
128
129
# File 'lib/blocks/makefile.rb', line 127

def clean
  return do_clean()
end

#cleanStepObject



131
132
133
# File 'lib/blocks/makefile.rb', line 131

def cleanStep
  return do_clean()
end

#do_cleanObject



121
122
123
124
125
# File 'lib/blocks/makefile.rb', line 121

def do_clean
  return true if Bake.options.linkOnly || @config.noClean
  @envs.each { |k,v| ENV[k] = v }
  return executeCommand(@cleanLine, "No rule to make target 'clean'.", @config.validExitCodes, @config.echo) unless Bake.options.filename
end

#executeObject



109
110
111
# File 'lib/blocks/makefile.rb', line 109

def execute
 return run()
end

#exitStepObject



117
118
119
# File 'lib/blocks/makefile.rb', line 117

def exitStep
  return run()
end

#fileAndDirObject



45
46
47
48
49
50
51
52
53
54
# File 'lib/blocks/makefile.rb', line 45

def fileAndDir
  if @config.changeWorkingDir
    return remove_empty_strings_and_join([
      MAKE_DIR_FLAG,  File.dirname(@makefile),
      MAKE_FILE_FLAG, File.basename(@makefile)])
  else
    return remove_empty_strings_and_join([
      MAKE_FILE_FLAG, @makefile])
  end
end

#runObject



103
104
105
106
107
# File 'lib/blocks/makefile.rb', line 103

def run
  return true if Bake.options.linkOnly
  @envs.each { |k,v| ENV[k] = v }
  return executeCommand(@commandLine, nil, @config.validExitCodes, @config.echo)
end

#startupStepObject



113
114
115
# File 'lib/blocks/makefile.rb', line 113

def startupStep
  return run()
end