2009-06-24 11:07:59 +04:00
|
|
|
#!./miniruby -sI.
|
2000-08-03 13:55:54 +04:00
|
|
|
|
2006-09-08 23:48:22 +04:00
|
|
|
$name = $library = $description = nil
|
|
|
|
|
* mkconfig.rb: generate RbConfig instead of Config.
* instruby.rb, rubytest.rb, runruby.rb, bcc32/Makefile.sub,
ext/extmk.rb, ext/dl/extconf.rb, ext/iconv/charset_alias.rb,
lib/mkmf.rb, lib/rdoc/ri/ri_paths.rb,
lib/webrick/httpservlet/cgihandler.rb,
test/dbm/test_dbm.rb, test/gdbm/test_gdbm.rb,
test/ruby/envutil.rb, test/soap/calc/test_calc_cgi.rb,
test/soap/header/test_authheader_cgi.rb, test/soap/ssl/test_ssl.rb,
win32/mkexports.rb, win32/resource.rb: Use RbConfig instead of
Config.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-02-20 11:34:53 +03:00
|
|
|
module RbConfig
|
2010-02-08 10:23:13 +03:00
|
|
|
autoload :CONFIG, "./rbconfig"
|
2000-08-03 13:55:54 +04:00
|
|
|
end
|
|
|
|
|
2005-11-05 07:43:46 +03:00
|
|
|
class Exports
|
2017-10-29 02:54:16 +03:00
|
|
|
PrivateNames = /(?:Init_|ruby_static_id_|.*_threadptr_|rb_ec_|DllMain\b)/
|
2015-02-23 10:05:23 +03:00
|
|
|
|
2009-02-03 02:18:30 +03:00
|
|
|
@@subclass = []
|
2005-11-05 07:43:46 +03:00
|
|
|
def self.inherited(klass)
|
2009-02-03 02:18:30 +03:00
|
|
|
@@subclass << [/#{klass.name.sub(/.*::/, '').downcase}/i, klass]
|
2005-11-05 07:43:46 +03:00
|
|
|
end
|
|
|
|
|
|
|
|
def self.create(*args, &block)
|
|
|
|
platform = RUBY_PLATFORM
|
2009-02-03 02:18:30 +03:00
|
|
|
pat, klass = @@subclass.find {|p, k| p =~ platform}
|
2005-11-05 07:43:46 +03:00
|
|
|
unless klass
|
|
|
|
raise ArgumentError, "unsupported platform: #{platform}"
|
|
|
|
end
|
|
|
|
klass.new(*args, &block)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.extract(objs, *rest)
|
|
|
|
create(objs).exports(*rest)
|
|
|
|
end
|
|
|
|
|
|
|
|
def self.output(output = $output, &block)
|
|
|
|
if output
|
2008-05-28 12:50:41 +04:00
|
|
|
open(output, 'wb', &block)
|
2005-11-05 07:43:46 +03:00
|
|
|
else
|
|
|
|
yield STDOUT
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def initialize(objs)
|
|
|
|
syms = {}
|
|
|
|
winapis = {}
|
2010-11-10 01:20:12 +03:00
|
|
|
syms["ruby_sysinit_real"] = "ruby_sysinit"
|
2005-11-05 07:43:46 +03:00
|
|
|
each_export(objs) do |internal, export|
|
|
|
|
syms[internal] = export
|
|
|
|
winapis[$1] = internal if /^_?(rb_w32_\w+)(?:@\d+)?$/ =~ internal
|
|
|
|
end
|
2011-11-28 07:15:31 +04:00
|
|
|
incdir = File.join(File.dirname(File.dirname(__FILE__)), "include/ruby")
|
|
|
|
read_substitution(incdir+"/win32.h", syms, winapis)
|
|
|
|
read_substitution(incdir+"/subst.h", syms, winapis)
|
|
|
|
syms["rb_w32_vsnprintf"] ||= "ruby_vsnprintf"
|
|
|
|
syms["rb_w32_snprintf"] ||= "ruby_snprintf"
|
|
|
|
@syms = syms
|
|
|
|
end
|
|
|
|
|
|
|
|
def read_substitution(header, syms, winapis)
|
|
|
|
IO.foreach(header) do |line|
|
2005-11-05 07:43:46 +03:00
|
|
|
if /^#define (\w+)\((.*?)\)\s+(?:\(void\))?(rb_w32_\w+)\((.*?)\)\s*$/ =~ line and
|
|
|
|
$2.delete(" ") == $4.delete(" ")
|
|
|
|
export, internal = $1, $3
|
|
|
|
if syms[internal] or internal = winapis[internal]
|
|
|
|
syms[forwarding(internal, export)] = internal
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def exports(name = $name, library = $library, description = $description)
|
|
|
|
exports = []
|
|
|
|
if name
|
|
|
|
exports << "Name " + name
|
|
|
|
elsif library
|
|
|
|
exports << "Library " + library
|
|
|
|
end
|
|
|
|
exports << "Description " + description.dump if description
|
2008-12-22 06:26:22 +03:00
|
|
|
exports << "VERSION #{RbConfig::CONFIG['MAJOR']}.#{RbConfig::CONFIG['MINOR']}"
|
2005-11-05 07:43:46 +03:00
|
|
|
exports << "EXPORTS" << symbols()
|
|
|
|
exports
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
def forwarding(internal, export)
|
|
|
|
internal.sub(/^[^@]+/, "\\1#{export}")
|
|
|
|
end
|
|
|
|
|
|
|
|
def each_export(objs)
|
|
|
|
end
|
|
|
|
|
2008-05-28 12:50:41 +04:00
|
|
|
def objdump(objs, &block)
|
|
|
|
if objs.empty?
|
|
|
|
$stdin.each_line(&block)
|
|
|
|
else
|
|
|
|
each_line(objs, &block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-05 07:43:46 +03:00
|
|
|
def symbols()
|
2007-10-13 04:02:20 +04:00
|
|
|
@syms.sort.collect {|k, v| v ? v == true ? "#{k} DATA" : "#{k}=#{v}" : k}
|
2005-11-05 07:43:46 +03:00
|
|
|
end
|
2000-08-03 13:55:54 +04:00
|
|
|
end
|
|
|
|
|
2005-11-05 07:43:46 +03:00
|
|
|
class Exports::Mswin < Exports
|
2008-05-28 12:50:41 +04:00
|
|
|
def each_line(objs, &block)
|
|
|
|
IO.popen(%w"dumpbin -symbols -exports" + objs) do |f|
|
|
|
|
f.each(&block)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-05 07:43:46 +03:00
|
|
|
def each_export(objs)
|
2007-06-27 15:47:53 +04:00
|
|
|
noprefix = ($arch ||= nil and /^(sh|i\d86)/ !~ $arch)
|
2005-11-05 07:43:46 +03:00
|
|
|
objs = objs.collect {|s| s.tr('/', '\\')}
|
|
|
|
filetype = nil
|
2008-05-28 12:50:41 +04:00
|
|
|
objdump(objs) do |l|
|
|
|
|
if (filetype = l[/^File Type: (.+)/, 1])..(/^\f/ =~ l)
|
|
|
|
case filetype
|
|
|
|
when /OBJECT/, /LIBRARY/
|
|
|
|
next if /^[[:xdigit:]]+ 0+ UNDEF / =~ l
|
|
|
|
next unless /External/ =~ l
|
2016-12-14 20:49:26 +03:00
|
|
|
next if /(?:_local_stdio_printf_options|v(f|sn?)printf(_s)?_l)\Z/ =~ l
|
2008-05-28 12:50:41 +04:00
|
|
|
next unless l.sub!(/.*?\s(\(\)\s+)?External\s+\|\s+/, '')
|
|
|
|
is_data = !$1
|
|
|
|
if noprefix or /^[@_]/ =~ l
|
2012-11-12 09:29:52 +04:00
|
|
|
next if /(?!^)@.*@/ =~ l || /@[[:xdigit:]]{8,32}$/ =~ l ||
|
2015-02-23 10:05:23 +03:00
|
|
|
/^_?#{PrivateNames}/o =~ l
|
2008-05-28 12:50:41 +04:00
|
|
|
l.sub!(/^[@_]/, '') if /@\d+$/ !~ l
|
|
|
|
elsif !l.sub!(/^(\S+) \([^@?\`\']*\)$/, '\1')
|
2005-11-05 07:43:46 +03:00
|
|
|
next
|
|
|
|
end
|
2008-05-28 12:50:41 +04:00
|
|
|
when /DLL/
|
|
|
|
next unless l.sub!(/^\s*\d+\s+[[:xdigit:]]+\s+[[:xdigit:]]+\s+/, '')
|
|
|
|
else
|
|
|
|
next
|
2005-11-05 07:43:46 +03:00
|
|
|
end
|
2008-05-28 12:50:41 +04:00
|
|
|
yield l.strip, is_data
|
2005-11-05 07:43:46 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
yield "strcasecmp", "msvcrt.stricmp"
|
|
|
|
yield "strncasecmp", "msvcrt.strnicmp"
|
|
|
|
end
|
2000-08-03 13:55:54 +04:00
|
|
|
end
|
2005-11-05 07:43:46 +03:00
|
|
|
|
2009-02-03 02:18:30 +03:00
|
|
|
class Exports::Cygwin < Exports
|
2005-11-05 07:43:46 +03:00
|
|
|
def self.nm
|
* mkconfig.rb: generate RbConfig instead of Config.
* instruby.rb, rubytest.rb, runruby.rb, bcc32/Makefile.sub,
ext/extmk.rb, ext/dl/extconf.rb, ext/iconv/charset_alias.rb,
lib/mkmf.rb, lib/rdoc/ri/ri_paths.rb,
lib/webrick/httpservlet/cgihandler.rb,
test/dbm/test_dbm.rb, test/gdbm/test_gdbm.rb,
test/ruby/envutil.rb, test/soap/calc/test_calc_cgi.rb,
test/soap/header/test_authheader_cgi.rb, test/soap/ssl/test_ssl.rb,
win32/mkexports.rb, win32/resource.rb: Use RbConfig instead of
Config.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@9970 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2006-02-20 11:34:53 +03:00
|
|
|
@@nm ||= RbConfig::CONFIG["NM"]
|
2005-11-05 07:43:46 +03:00
|
|
|
end
|
|
|
|
|
2008-12-22 06:26:22 +03:00
|
|
|
def exports(*)
|
|
|
|
super()
|
|
|
|
end
|
|
|
|
|
2008-05-28 12:50:41 +04:00
|
|
|
def each_line(objs, &block)
|
|
|
|
IO.foreach("|#{self.class.nm} --extern --defined #{objs.join(' ')}", &block)
|
|
|
|
end
|
|
|
|
|
2005-11-05 07:43:46 +03:00
|
|
|
def each_export(objs)
|
2010-11-11 14:45:32 +03:00
|
|
|
symprefix = RbConfig::CONFIG["SYMBOL_PREFIX"]
|
|
|
|
symprefix.strip! if symprefix
|
2015-02-23 10:05:23 +03:00
|
|
|
re = /\s(?:(T)|[[:upper:]])\s#{symprefix}((?!#{PrivateNames}).*)$/
|
2008-05-28 12:50:41 +04:00
|
|
|
objdump(objs) do |l|
|
2009-02-04 05:50:04 +03:00
|
|
|
next if /@.*@/ =~ l
|
2010-11-11 14:45:32 +03:00
|
|
|
yield $2, !$1 if re =~ l
|
2005-11-05 07:43:46 +03:00
|
|
|
end
|
2009-02-03 02:18:30 +03:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2010-10-03 19:06:23 +04:00
|
|
|
class Exports::Mingw < Exports::Cygwin
|
2010-09-23 13:59:38 +04:00
|
|
|
def each_export(objs)
|
2010-10-05 17:20:49 +04:00
|
|
|
super
|
2010-09-23 13:59:38 +04:00
|
|
|
yield "strcasecmp", "_stricmp"
|
|
|
|
yield "strncasecmp", "_strnicmp"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2005-11-05 07:43:46 +03:00
|
|
|
END {
|
|
|
|
exports = Exports.extract(ARGV)
|
2006-09-08 23:48:22 +04:00
|
|
|
Exports.output {|f| f.puts(*exports)}
|
2005-11-05 07:43:46 +03:00
|
|
|
}
|