docs: fix case of mruby
[mruby.git] / lib / mruby / build / command.rb
blobc93d08ea79ef75368c7027d483ba791cb97b3057
1 require 'forwardable'
3 module MRuby
4   class Command
5     include Rake::DSL
6     extend Forwardable
7     def_delegators :@build, :filename, :objfile, :libfile, :exefile
8     attr_accessor :build, :command
10     def initialize(build)
11       @build = build
12     end
14     # clone is deep clone without @build
15     def clone
16       target = super
17       excepts = %w(@build)
18       instance_variables.each do |attr|
19         unless excepts.include?(attr.to_s)
20           val = Marshal::load(Marshal.dump(instance_variable_get(attr))) # deep clone
21           target.instance_variable_set(attr, val)
22         end
23       end
24       target
25     end
27     def shellquote(s)
28       if ENV['OS'] == 'Windows_NT'
29         "\"#{s}\""
30       else
31         "#{s}"
32       end
33     end
35     private
36     def _run(options, params={})
37       sh "#{build.filename(command)} #{options % params}"
38     end
39   end
41   class Command::Compiler < Command
42     attr_accessor :label, :flags, :include_paths, :defines, :source_exts
43     attr_accessor :compile_options, :option_define, :option_include_path, :out_ext
44     attr_accessor :cxx_compile_flag, :cxx_exception_flag, :cxx_invalid_flags
45     attr_writer :preprocess_options
47     def initialize(build, source_exts=[], label: "CC")
48       super(build)
49       @command = ENV['CC'] || 'cc'
50       @label = label
51       @flags = [ENV['CFLAGS'] || []]
52       @source_exts = source_exts