2010-05-06 10:59:24 +04:00
|
|
|
require 'mkmf'
|
|
|
|
|
|
|
|
# :stopdoc:
|
|
|
|
|
2014-12-20 05:23:00 +03:00
|
|
|
if ! enable_config('bundled-libffi', false)
|
|
|
|
dir_config 'libffi'
|
2010-05-06 10:59:24 +04:00
|
|
|
|
2014-12-20 05:23:00 +03:00
|
|
|
pkg_config("libffi")
|
|
|
|
ver = pkg_config("libffi", "modversion")
|
2013-04-11 01:15:37 +04:00
|
|
|
|
2014-12-20 05:23:00 +03:00
|
|
|
if have_header('ffi.h')
|
|
|
|
true
|
|
|
|
elsif have_header('ffi/ffi.h')
|
2010-05-06 10:59:24 +04:00
|
|
|
$defs.push(format('-DUSE_HEADER_HACKS'))
|
2014-12-20 05:23:00 +03:00
|
|
|
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 = "."
|
2010-05-06 10:59:24 +04:00
|
|
|
else
|
2014-12-20 05:23:00 +03:00
|
|
|
builddir = bundled
|
|
|
|
libffi_srcdir = relative_from("#{$srcdir}/#{bundled}", "..")
|
2010-05-06 10:59:24 +04:00
|
|
|
end
|
2014-12-20 05:23:00 +03:00
|
|
|
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]
|
2010-05-06 10:59:24 +04:00
|
|
|
end
|
|
|
|
|
2014-12-20 05:23:00 +03:00
|
|
|
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 }})
|
2010-05-06 10:59:24 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
have_header 'sys/mman.h'
|
|
|
|
|
2012-11-27 23:54:50 +04:00
|
|
|
if have_header "dlfcn.h"
|
|
|
|
have_library "dl"
|
|
|
|
|
|
|
|
%w{ dlopen dlclose dlsym }.each do |func|
|
|
|
|
abort "missing function #{func}" unless have_func(func)
|
|
|
|
end
|
|
|
|
|
|
|
|
have_func "dlerror"
|
|
|
|
elsif have_header "windows.h"
|
|
|
|
%w{ LoadLibrary FreeLibrary GetProcAddress }.each do |func|
|
|
|
|
abort "missing function #{func}" unless have_func(func)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2012-11-30 19:57:21 +04:00
|
|
|
have_const('FFI_STDCALL', 'ffi.h') || have_const('FFI_STDCALL', 'ffi/ffi.h')
|
|
|
|
|
2012-02-25 09:47:16 +04:00
|
|
|
config = File.read(RbConfig.expand(File.join($arch_hdrdir, "ruby/config.h")))
|
|
|
|
types = {"SIZE_T"=>"SSIZE_T", "PTRDIFF_T"=>nil, "INTPTR_T"=>nil}
|
|
|
|
types.each do |type, signed|
|
|
|
|
if /^\#define\s+SIZEOF_#{type}\s+(SIZEOF_(.+)|\d+)/ =~ config
|
|
|
|
if size = $2 and size != 'VOIDP'
|
|
|
|
size = types.fetch(size) {size}
|
|
|
|
$defs << format("-DTYPE_%s=TYPE_%s", signed||type, size)
|
|
|
|
end
|
|
|
|
if signed
|
|
|
|
check_signedness(type.downcase, "stddef.h")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-12-20 05:23:00 +03:00
|
|
|
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
|
2010-05-06 10:59:24 +04:00
|
|
|
|
|
|
|
# :startdoc:
|