lib/mkmf/lite.rb in mkmf-lite-0.2.2 vs lib/mkmf/lite.rb in mkmf-lite-0.2.3
- old
+ new
@@ -10,27 +10,32 @@
end
module Mkmf
module Lite
# The version of the mkmf-lite library
- MKMF_LITE_VERSION = '0.2.2'
+ MKMF_LITE_VERSION = '0.2.3'
- @@cpp_command = Config::CONFIG['CC'] || Config::CONFIG['CPP']
- @@cpp_outfile = Config::CONFIG['CPPOUTFILE'] || "-o conftest.i"
+ @@cpp_command = RbConfig::CONFIG['CC'] || RbConfig::CONFIG['CPP']
@@cpp_srcfile = 'conftest.c'
- if Config::CONFIG['LIBS']
- @@cpp_libraries = Config::CONFIG['LIBS'] + Config::CONFIG['LIBRUBYARG']
+ if File::ALT_SEPARATOR && RbConfig::CONFIG['CPP'] =~ /^cl/
+ @@cpp_outfile = '/Feconftest.exe'
else
+ @@cpp_outfile = '-o conftest.exe'
+ end
+
+ if RbConfig::CONFIG['LIBS']
+ @@cpp_libraries = RbConfig::CONFIG['LIBS'] + RbConfig::CONFIG['LIBRUBYARG']
+ else
# TODO: We should adjust this based on OS. For now we're using
# arguments I think you'll typically see set on Linux and BSD.
@@cpp_libraries = "-lrt -ldl -lcrypt -lm"
end
# JRuby, and possibly others
unless @@cpp_command
- case Config::CONFIG['host_os']
+ case RbConfig::CONFIG['host_os']
when /msdos|mswin|win32|windows|mingw|cygwin/i
@@cpp_command = File.which('cl') || File.which('gcc')
when /sunos|solaris|hpux/i
@@cpp_command = File.which('cc') || File.which('gcc')
else
@@ -115,11 +120,11 @@
# This string is then to be used at the top of the ERB templates.
#
def get_header_string(headers)
headers = [headers] unless headers.is_a?(Array)
- common_headers = Config::CONFIG['COMMON_HEADERS']
+ common_headers = RbConfig::CONFIG['COMMON_HEADERS']
if common_headers.nil? || common_headers.empty?
if headers.empty?
headers = ['stdio.h', 'stdlib.h']
headers += 'windows.h' if File::ALT_SEPARATOR
@@ -146,34 +151,42 @@
def try_to_execute(code)
begin
result = 0
stderr_orig = $stderr.dup
+ stdout_orig = $stdout.dup
Dir.chdir(Dir.tmpdir){
File.open(@@cpp_srcfile, 'w'){ |fh| fh.write(code) }
command = @@cpp_command + ' '
command += @@cpp_outfile + ' '
command += @@cpp_srcfile
+ # Temporarily close these
$stderr.reopen(File.null)
+ $stdout.reopen(File.null)
if system(command)
- Open3.popen3("./conftest.i") do |stdin, stdout, stderr|
+ $stdout.reopen(stdout_orig) # We need this back for open3 to work.
+
+ conftest = File::ALT_SEPARATOR ? "conftest.exe" : "./conftest.exe"
+
+ Open3.popen3(conftest) do |stdin, stdout, stderr|
stdin.close
stderr.close
result = stdout.gets.chomp.to_i
end
else
- raise "Failed to compile source code:\n===\n" + code + "==="
+ raise "Failed to compile source code with command '#{command}':\n===\n" + code + "==="
end
}
ensure
File.delete(@@cpp_srcfile) if File.exists?(@@cpp_srcfile)
File.delete(@@cpp_outfile) if File.exists?(@@cpp_outfile)
$stderr.reopen(stderr_orig)
+ $stdout.reopen(stdout_orig)
end
result
end
@@ -186,23 +199,26 @@
#
def try_to_compile(code)
begin
boolean = false
stderr_orig = $stderr.dup
+ stdout_orig = $stdout.dup
Dir.chdir(Dir.tmpdir){
File.open(@@cpp_srcfile, 'w'){ |fh| fh.write(code) }
command = @@cpp_command + ' '
command += @@cpp_outfile + ' '
command += @@cpp_srcfile
$stderr.reopen(File.null)
+ $stdout.reopen(File.null)
boolean = system(command)
}
ensure
File.delete(@@cpp_srcfile) if File.exists?(@@cpp_srcfile)
File.delete(@@cpp_outfile) if File.exists?(@@cpp_outfile)
+ $stdout.reopen(stdout_orig)
$stderr.reopen(stderr_orig)
end
boolean
end