1 MRuby::Toolchain.new(:gcc) do |conf, params|
2 default_command = params[:default_command] || 'gcc'
3 compiler_flags = %w(-g -O3 -Wall -Wundef)
4 c_mandatory_flags = %w(-std=gnu99)
5 cxx_invalid_flags = %w(-Wdeclaration-after-statement -Werror-implicit-function-declaration)
7 [conf.cc, conf.objc, conf.asm, conf.cxx].each do |compiler|
8 if compiler == conf.cxx
9 compiler.command = ENV['CXX'] || default_command.sub(/cc|$/, '++')
10 compiler.flags = [ENV['CXXFLAGS'] || ENV['CFLAGS'] || compiler_flags]
12 compiler.command = ENV['CC'] || default_command
13 compiler.flags = [c_mandatory_flags, ENV['CFLAGS'] || [compiler_flags, cxx_invalid_flags, %w(-Wwrite-strings)]]
15 compiler.option_include_path = %q[-I"%s"]
16 compiler.option_define = '-D%s'
17 compiler.compile_options = %q[%{flags} -MMD -o "%{outfile}" -c "%{infile}"]
18 compiler.cxx_compile_flag = '-x c++ -std=gnu++03'
19 compiler.cxx_exception_flag = '-fexceptions'
20 compiler.cxx_invalid_flags = c_mandatory_flags + cxx_invalid_flags
23 conf.linker do |linker|
24 linker.command = ENV['LD'] || ENV['CXX'] || ENV['CC'] || default_command
25 linker.flags = [ENV['LDFLAGS'] || %w()]
26 linker.libraries = %w(m)
27 linker.library_paths = []
28 linker.option_library = '-l%s'
29 linker.option_library_path = '-L%s'
30 linker.link_options = '%{flags} -o "%{outfile}" %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}'
33 [[conf.cc, 'c'], [conf.cxx, 'c++']].each do |cc, lang|
34 cc.instance_variable_set :@header_search_language, lang
35 def cc.header_search_paths
36 if @header_search_command != command
37 result = `echo | #{build.filename command} -x#{@header_search_language} -Wp,-v - -fsyntax-only 2>&1`
38 result = `echo | #{command} -x#{@header_search_language} -Wp,-v - -fsyntax-only 2>&1` if $?.exitstatus != 0
39 return include_paths if $?.exitstatus != 0
42 @header_search_paths = result.lines.map { |v|
43 framework = v.match(/^ (.*)(?: \(framework directory\))$/)
45 @frameworks << framework[1]
50 }.compact.map { |v| v[1] }.select { |v| File.directory? v }
51 @header_search_paths += include_paths
52 @header_search_command = command
58 def conf.enable_sanitizer(*opts)
59 fail 'sanitizer already set' if @sanitizer_list
61 @sanitizer_list = opts
62 flg = "-fsanitize=#{opts.join ','}"
63 [self.cc, self.cxx, self.linker].each{|cmd| cmd.flags << flg }