summaryrefslogtreecommitdiff
path: root/ext/fiddle
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-20 02:23:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-12-20 02:23:00 +0000
commit5856a951914785b4b48f81340621d0cdb2271118 (patch)
tree9fe6a5b1748191225f4fd6f1569970d8e4976bc6 /ext/fiddle
parentf7e32f01825cfdb5ff72de9cc2222c48c0c048cb (diff)
fiddle: bundled libffi
* ext/fiddle/depend, ext/fiddle/extconf.rb: try to build bundled libffi if existing. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48903 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/fiddle')
-rw-r--r--ext/fiddle/depend22
-rw-r--r--ext/fiddle/extconf.rb67
2 files changed, 76 insertions, 13 deletions
diff --git a/ext/fiddle/depend b/ext/fiddle/depend
index e786dc7..8fcb06e 100644
--- a/ext/fiddle/depend
+++ b/ext/fiddle/depend
@@ -1,4 +1,26 @@
+PWD =
+LOCAL_LIBS = $(LIBFFI_A)
+
+CONFIGURE_LIBFFI = \
+ cd $(LIBFFI_DIR) && \
+ $(LIBFFI_CONFIGURE) --disable-shared \
+ --host=$(LIBFFI_ARCH) --enable-builddir=$(arch) \
+ CC="$(CC)" CFLAGS="$(LIBFFI_CFLAGS)"
+
$(OBJS): $(HDRS) $(ruby_headers) \
$(hdrdir)/ruby/io.h \
$(hdrdir)/ruby/encoding.h \
$(hdrdir)/ruby/oniguruma.h
+
+$(STATIC_LIB) $(RUBYARCHDIR)/$(DLLIB) $(DLLIB): $(LIBFFI_A)
+
+$(OBJS): $(FFI_H)
+
+hdr: $(FFI_H)
+configure-libffi $(FFI_H):
+ $(Q) $(MAKEDIRS) $(LIBFFI_DIR)
+ $(Q) $(CONFIGURE_LIBFFI)
+
+lib: $(LIBFFI_A)
+$(LIBFFI_A):
+ $(Q) $(SUBMAKE_LIBFFI)
diff --git a/ext/fiddle/extconf.rb b/ext/fiddle/extconf.rb
index 466d77e..b3c58de 100644
--- a/ext/fiddle/extconf.rb
+++ b/ext/fiddle/extconf.rb
@@ -2,25 +2,44 @@ require 'mkmf'
# :stopdoc:
-dir_config 'libffi'
+if ! enable_config('bundled-libffi', false)
+ dir_config 'libffi'
-pkg_config("libffi")
-if ver = pkg_config("libffi", "modversion")
- ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just ignored.
- ver = (ver.split('.') + [0,0])[0,3]
- $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver }})
-end
+ pkg_config("libffi")
+ ver = pkg_config("libffi", "modversion")
-unless have_header('ffi.h')
- if have_header('ffi/ffi.h')
+ if have_header('ffi.h')
+ true
+ elsif have_header('ffi/ffi.h')
$defs.push(format('-DUSE_HEADER_HACKS'))
+ true
+ end and (have_library('ffi') || have_library('libffi'))
+end or
+begin
+ ver = Dir.glob("#{$srcdir}/libffi-*/")
+ .map {|n| File.basename(n)}
+ .max_by {|n| n.scan(/\d+/).map(&:to_i)}
+ bundled = ver
+ if $srcdir == "."
+ builddir = "#{ver}/#{RUBY_PLATFORM}"
+ libffi_srcdir = "."
else
- raise "ffi.h is missing. Please install libffi."
+ builddir = bundled
+ libffi_srcdir = relative_from("#{$srcdir}/#{bundled}", "..")
end
+ libffi_include = "#{builddir}/include"
+ libffi_lib = "#{builddir}/.libs"
+ libffi_a = "#{libffi_lib}/libffi.#{$LIBEXT}"
+ libffi_cflags = RbConfig.expand("$(CFLAGS)", CONFIG.merge("warnflags"=>""))
+ $LIBPATH.unshift libffi_lib
+ $INCFLAGS << " -I" << libffi_include
+ ver = ver[/libffi-(.*)/, 1]
end
-unless have_library('ffi') || have_library('libffi')
- raise "libffi is missing. Please install libffi."
+if ver
+ ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just ignored.
+ ver = (ver.split('.') + [0,0])[0,3]
+ $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver }})
end
have_header 'sys/mman.h'
@@ -55,6 +74,28 @@ types.each do |type, signed|
end
end
-create_makefile 'fiddle'
+create_makefile 'fiddle' do |conf|
+ if $gnumake
+ submake = "$(MAKE) -C $(LIBFFI_DIR)\n"
+ else
+ submake = "cd $(LIBFFI_DIR) && \\\n\t\t" << "#{config_string("exec")} $(MAKE)".strip
+ end
+ conf << <<-MK.gsub(/^ +/, '')
+ PWD =
+ LIBFFI_CONFIGURE = $(LIBFFI_SRCDIR)/configure#{/'-C'/ =~ CONFIG['configure_args'] ? ' -C' : ''}
+ LIBFFI_ARCH = #{RbConfig::CONFIG['arch'].sub(/\Ax64-(?=mingw|mswin)/, 'x86_64-')}
+ LIBFFI_SRCDIR = #{libffi_srcdir}
+ LIBFFI_DIR = #{bundled}
+ LIBFFI_A = #{libffi_a}
+ LIBFFI_CFLAGS = #{libffi_cflags}
+ FFI_H = #{bundled && '$(LIBFFI_DIR)/include/ffi.h'}
+ SUBMAKE_LIBFFI = #{submake}
+ MK
+end
+
+if bundled
+ xsystem([$make, 'configure-libffi', *sysquote($mflags)]) or
+ raise "failed to configure libffi. Please install libffi."
+end
# :startdoc: