Class: Magica::Command::Compiler
- Inherits:
-
Magica::Command
- Object
- Magica::Command
- Magica::Command::Compiler
- Defined in:
- lib/magica/commands/compiler.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#flags ⇒ Object
Returns the value of attribute flags.
Attributes inherited from Magica::Command
Instance Method Summary collapse
- #combine_flags(defines = [], include_paths = [], flags = []) ⇒ Object
-
#initialize(build, source_exts = []) ⇒ Compiler
constructor
A new instance of Compiler.
- #run(outfile, infile, defines = [], include_paths = [], flags = []) ⇒ Object
Constructor Details
#initialize(build, source_exts = []) ⇒ Compiler
Returns a new instance of Compiler.
8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/magica/commands/compiler.rb', line 8 def initialize(build, source_exts = []) super(build) @command = ENV['CC'] || 'cc' @flags = [ENV['CFLAGS'] || []] @source_exts = source_exts @compile_options = '%{flags} -o %{outfile} -c %{infile}' @include_paths = ['include'] @defines = %w[] @option_include_path = '-I%s' @option_defines = '-D%s' end |
Instance Attribute Details
#flags ⇒ Object
Returns the value of attribute flags.
6 7 8 |
# File 'lib/magica/commands/compiler.rb', line 6 def flags @flags end |
Instance Method Details
#combine_flags(defines = [], include_paths = [], flags = []) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/magica/commands/compiler.rb', line 22 def combine_flags(defines = [], include_paths = [], flags = []) define_flags = [ @defines, defines ].flatten.map { |define| @option_defines % define } include_path_flags = [ @include_paths, include_paths ].flatten.map do |include_path| @option_include_path % filename(include_path) end [define_flags, include_path_flags, flags].flatten.uniq.join(' ') end |
#run(outfile, infile, defines = [], include_paths = [], flags = []) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/magica/commands/compiler.rb', line 34 def run(outfile, infile, defines = [], include_paths = [], flags = []) FileUtils.mkdir_p File.dirname(outfile) puts "COMPILE\t#{outfile}" _run(@compile_options, outfile: outfile, infile: infile, flags: combine_flags(defines, include_paths, flags)) end |