ruby-changes:36822
From: nobu <ko1@a...>
Date: Sat, 20 Dec 2014 11:23:15 +0900 (JST)
Subject: [ruby-changes:36822] nobu:r48903 (trunk): fiddle: bundled libffi
nobu 2014-12-20 11:23:00 +0900 (Sat, 20 Dec 2014) New Revision: 48903 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=48903 Log: fiddle: bundled libffi * ext/fiddle/depend, ext/fiddle/extconf.rb: try to build bundled libffi if existing. Modified files: trunk/ChangeLog trunk/ext/fiddle/depend trunk/ext/fiddle/extconf.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 48902) +++ ChangeLog (revision 48903) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Dec 20 11:22:58 2014 Nobuyoshi Nakada <nobu@r...> + + * ext/fiddle/depend, ext/fiddle/extconf.rb: try to build bundled + libffi if existing. + Sat Dec 20 05:21:00 2014 Eric Wong <e@8...> * test/test_weakref.rb (test_repeated_object_leak): increase timeout Index: ext/fiddle/depend =================================================================== --- ext/fiddle/depend (revision 48902) +++ ext/fiddle/depend (revision 48903) @@ -1,4 +1,26 @@ https://github.com/ruby/ruby/blob/trunk/ext/fiddle/depend#L1 +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) Index: ext/fiddle/extconf.rb =================================================================== --- ext/fiddle/extconf.rb (revision 48902) +++ ext/fiddle/extconf.rb (revision 48903) @@ -2,25 +2,44 @@ require 'mkmf' https://github.com/ruby/ruby/blob/trunk/ext/fiddle/extconf.rb#L2 # :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| https://github.com/ruby/ruby/blob/trunk/ext/fiddle/extconf.rb#L74 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: -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/