diff --git a/build_config.rb b/build_config.rb index 8293092abe..58ee38b57d 100644 --- a/build_config.rb +++ b/build_config.rb @@ -1,12 +1,18 @@ -MRuby::Build.new do |conf| - # load specific toolchain settings - - # Gets set by the VS command prompts. +def detect_toolchain if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] - toolchain :visualcpp + :visualcpp else - toolchain :gcc + cc = ENV['CC'] || 'cc' + if `#{cc} --version 2>&1` =~ /clang/i + :clang + else + :gcc + end end +end + +MRuby::Build.new do |conf| + toolchain detect_toolchain enable_debug @@ -85,14 +91,7 @@ end MRuby::Build.new('host-debug') do |conf| - # load specific toolchain settings - - # Gets set by the VS command prompts. - if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] - toolchain :visualcpp - else - toolchain :gcc - end + toolchain detect_toolchain enable_debug @@ -110,12 +109,7 @@ end MRuby::Build.new('test') do |conf| - # Gets set by the VS command prompts. - if ENV['VisualStudioVersion'] || ENV['VSINSTALLDIR'] - toolchain :visualcpp - else - toolchain :gcc - end + toolchain detect_toolchain enable_debug conf.enable_bintest diff --git a/tasks/toolchains/gcc.rake b/tasks/toolchains/gcc.rake index f370c0abf3..76022740b8 100644 --- a/tasks/toolchains/gcc.rake +++ b/tasks/toolchains/gcc.rake @@ -24,7 +24,7 @@ MRuby::Toolchain.new(:gcc) do |conf, _params| conf.linker do |linker| linker.command = ENV['LD'] || 'gcc' linker.flags = [ENV['LDFLAGS'] || %w()] - linker.libraries = %w(m) + linker.libraries = RUBY_PLATFORM =~ /darwin/ ? %w() : %w(m) linker.library_paths = [] linker.option_library = '-l%s' linker.option_library_path = '-L%s'