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