зеркало из https://github.com/github/ruby.git
65 строки
1.9 KiB
Ruby
65 строки
1.9 KiB
Ruby
# frozen_string_literal: true
|
|
# shareable_constant_value: literal
|
|
<%
|
|
arg = {}
|
|
while /\A(\w+)=(.*)/ =~ ARGV[0]
|
|
arg[$1] = $2
|
|
arg[$1].tr!(File::ALT_SEPARATOR, File::SEPARATOR) if File::ALT_SEPARATOR
|
|
ARGV.shift
|
|
end
|
|
if inc = arg['i']
|
|
src = inc == '-' ? STDIN.read : File.read(inc)
|
|
src.gsub!(/^#.*\n/, '')
|
|
else
|
|
src = ""
|
|
end
|
|
def src.value(name)
|
|
unless val = self[/\bruby_#{name}(?:\[\])?\s*=\s*((?:"(?:\\.|[^\"\\])*"\s*)*(?=;)|[^{};]+)/m, 1]
|
|
return
|
|
end
|
|
eval(val.gsub(/#/, '\\#').gsub(/((?:\G|[^\\])(?:\\\\)*)\n/, '\1'))
|
|
end
|
|
arg['versions'] = version = {}
|
|
File.read(File.join(arg['srcdir'], 'version.c')).
|
|
scan(/rb_define_global_const\("(RUBY_\w+)",[^;]*?\bMK(?:INT|(STR))\(([^()]*)\)/m) do |n, s, v|
|
|
version[n] = arg[v] || src.value(v) || (s ? v : 0)
|
|
end
|
|
-%>
|
|
baseruby="<%=arg['BASERUBY']%>"
|
|
_\
|
|
=begin
|
|
_=
|
|
ruby="${RUBY-$baseruby}"
|
|
case "$ruby" in "echo "*) $ruby; exit $?;; esac
|
|
case "$0" in /*) r=-r"$0";; *) r=-r"./$0";; esac
|
|
exec $ruby "$r" "$@"
|
|
=end
|
|
=baseruby
|
|
class Object
|
|
remove_const :CROSS_COMPILING if defined?(CROSS_COMPILING)
|
|
CROSS_COMPILING = RUBY_PLATFORM
|
|
options = remove_const(:RUBY_DESCRIPTION)[/( \+[^\[\]\+]+)*(?= \[\S+\]\z)/]
|
|
constants.grep(/^RUBY_/) {|n| remove_const n}
|
|
% arg['versions'].each {|n, v|
|
|
<%=n%> = <%if n=='RUBY_DESCRIPTION'
|
|
v1, v2 = v.split(/(?= \[\S+\]\z)/)
|
|
%><%=v1.dump.chomp('"')%>#{options}<%=
|
|
v2.dump[1..-1]%>.freeze<%
|
|
else%><%=v.inspect%><%end%>
|
|
% }
|
|
end
|
|
builddir = File.dirname(File.expand_path(__FILE__))
|
|
libpathenv = libpathenv = "<%=arg['LIBPATHENV']%>"
|
|
preloadenv = preloadenv = "<%=arg['PRELOADENV']%>"
|
|
libruby_so = libruby_so = "<%=arg['LIBRUBY_SO']%>"
|
|
srcdir = "<%=arg['srcdir']%>"
|
|
top_srcdir = File.realpath(srcdir, builddir)
|
|
fake = File.join(top_srcdir, "tool/fake.rb")
|
|
eval(File.binread(fake), nil, fake)
|
|
ropt = "-r#{__FILE__}"
|
|
["RUBYOPT"].each do |flag|
|
|
opt = ENV[flag]
|
|
opt = opt ? ([ropt] | opt.b.split(/\s+/)).join(" ") : ropt
|
|
ENV[flag] = opt
|
|
end
|