Class: Magica::Builder
- Includes:
- Rake::DSL
- Defined in:
- lib/magica/builder.rb
Constant Summary collapse
- COMPILERS =
%w(cxx)
- COMMANDS =
COMPILERS + %w(linker)
Instance Method Summary collapse
- #compile(source) ⇒ Object
- #define(name) ⇒ Object
- #exefile(name) ⇒ Object
- #filename(name) ⇒ Object
- #flag(flag) ⇒ Object
- #include_path(path) ⇒ Object
-
#initialize(name = 'host', dest = 'build', &block) ⇒ Builder
constructor
A new instance of Builder.
- #libfile ⇒ Object
- #library(name, path) ⇒ Object
- #link(exec, objects) ⇒ Object
- #objfile(name) ⇒ Object
- #source(path) ⇒ Object
- #toolchain(name, params = {}) ⇒ Object
Constructor Details
#initialize(name = 'host', dest = 'build', &block) ⇒ Builder
Returns a new instance of Builder.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/magica/builder.rb', line 10 def initialize(name = 'host', dest = 'build', &block) @name = name.to_s @dest = dest.to_s @sources = FileList["src/**/*.cpp"] @cxx = Command::Compiler.new(self, %w(.cpp)) @linker = Command::Linker.new(self) @defines = %w() @include_paths = %w() @libaries = %w() @libary_paths = %w() @flags = %w() Magica.targets[@name] = self Magica.targets[@name].instance_eval(&block) unless block.nil? Magica.default_toolchain.setup(self, Magica.toolchain_params) if Magica.default_toolchain end |
Instance Method Details
#compile(source) ⇒ Object
78 79 80 81 82 |
# File 'lib/magica/builder.rb', line 78 def compile(source) file objfile(source) => source do |t| @cxx.run t.name, t.prerequisites.first, @defines, @include_paths, @flags end end |
#define(name) ⇒ Object
28 29 30 |
# File 'lib/magica/builder.rb', line 28 def define(name) @defines << name.to_s.upcase end |
#exefile(name) ⇒ Object
53 54 55 56 57 58 59 |
# File 'lib/magica/builder.rb', line 53 def exefile(name) if name.is_a?(Array) name.flatten.map { |n| exefile(n) } else "#{name}" end end |
#filename(name) ⇒ Object
49 50 51 |
# File 'lib/magica/builder.rb', line 49 def filename(name) '"%s"' % name end |
#flag(flag) ⇒ Object
36 37 38 |
# File 'lib/magica/builder.rb', line 36 def flag(flag) @flags << flag.to_s end |
#include_path(path) ⇒ Object
32 33 34 |
# File 'lib/magica/builder.rb', line 32 def include_path(path) @include_paths << path.to_s end |
#libfile ⇒ Object
61 62 |
# File 'lib/magica/builder.rb', line 61 def libfile end |
#library(name, path) ⇒ Object
40 41 42 43 |
# File 'lib/magica/builder.rb', line 40 def library(name, path) @libaries << name.to_s @libary_paths << path.to_s end |
#link(exec, objects) ⇒ Object
84 85 86 87 88 |
# File 'lib/magica/builder.rb', line 84 def link(exec, objects) task "build:#{@name}" => objects do @linker.run "#{exec}", objects, @libaries, @libary_paths, @flags end end |
#objfile(name) ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/magica/builder.rb', line 64 def objfile(name) if name.is_a?(Array) name.flatten.map { |n| objfile(n) } else "#{@dest}/#{name}.o" end end |
#source(path) ⇒ Object
45 46 47 |
# File 'lib/magica/builder.rb', line 45 def source(path) @sources = FileList[path] end |