From ae623435e063667e017f909ddf5385d8fa6d2396 Mon Sep 17 00:00:00 2001 From: usa Date: Fri, 12 May 2017 06:39:43 +0000 Subject: Support building exts of spec on mswin * spec/rubyspec/optional/capi/spec_helper.rb: building command of extensions on mswin differs from Unixen's one. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58671 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- spec/rubyspec/optional/capi/spec_helper.rb | 32 ++++++++++++++++++++---------- 1 file changed, 22 insertions(+), 10 deletions(-) (limited to 'spec/rubyspec') diff --git a/spec/rubyspec/optional/capi/spec_helper.rb b/spec/rubyspec/optional/capi/spec_helper.rb index ce8a07aeba..e60016f4a7 100644 --- a/spec/rubyspec/optional/capi/spec_helper.rb +++ b/spec/rubyspec/optional/capi/spec_helper.rb @@ -25,7 +25,6 @@ def compile_extension(name) # TODO use rakelib/ext_helper.rb? arch_hdrdir = nil - ruby_hdrdir = nil if RUBY_NAME == 'rbx' hdrdir = RbConfig::CONFIG["rubyhdrdir"] @@ -33,7 +32,6 @@ def compile_extension(name) if hdrdir = RbConfig::CONFIG["rubyhdrdir"] arch_hdrdir = RbConfig::CONFIG["rubyarchhdrdir"] || File.join(hdrdir, RbConfig::CONFIG["arch"]) - ruby_hdrdir = File.join hdrdir, "ruby" else hdrdir = RbConfig::CONFIG["archdir"] end @@ -69,32 +67,46 @@ def compile_extension(name) cflags = (ENV["CFLAGS"] || RbConfig::CONFIG["CFLAGS"]).dup cflags += " #{RbConfig::CONFIG["ARCH_FLAG"]}" if RbConfig::CONFIG["ARCH_FLAG"] cflags += " #{RbConfig::CONFIG["CCDLFLAGS"]}" if RbConfig::CONFIG["CCDLFLAGS"] - incflags = "-I#{path} -I#{hdrdir}" + cppflags = (ENV["CPPFLAGS"] || RbConfig::CONFIG["CPPFLAGS"]).dup + incflags = "-I#{path}" incflags << " -I#{arch_hdrdir}" if arch_hdrdir - incflags << " -I#{ruby_hdrdir}" if ruby_hdrdir + incflags << " -I#{hdrdir}" + csrcflag = RbConfig::CONFIG["CSRCFLAG"] + coutflag = RbConfig::CONFIG["COUTFLAG"] - output = `#{cc} #{incflags} #{cflags} -c #{source} -o #{obj}` + compile_cmd = "#{cc} #{incflags} #{cflags} #{cppflags} #{coutflag}#{obj} -c #{csrcflag}#{source}" + output = `#{compile_cmd}` unless $?.success? and File.exist?(obj) - puts "ERROR:\n#{output}" + puts "\nERROR:\n#{compile_cmd}\n#{output}" puts "incflags=#{incflags}" puts "cflags=#{cflags}" + puts "cppflags=#{cppflags}" raise "Unable to compile \"#{source}\"" end ldshared = RbConfig::CONFIG["LDSHARED"] ldshared += " #{RbConfig::CONFIG["ARCH_FLAG"]}" if RbConfig::CONFIG["ARCH_FLAG"] - libpath = "-L#{path}" libs = RbConfig::CONFIG["LIBS"] dldflags = "#{RbConfig::CONFIG["LDFLAGS"]} #{RbConfig::CONFIG["DLDFLAGS"]} #{RbConfig::CONFIG["EXTDLDFLAGS"]}" dldflags.sub!(/-Wl,-soname,\S+/, '') - dldflags.sub!("$(TARGET_ENTRY)", "Init_#{ext}") - link_cmd = "#{ldshared} #{obj} #{libpath} #{dldflags} #{libs} -o #{lib}" + if /mswin/ =~ RUBY_PLATFORM + dldflags.sub!("$(LIBPATH)", RbConfig::CONFIG["LIBPATHFLAG"] % path) + libs += RbConfig::CONFIG["LIBRUBY"] + outflag = RbConfig::CONFIG["OUTFLAG"] + + link_cmd = "#{ldshared} #{outflag}#{lib} #{obj} #{libs} -link #{dldflags} /export:Init_#{ext}" + else + libpath = "-L#{path}" + dldflags.sub!("$(TARGET_ENTRY)", "Init_#{ext}") + + link_cmd = "#{ldshared} #{obj} #{libpath} #{dldflags} #{libs} -o #{lib}" + end output = `#{link_cmd}` unless $?.success? - puts "ERROR:\n#{link_cmd}\n#{output}" + puts "\nERROR:\n#{link_cmd}\n#{output}" raise "Unable to link \"#{source}\"" end -- cgit v1.2.3