Debian Codegraph @

vendor/mruby-source/tasks/toolchains/gcc.rake

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