fiddle: win32/libffi-config.rb
* ext/fiddle/win32/libffi-config.rb: generate necessary files to build on mswin. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48957 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
84c39fb2fa
commit
0cd829c339
@ -1,7 +1,6 @@
|
|||||||
PWD =
|
PWD =
|
||||||
|
|
||||||
CONFIGURE_LIBFFI = \
|
CONFIGURE_LIBFFI = \
|
||||||
cd $(LIBFFI_DIR) && \
|
|
||||||
$(LIBFFI_CONFIGURE) --disable-shared \
|
$(LIBFFI_CONFIGURE) --disable-shared \
|
||||||
--host=$(LIBFFI_ARCH) --enable-builddir=$(arch) \
|
--host=$(LIBFFI_ARCH) --enable-builddir=$(arch) \
|
||||||
CC="$(CC)" CFLAGS="$(LIBFFI_CFLAGS)" \
|
CC="$(CC)" CFLAGS="$(LIBFFI_CFLAGS)" \
|
||||||
@ -31,7 +30,7 @@ clean-libffi:
|
|||||||
distclean-libffi:
|
distclean-libffi:
|
||||||
$(Q) $(SUBMAKE_LIBFFI) distclean
|
$(Q) $(SUBMAKE_LIBFFI) distclean
|
||||||
$(Q) $(RM) $(LIBFFI_DIR)/local.exp
|
$(Q) $(RM) $(LIBFFI_DIR)/local.exp
|
||||||
$(Q) $(RUBY) -rfileutils -e 'FileUtils.rmdir(Dir.glob(ARGV[0]+"/**/"), :parents=>true)' $(LIBFFI_DIR)
|
$(Q) $(RUBY) -rfileutils -e "FileUtils.rmdir(Dir.glob(ARGV[0]+'/**/'), :parents=>true)" $(LIBFFI_DIR)
|
||||||
|
|
||||||
realclean-libffi:
|
realclean-libffi:
|
||||||
$(Q) $(RMALL) $(LIBFFI_DIR)
|
$(Q) $(RMALL) $(LIBFFI_DIR)
|
||||||
|
@ -47,25 +47,27 @@ begin
|
|||||||
libffi.arch = RbConfig::CONFIG['host']
|
libffi.arch = RbConfig::CONFIG['host']
|
||||||
if $mswin
|
if $mswin
|
||||||
$defs << "-DFFI_BUILDING"
|
$defs << "-DFFI_BUILDING"
|
||||||
libffi.opt = '-C'
|
libffi_config = "#{relative_from($srcdir, '..')}/win32/libffi-config.rb"
|
||||||
cc = "#{libffi.srcdir}/msvcc.sh"
|
config = CONFIG.merge("top_srcdir" => $top_srcdir)
|
||||||
libffi.arch = libffi.arch.sub(/mswin\d+(_\d+)?\z/, 'mingw32')
|
args = $ruby.gsub(/:\/=\\/, '')
|
||||||
cc << (libffi.arch.sub!(/^x64/, 'x86_64') ? " -m64" : " -m32")
|
args.gsub!(/\)\\/, ')/')
|
||||||
libffi.ldflags = ''
|
args = args.shellsplit
|
||||||
cxx = cc
|
args.map! {|s| RbConfig.expand(s, config)}
|
||||||
ld = "link"
|
args << '-C' << libffi.dir << libffi_config
|
||||||
cpp = "cl -nologo -EP"
|
opts = {}
|
||||||
else
|
else
|
||||||
cc = RbConfig::CONFIG['CC']
|
args = %W[sh #{libffi.srcdir}/configure ]
|
||||||
ld = RbConfig::CONFIG['LD']
|
opts = {chdir: libffi.dir}
|
||||||
end
|
end
|
||||||
args = %W[
|
cc = RbConfig::CONFIG['CC']
|
||||||
sh #{libffi.srcdir}/configure
|
cxx = RbConfig::CONFIG['CXX']
|
||||||
|
ld = RbConfig::CONFIG['LD']
|
||||||
|
args.concat %W[
|
||||||
|
--srcdir=#{libffi.srcdir}
|
||||||
--disable-shared --host=#{libffi.arch}
|
--disable-shared --host=#{libffi.arch}
|
||||||
--enable-builddir=#{RUBY_PLATFORM}
|
--enable-builddir=#{RUBY_PLATFORM}
|
||||||
]
|
]
|
||||||
args << libffi.opt if libffi.opt
|
args << libffi.opt if libffi.opt
|
||||||
args << "CPP=#{cpp}" if cpp
|
|
||||||
args.concat %W[
|
args.concat %W[
|
||||||
CC=#{cc} CFLAGS=#{libffi.cflags}
|
CC=#{cc} CFLAGS=#{libffi.cflags}
|
||||||
CXX=#{cxx} CXXFLAGS=#{RbConfig.expand("$(CXXFLAGS)", nowarn)}
|
CXX=#{cxx} CXXFLAGS=#{RbConfig.expand("$(CXXFLAGS)", nowarn)}
|
||||||
@ -74,8 +76,8 @@ begin
|
|||||||
|
|
||||||
FileUtils.rm_f("#{libffi.include}/ffitarget.h")
|
FileUtils.rm_f("#{libffi.include}/ffitarget.h")
|
||||||
Logging::open do
|
Logging::open do
|
||||||
Logging.message("%p in %s\n", args, libffi.dir)
|
Logging.message("%p in %p\n", args, opts)
|
||||||
system(*args, chdir: libffi.dir) or
|
system(*args, **opts) or
|
||||||
raise "failed to configure libffi. Please install libffi."
|
raise "failed to configure libffi. Please install libffi."
|
||||||
end
|
end
|
||||||
if $mswin && File.file?("#{libffi.include}/ffitarget.h")
|
if $mswin && File.file?("#{libffi.include}/ffitarget.h")
|
||||||
@ -131,18 +133,21 @@ end
|
|||||||
create_makefile 'fiddle' do |conf|
|
create_makefile 'fiddle' do |conf|
|
||||||
if !libffi
|
if !libffi
|
||||||
next conf << "LIBFFI_CLEAN = none\n"
|
next conf << "LIBFFI_CLEAN = none\n"
|
||||||
elsif $mswin
|
elsif $gnumake && !$nmake
|
||||||
submake = "make -C $(LIBFFI_DIR)\n"
|
|
||||||
elsif $gnumake
|
|
||||||
submake = "$(MAKE) -C $(LIBFFI_DIR)\n"
|
submake = "$(MAKE) -C $(LIBFFI_DIR)\n"
|
||||||
else
|
else
|
||||||
submake = "cd $(LIBFFI_DIR) && \\\n\t\t" << "#{config_string("exec")} $(MAKE)".strip
|
submake = "cd $(LIBFFI_DIR) && \\\n\t\t" << "#{config_string("exec")} $(MAKE)".strip
|
||||||
end
|
end
|
||||||
|
if $nmake
|
||||||
|
cmd = "$(RUBY) -C $(LIBFFI_DIR) #{libffi_config} --srcdir=$(LIBFFI_SRCDIR)"
|
||||||
|
else
|
||||||
|
cmd = "cd $(LIBFFI_DIR) && #$exec $(LIBFFI_SRCDIR)/configure #{libffi.opt}"
|
||||||
|
end
|
||||||
sep = "/"
|
sep = "/"
|
||||||
seprpl = config_string('BUILD_FILE_SEPARATOR') {|s| sep = s; ":/=#{s}" if s != "/"} || ""
|
seprpl = config_string('BUILD_FILE_SEPARATOR') {|s| sep = s; ":/=#{s}" if s != "/"} || ""
|
||||||
conf << <<-MK.gsub(/^ +| +$/, '')
|
conf << <<-MK.gsub(/^ +| +$/, '')
|
||||||
PWD =
|
PWD =
|
||||||
LIBFFI_CONFIGURE = $(LIBFFI_SRCDIR#{seprpl})#{sep}configure #{libffi.opt}
|
LIBFFI_CONFIGURE = #{cmd}
|
||||||
LIBFFI_ARCH = #{libffi.arch}
|
LIBFFI_ARCH = #{libffi.arch}
|
||||||
LIBFFI_SRCDIR = #{libffi.srcdir}
|
LIBFFI_SRCDIR = #{libffi.srcdir}
|
||||||
LIBFFI_DIR = #{libffi.dir}
|
LIBFFI_DIR = #{libffi.dir}
|
||||||
|
29
ext/fiddle/win32/fficonfig.h
Executable file
29
ext/fiddle/win32/fficonfig.h
Executable file
@ -0,0 +1,29 @@
|
|||||||
|
#define HAVE_ALLOCA 1
|
||||||
|
#define HAVE_MEMCPY 1
|
||||||
|
#define HAVE_MEMORY_H 1
|
||||||
|
#define HAVE_STDLIB_H 1
|
||||||
|
#define HAVE_STRING_H 1
|
||||||
|
#define HAVE_SYS_STAT_H 1
|
||||||
|
#define HAVE_SYS_TYPES_H 1
|
||||||
|
#if _MSC_VER >= 1600
|
||||||
|
#define HAVE_INTTYPES_H 1
|
||||||
|
#define HAVE_STDINT_H 1
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define SIZEOF_DOUBLE 8
|
||||||
|
#if defined(X86_WIN64)
|
||||||
|
#define SIZEOF_SIZE_T 8
|
||||||
|
#else
|
||||||
|
#define SIZEOF_SIZE_T 4
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#define STACK_DIRECTION -1
|
||||||
|
|
||||||
|
#define STDC_HEADERS 1
|
||||||
|
|
||||||
|
#ifdef LIBFFI_ASM
|
||||||
|
#define FFI_HIDDEN(name)
|
||||||
|
#else
|
||||||
|
#define FFI_HIDDEN
|
||||||
|
#endif
|
||||||
|
|
47
ext/fiddle/win32/libffi-config.rb
Executable file
47
ext/fiddle/win32/libffi-config.rb
Executable file
@ -0,0 +1,47 @@
|
|||||||
|
#!/usr/bin/ruby
|
||||||
|
require 'fileutils'
|
||||||
|
|
||||||
|
basedir = File.dirname(__FILE__)
|
||||||
|
conf = {}
|
||||||
|
enable = {}
|
||||||
|
until ARGV.empty?
|
||||||
|
arg = ARGV.shift
|
||||||
|
case arg
|
||||||
|
when '-C'
|
||||||
|
# ignore
|
||||||
|
when /\A--srcdir=(.*)/
|
||||||
|
conf['SRCDIR'] = srcdir = $1
|
||||||
|
when /\A(CC|CFLAGS|CXX|CXXFLAGS|LD|LDFLAGS)=(.*)/
|
||||||
|
conf[$1] = $2
|
||||||
|
when /\A--host=(.*)/
|
||||||
|
host = $1
|
||||||
|
when /\A--enable-([^=]+)(?:=(.*))?/
|
||||||
|
enable[$1] = $2 || true
|
||||||
|
when /\A--disable-([^=]+)/
|
||||||
|
enable[$1] = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
IO.foreach("#{srcdir}/configure.ac") do |line|
|
||||||
|
if /^AC_INIT\((.*)\)/ =~ line
|
||||||
|
version = $1.split(/,\s*/)[1]
|
||||||
|
version.gsub!(/\A\[|\]\z/, '')
|
||||||
|
conf['VERSION'] = version
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
builddir = srcdir == "." ? enable['builddir'] : "."
|
||||||
|
conf['TARGET'] = /^x64/ =~ host ? "X86_WIN64" : "X86_WIN32"
|
||||||
|
|
||||||
|
FileUtils.mkdir_p([builddir, "#{builddir}/include", "#{builddir}/src/x86"])
|
||||||
|
FileUtils.cp("#{basedir}/fficonfig.h", ".", preserve: true)
|
||||||
|
|
||||||
|
hdr = IO.binread("#{srcdir}/include/ffi.h.in")
|
||||||
|
hdr.gsub!(/@(\w+)@/) {conf[$1] || $&}
|
||||||
|
hdr.gsub!(/^(#if\s+)@\w+@/, '\10')
|
||||||
|
IO.binwrite("#{builddir}/include/ffi.h", hdr)
|
||||||
|
|
||||||
|
mk = IO.binread("#{basedir}/libffi.mk.tmpl")
|
||||||
|
mk.gsub!(/@(\w+)@/) {conf[$1] || $&}
|
||||||
|
IO.binwrite("Makefile", mk)
|
96
ext/fiddle/win32/libffi.mk.tmpl
Executable file
96
ext/fiddle/win32/libffi.mk.tmpl
Executable file
@ -0,0 +1,96 @@
|
|||||||
|
# -*- makefile -*-
|
||||||
|
# ====================================================================
|
||||||
|
#
|
||||||
|
# libffi Windows Makefile
|
||||||
|
#
|
||||||
|
#
|
||||||
|
# ====================================================================
|
||||||
|
#
|
||||||
|
NAME = ffi
|
||||||
|
TARGET = @TARGET@
|
||||||
|
CC = cl
|
||||||
|
!if "$(TARGET)" == "X86_WIN64"
|
||||||
|
AS = ml64
|
||||||
|
!else
|
||||||
|
AS = ml
|
||||||
|
!endif
|
||||||
|
AR = link
|
||||||
|
DLEXT = dll
|
||||||
|
OBJEXT = obj
|
||||||
|
LIBEXT = lib
|
||||||
|
TOPDIR = @SRCDIR@
|
||||||
|
CPP = $(CC) -EP
|
||||||
|
CFLAGS = @CFLAGS@
|
||||||
|
ARFLAGS = -lib
|
||||||
|
ASFLAGS = -coff -W3 -Cx
|
||||||
|
INCLUDES= -I. -I./include -I./src/x86 \
|
||||||
|
-I$(TOPDIR)/include -I$(TOPDIR)/include/src/x86
|
||||||
|
|
||||||
|
SRCDIR = $(TOPDIR)/src
|
||||||
|
WORKDIR = ./.libs
|
||||||
|
BUILDDIR= ./src
|
||||||
|
LIBNAME = lib$(NAME)
|
||||||
|
STATICLIB= $(WORKDIR)/$(LIBNAME).$(LIBEXT)
|
||||||
|
|
||||||
|
HEADERS = \
|
||||||
|
./fficonfig.h
|
||||||
|
FFI_HEADERS = \
|
||||||
|
./include/ffi.h \
|
||||||
|
./include/ffitarget.h
|
||||||
|
|
||||||
|
!if "$(TARGET)" == "X86_WIN32"
|
||||||
|
OSSRC = win32
|
||||||
|
!else if "$(TARGET)" == "X86_WIN64"
|
||||||
|
OSSRC = win64
|
||||||
|
!else
|
||||||
|
! error unknown target: $(TARGET)
|
||||||
|
!endif
|
||||||
|
|
||||||
|
OBJECTS = \
|
||||||
|
$(BUILDDIR)/closures.$(OBJEXT) \
|
||||||
|
$(BUILDDIR)/debug.$(OBJEXT) \
|
||||||
|
$(BUILDDIR)/java_raw_api.$(OBJEXT) \
|
||||||
|
$(BUILDDIR)/prep_cif.$(OBJEXT) \
|
||||||
|
$(BUILDDIR)/raw_api.$(OBJEXT) \
|
||||||
|
$(BUILDDIR)/types.$(OBJEXT) \
|
||||||
|
$(BUILDDIR)/x86/ffi.$(OBJEXT) \
|
||||||
|
$(BUILDDIR)/x86/$(OSSRC).$(OBJEXT)
|
||||||
|
ASMSRCS = \
|
||||||
|
$(BUILDDIR)/x86/$(OSSRC).asm
|
||||||
|
|
||||||
|
.SUFFIXES : .S .asm
|
||||||
|
|
||||||
|
all: $(WORKDIR) $(STATICLIB)
|
||||||
|
|
||||||
|
{$(SRCDIR)}.c{$(BUILDDIR)}.$(OBJEXT):
|
||||||
|
$(CC) -c $(CFLAGS) $(INCLUDES) -Fo$(@:\=/) -Fd$(WORKDIR)/$(NAME)-src $(<:\=/)
|
||||||
|
|
||||||
|
{$(SRCDIR)/x86}.c{$(BUILDDIR)/x86}.$(OBJEXT):
|
||||||
|
$(CC) -c $(CFLAGS) $(INCLUDES) -Fo$(@:\=/) -Fd$(WORKDIR)/$(NAME)-src $(<:\=/)
|
||||||
|
|
||||||
|
{$(SRCDIR)/x86}.S{$(BUILDDIR)/x86}.asm:
|
||||||
|
$(CPP) $(CFLAGS) $(INCLUDES) $(<:\=/) >$(@:\=/)
|
||||||
|
|
||||||
|
{$(BUILDDIR)/x86}.asm{$(BUILDDIR)/x86}.$(OBJEXT):
|
||||||
|
$(AS) -c $(ASFLAGS) -Fo $(@:\=/) $(<:\=/)
|
||||||
|
|
||||||
|
$(BUILDDIR)/x86/$(OSSRC).asm: $(SRCDIR)/x86/$(OSSRC).S
|
||||||
|
|
||||||
|
$(OBJECTS): $(FFI_HEADERS) $(HEADERS)
|
||||||
|
|
||||||
|
$(WORKDIR):
|
||||||
|
-@if not exist "$(WORKDIR:/=\)\$(NULL)" mkdir $(WORKDIR:/=\)
|
||||||
|
|
||||||
|
$(STATICLIB): $(WORKDIR) $(OBJECTS)
|
||||||
|
$(AR) $(ARFLAGS) -out:$(STATICLIB) @<<
|
||||||
|
$(OBJECTS)
|
||||||
|
<<
|
||||||
|
|
||||||
|
clean:
|
||||||
|
-@del /Q $(OBJECTS:/=\) 2>NUL
|
||||||
|
-@del /Q $(ASMSRCS:/=\) 2>NUL
|
||||||
|
-@del /Q /S $(WORKDIR:/=\) 2>NUL
|
||||||
|
|
||||||
|
distclean: clean
|
||||||
|
-@del /Q $(HEADERS:/=\) $(FFI_HEADERS:/=\) 2>NUL
|
||||||
|
-@del /Q Makefile 2>NUL
|
Loading…
x
Reference in New Issue
Block a user