summaryrefslogtreecommitdiff
path: root/ext/fiddle
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-23 06:21:49 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-23 06:21:49 +0000
commitb2c4e778ba10619ba76b5b4c6d554a47cb6d41ef (patch)
treef5923f134a3e7757cb376fef2931095483544b81 /ext/fiddle
parent36cea85aa42681cc5b05d1b1d48b2a5255192ed1 (diff)
extconf.rb: libffi on mswin
* ext/fiddle/extconf.rb: try to compile libffi as mingw on mswin if possible. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48925 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/fiddle')
-rw-r--r--ext/fiddle/extconf.rb43
1 files changed, 35 insertions, 8 deletions
diff --git a/ext/fiddle/extconf.rb b/ext/fiddle/extconf.rb
index 04c4bce..edaba21 100644
--- a/ext/fiddle/extconf.rb
+++ b/ext/fiddle/extconf.rb
@@ -23,6 +23,7 @@ begin
raise "missing libffi. Please install libffi."
end
+ srcdir = "#{$srcdir}/#{ver}"
ffi_header = 'ffi.h'
libffi = Struct.new(*%I[dir srcdir builddir include lib a cflags ldflags opt arch]).new
libffi.dir = ver
@@ -31,31 +32,55 @@ begin
libffi.srcdir = "."
else
libffi.builddir = libffi.dir
- libffi.srcdir = relative_from("#{$srcdir}/#{ver}", "..")
+ libffi.srcdir = relative_from(srcdir, "..")
end
libffi.include = "#{libffi.builddir}/include"
libffi.lib = "#{libffi.builddir}/.libs"
libffi.a = "#{libffi.lib}/libffi.#{$LIBEXT}"
- libffi.cflags = RbConfig.expand("$(CFLAGS)", CONFIG.merge("warnflags"=>""))
+ nowarn = CONFIG.merge("warnflags"=>"")
+ libffi.cflags = RbConfig.expand("$(CFLAGS)", nowarn)
ver = ver[/libffi-(.*)/, 1]
FileUtils.mkdir_p(libffi.dir)
libffi.opt = CONFIG['configure_args'][/'(-C)'/, 1]
libffi.ldflags = RbConfig.expand("$(LDFLAGS) #{libpathflag([relative_from($topdir, "..")])} #{$LIBRUBYARG}")
libffi.arch = RbConfig::CONFIG['host']
+ if $mswin
+ $defs << "-DFFI_BUILDING"
+ libffi.opt = '-C'
+ cc = "#{libffi.srcdir}/msvcc.sh"
+ libffi.arch = libffi.arch.sub(/mswin\d+(_\d+)?\z/, 'mingw32')
+ cc << (libffi.arch.sub!(/^x64/, 'x86_64') ? " -m64" : " -m32")
+ libffi.ldflags = ''
+ cxx = cc
+ ld = "link"
+ cpp = "cl -nologo -EP"
+ else
+ cc = RbConfig::CONFIG['CC']
+ ld = RbConfig::CONFIG['LD']
+ end
args = %W[
- #{libffi.srcdir}/configure #{libffi.opt}
- --disable-shared
- --host=#{libffi.arch} --enable-builddir=#{RUBY_PLATFORM}
- CC=#{RbConfig::CONFIG['CC']} CFLAGS=#{libffi.cflags}
- LD=#{RbConfig::CONFIG['LD']} LDFLAGS=#{libffi.ldflags}
+ sh #{libffi.srcdir}/configure
+ --disable-shared --host=#{libffi.arch}
+ --enable-builddir=#{RUBY_PLATFORM}
+ ]
+ args << libffi.opt if libffi.opt
+ args.concat %W[
+ CC=#{cc} CFLAGS=#{libffi.cflags}
+ CXX=#{cxx} CXXFLAGS=#{RbConfig.expand("$(CXXFLAGS)", nowarn)}
+ LD=#{ld} LDFLAGS=#{libffi.ldflags}
+ CPP=#{cpp}
]
+ FileUtils.rm_f("#{libffi.include}/ffitarget.h")
Logging::open do
Logging.message("%p in %s\n", args, libffi.dir)
system(*args, chdir: libffi.dir) or
raise "failed to configure libffi. Please install libffi."
end
+ unless File.file?("#{libffi.include}/ffitarget.h")
+ FileUtils.cp("#{srcdir}/src/x86/ffitarget.h", libffi.include, preserve: true)
+ end
$INCFLAGS << " -I" << libffi.include
end
@@ -103,7 +128,9 @@ if libffi
end
create_makefile 'fiddle' do |conf|
next conf unless libffi
- if $gnumake
+ if $mswin
+ submake = "make -C $(LIBFFI_DIR)\n"
+ elsif $gnumake
submake = "$(MAKE) -C $(LIBFFI_DIR)\n"
else
submake = "cd $(LIBFFI_DIR) && \\\n\t\t" << "#{config_string("exec")} $(MAKE)".strip