mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Implement header search for gcc and clang.
This commit is contained in:
@@ -54,6 +54,18 @@ module MRuby
|
||||
@compile_options = '%{flags} -o %{outfile} -c %{infile}'
|
||||
end
|
||||
|
||||
alias header_search_paths include_paths
|
||||
def search_header_path(name)
|
||||
header_search_paths.find do |v|
|
||||
File.exist? build.filename("#{v}/#{name}").sub(/^"(.*)"$/, '\1')
|
||||
end
|
||||
end
|
||||
|
||||
def search_header(name)
|
||||
path = search_header_path name
|
||||
path && build.filename("#{path}/#{name}").sub(/^"(.*)"$/, '\1')
|
||||
end
|
||||
|
||||
def all_flags(_defineds=[], _include_paths=[], _flags=[])
|
||||
define_flags = [defines, _defineds].flatten.map{ |d| option_define % d }
|
||||
include_path_flags = [include_paths, _include_paths].flatten.map do |f|
|
||||
|
||||
@@ -28,4 +28,28 @@ MRuby::Toolchain.new(:gcc) do |conf|
|
||||
linker.option_library_path = '-L%s'
|
||||
linker.link_options = '%{flags} -o %{outfile} %{objs} %{flags_before_libraries} %{libs} %{flags_after_libraries}'
|
||||
end
|
||||
|
||||
[[conf.cc, 'c'], [conf.cxx, 'c++']].each do |cc, lang|
|
||||
cc.define_singleton_method(:header_search_paths) do
|
||||
if @header_search_command != command
|
||||
result = `echo | #{build.filename command} -x#{lang} -Wp,-v - -fsyntax-only 2>&1`
|
||||
result = `echo | #{command} -x#{lang} -Wp,-v - -fsyntax-only 2>&1` if $?.exitstatus != 0
|
||||
return include_paths if $?.exitstatus != 0
|
||||
|
||||
@frameworks = []
|
||||
@header_search_paths = result.lines.map { |v|
|
||||
framework = v.match(/^ (.*)(?: \(framework directory\))$/)
|
||||
if framework
|
||||
@frameworks << framework[1]
|
||||
next nil
|
||||
end
|
||||
|
||||
v.match(/^ (.*)$/)
|
||||
}.compact.map { |v| v[1] }.select { |v| File.directory? v }
|
||||
@header_search_paths += include_paths
|
||||
@header_search_command = command
|
||||
end
|
||||
@header_search_paths
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user