|
3 | 3 |
|
4 | 4 | # :stopdoc:
|
5 | 5 |
|
| 6 | +libffi_version = nil |
| 7 | +have_libffi = false |
6 | 8 | bundle = enable_config('bundled-libffi')
|
7 |
| -if ! bundle |
| 9 | +unless bundle |
8 | 10 | dir_config 'libffi'
|
9 | 11 |
|
10 |
| - pkg_config("libffi") and |
11 |
| - ver = pkg_config("libffi", "modversion") |
| 12 | + if pkg_config("libffi") |
| 13 | + libffi_version = pkg_config("libffi", "modversion") |
| 14 | + end |
12 | 15 |
|
| 16 | + have_ffi_header = false |
13 | 17 | if have_header(ffi_header = 'ffi.h')
|
14 |
| - true |
| 18 | + have_ffi_header = true |
15 | 19 | elsif have_header(ffi_header = 'ffi/ffi.h')
|
16 | 20 | $defs.push('-DUSE_HEADER_HACKS')
|
17 |
| - true |
18 |
| - end and (have_library('ffi') || have_library('libffi')) |
19 |
| -end or |
20 |
| -begin |
| 21 | + have_ffi_header = true |
| 22 | + end |
| 23 | + if have_ffi_header && (have_library('ffi') || have_library('libffi')) |
| 24 | + have_libffi = true |
| 25 | + end |
| 26 | +end |
| 27 | + |
| 28 | +unless have_libffi |
21 | 29 | # for https://github.com/ruby/fiddle
|
22 |
| - if bundle && File.exist?("../../bin/extlibs.rb") |
| 30 | + extlibs_rb = File.expand_path("../../bin/extlibs.rb", $srcdir) |
| 31 | + if bundle && File.exist?(extlibs_rb) |
23 | 32 | require "fileutils"
|
24 | 33 | require_relative "../../bin/extlibs"
|
25 | 34 | extlibs = ExtLibs.new
|
|
28 | 37 | Dir.glob("#{$srcdir}/libffi-*/").each{|dir| FileUtils.rm_rf(dir)}
|
29 | 38 | extlibs.run(["--cache=#{cache_dir}", ext_dir])
|
30 | 39 | end
|
31 |
| - ver = bundle != false && |
32 |
| - Dir.glob("#{$srcdir}/libffi-*/") |
33 |
| - .map {|n| File.basename(n)} |
34 |
| - .max_by {|n| n.scan(/\d+/).map(&:to_i)} |
35 |
| - unless ver |
| 40 | + if bundle |
| 41 | + libffi_package_name = Dir.glob("#{$srcdir}/libffi-*/") |
| 42 | + .map {|n| File.basename(n)} |
| 43 | + .max_by {|n| n.scan(/\d+/).map(&:to_i)} |
| 44 | + end |
| 45 | + unless libffi_package_name |
36 | 46 | raise "missing libffi. Please install libffi."
|
37 | 47 | end
|
38 | 48 |
|
39 |
| - srcdir = "#{$srcdir}/#{ver}" |
| 49 | + libffi_srcdir = "#{$srcdir}/#{libffi_package_name}" |
40 | 50 | ffi_header = 'ffi.h'
|
41 | 51 | libffi = Struct.new(*%I[dir srcdir builddir include lib a cflags ldflags opt arch]).new
|
42 |
| - libffi.dir = ver |
| 52 | + libffi.dir = libffi_package_name |
43 | 53 | if $srcdir == "."
|
44 |
| - libffi.builddir = "#{ver}/#{RUBY_PLATFORM}" |
| 54 | + libffi.builddir = libffi_package_name |
45 | 55 | libffi.srcdir = "."
|
46 | 56 | else
|
47 | 57 | libffi.builddir = libffi.dir
|
48 |
| - libffi.srcdir = relative_from(srcdir, "..") |
| 58 | + libffi.srcdir = relative_from(libffi_srcdir, "..") |
49 | 59 | end
|
50 | 60 | libffi.include = "#{libffi.builddir}/include"
|
51 | 61 | libffi.lib = "#{libffi.builddir}/.libs"
|
52 | 62 | libffi.a = "#{libffi.lib}/libffi_convenience.#{$LIBEXT}"
|
53 | 63 | nowarn = CONFIG.merge("warnflags"=>"")
|
54 | 64 | libffi.cflags = RbConfig.expand("$(CFLAGS)".dup, nowarn)
|
55 |
| - ver = ver[/libffi-(.*)/, 1] |
| 65 | + libffi_version = libffi_package_name[/libffi-(.*)/, 1] |
56 | 66 |
|
57 | 67 | FileUtils.mkdir_p(libffi.dir)
|
58 | 68 | libffi.opt = CONFIG['configure_args'][/'(-C)'/, 1]
|
|
81 | 91 | args.concat %W[
|
82 | 92 | --srcdir=#{libffi.srcdir}
|
83 | 93 | --host=#{libffi.arch}
|
84 |
| - --enable-builddir=#{RUBY_PLATFORM} |
85 | 94 | ]
|
86 | 95 | args << ($enable_shared || !$static ? '--enable-shared' : '--enable-static')
|
87 | 96 | args << libffi.opt if libffi.opt
|
|
98 | 107 | begin
|
99 | 108 | IO.copy_stream(libffi.dir + "/config.log", Logging.instance_variable_get(:@logfile))
|
100 | 109 | rescue SystemCallError => e
|
101 |
| - Logfile.message("%s\n", e.message) |
| 110 | + Logging.message("%s\n", e.message) |
102 | 111 | end
|
103 | 112 | raise "failed to configure libffi. Please install libffi."
|
104 | 113 | end
|
|
107 | 116 | FileUtils.rm_f("#{libffi.include}/ffitarget.h")
|
108 | 117 | end
|
109 | 118 | unless File.file?("#{libffi.include}/ffitarget.h")
|
110 |
| - FileUtils.cp("#{srcdir}/src/x86/ffitarget.h", libffi.include, preserve: true) |
| 119 | + FileUtils.cp("#{libffi_srcdir}/src/x86/ffitarget.h", libffi.include, preserve: true) |
111 | 120 | end
|
112 | 121 | $INCFLAGS << " -I" << libffi.include
|
113 | 122 | end
|
114 | 123 |
|
115 |
| -if ver |
116 |
| - ver = ver.gsub(/-rc\d+/, '') # If ver contains rc version, just ignored. |
117 |
| - ver = (ver.split('.').map(&:to_i) + [0,0])[0,3] |
118 |
| - $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % ver }}) |
119 |
| - warn "libffi_version: #{ver.join('.')}" |
| 124 | +if libffi_version |
| 125 | + # If libffi_version contains rc version, just ignored. |
| 126 | + libffi_version = libffi_version.gsub(/-rc\d+/, '') |
| 127 | + libffi_version = (libffi_version.split('.').map(&:to_i) + [0,0])[0,3] |
| 128 | + $defs.push(%{-DRUBY_LIBFFI_MODVERSION=#{ '%d%03d%03d' % libffi_version }}) |
| 129 | + warn "libffi_version: #{libffi_version.join('.')}" |
120 | 130 | end
|
121 | 131 |
|
122 | 132 | case
|
123 |
| -when $mswin, $mingw, (ver && (ver <=> [3, 2]) >= 0) |
| 133 | +when $mswin, $mingw, (libffi_version && (libffi_version <=> [3, 2]) >= 0) |
124 | 134 | $defs << "-DUSE_FFI_CLOSURE_ALLOC=1"
|
125 |
| -when (ver && (ver <=> [3, 2]) < 0) |
| 135 | +when (libffi_version && (libffi_version <=> [3, 2]) < 0) |
126 | 136 | else
|
127 | 137 | have_func('ffi_closure_alloc', ffi_header)
|
128 | 138 | end
|
129 | 139 |
|
130 |
| -have_func('ffi_prep_cif_var', ffi_header) |
| 140 | +if libffi |
| 141 | + $defs << "-DHAVE_FFI_PREP_CIF_VAR" |
| 142 | +else |
| 143 | + have_func('ffi_prep_cif_var', ffi_header) |
| 144 | +end |
131 | 145 |
|
132 | 146 | have_header 'sys/mman.h'
|
133 | 147 |
|
|
0 commit comments