#!/usr/bin/env ruby
require 'mkmf'
require 'rbconfig'
dir_config("ffi_c")
IS_MAC = Config::CONFIG['host_os'] =~ /^darwin/
if IS_MAC
  $CPPFLAGS << " -DMACOSX"
  find_header("ffi.h", "/usr/include/ffi")
end
have_closure_alloc = have_library("ffi", "ffi_closure_alloc", [ "ffi.h" ])
$defs.push("-DHAVE_FFI_CLOSURE_ALLOC") if have_closure_alloc
libffi_ok = have_closure_alloc || (IS_MAC && have_library("ffi", "ffi_prep_closure", [ "ffi.h" ]))
$defs << "-DHAVE_LIBFFI" if libffi_ok
$defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works

create_makefile("ffi_c")
create_header("extconf.h")
File.open("Makefile", "a") do |mf|
  mf.puts "include $(srcdir)/ffi.mk"
  if Config::CONFIG['host_os'] =~ /darwin/
    mf.puts "include $(srcdir)/libffi.darwin.mk"
  else
    mf.puts "include $(srcdir)/libffi.mk"
  end
end unless libffi_ok

#!/usr/bin/env ruby
require 'mkmf'
require 'rbconfig'
dir_config("ffi_c")
IS_MAC = Config::CONFIG['host_os'] =~ /^darwin/
if IS_MAC
  $CPPFLAGS << " -DMACOSX"
  find_header("ffi.h", "/usr/include/ffi")
end
have_closure_alloc = have_library("ffi", "ffi_closure_alloc", [ "ffi.h" ])
$defs.push("-DHAVE_FFI_CLOSURE_ALLOC") if have_closure_alloc
libffi_ok = have_closure_alloc
$defs << "-DHAVE_LIBFFI" if libffi_ok
$defs << "-DHAVE_EXTCONF_H" if $defs.empty? # needed so create_header works

create_makefile("ffi_c")
create_header("extconf.h")
File.open("Makefile", "a") do |mf|
  mf.puts "include $(srcdir)/ffi.mk"
  if Config::CONFIG['host_os'] =~ /darwin/
    mf.puts "include $(srcdir)/libffi.darwin.mk"
  else
    mf.puts "include $(srcdir)/libffi.mk"
  end
end unless libffi_ok

Disable use of /usr/lib/libffi.dylib on MacOS as it does not have ffi_raw_call
Disable use of /usr/lib/libffi.dylib on MacOS as it does not have ffi_raw_call
