Unverified Commit 5592c741 authored by Rory OConnell's avatar Rory OConnell Committed by Yukihiro "Matz" Matsumoto

Remove compiler feature detection

parent fff0f17b
require 'forwardable' require 'forwardable'
require 'tempfile'
module MRuby module MRuby
class Command class Command
...@@ -127,31 +126,6 @@ module MRuby ...@@ -127,31 +126,6 @@ module MRuby
end end
end end
def compiles?(source_text)
infile = Tempfile.new ['', '.c']
infile.write source_text
infile.close
cwd = Dir.pwd
is_success = false
# Change to a tmp dir when compiling so we don't litter compiler artifacts
tmpdir = Dir.mktmpdir
Dir.chdir tmpdir
sh(command, infile.path, verbose: false) { |retval, _| is_success = retval }
infile.delete
Dir.chdir cwd
# Some systems strangely do not allow removing a temp dir after creation
FileUtils.remove_entry(tmpdir) rescue Errno::EACCES
return is_success
end
def has_header?(header_name)
compiles? test_code_template header: header_name
end
def has_function?(function_name, with_header: nil)
compiles? test_code_template function: function_name, header: with_header
end
private private
# #
...@@ -191,46 +165,6 @@ module MRuby ...@@ -191,46 +165,6 @@ module MRuby
end.flatten.uniq end.flatten.uniq
deps << MRUBY_CONFIG deps << MRUBY_CONFIG
end end
def test_code_template(function: nil, header: nil)
preamble = ''
body = ''
if header
preamble += <<-TEMPLATE
#if defined __has_include
#if !__has_include("#{header}")
#error "Header #{header} not found"
#endif
#endif
#include <#{header}>
TEMPLATE
end
if function
preamble += <<-TEMPLATE
#if defined __stub_#{function} || defined __stub___#{function}
#{function} unavailable
#endif
TEMPLATE
# This is how autoconf works when using a function prototype.
body += <<-TEMPLATE
void *a = (void*) &#{function};
long long b = (long long) a;
return (int) b;
TEMPLATE
else
body = 'return 0;'
end
<<-TEMPLATE
#{preamble}
int main(void) {{
#{body}
}}
TEMPLATE
end
end end
class Command::Linker < Command class Command::Linker < Command
......
...@@ -31,8 +31,6 @@ MRuby::Toolchain.new(:gcc) do |conf, params| ...@@ -31,8 +31,6 @@ MRuby::Toolchain.new(:gcc) do |conf, params|
end end
[[conf.cc, 'c'], [conf.cxx, 'c++']].each do |cc, lang| [[conf.cc, 'c'], [conf.cxx, 'c++']].each do |cc, lang|
cc.defines += %w(HAS_MALLOC_TRIM) if cc.has_function? 'malloc_trim', with_header: 'malloc.h'
cc.instance_variable_set :@header_search_language, lang cc.instance_variable_set :@header_search_language, lang
def cc.header_search_paths def cc.header_search_paths
if @header_search_command != command if @header_search_command != command
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment