summaryrefslogtreecommitdiff
path: root/template/fake.rb.in
blob: c7b11eff76a0334364791e67bcddd29fa38048c7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# 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)
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
arg['RUBY_DESCRIPTION_WITH_RJIT'] = src.value('description_with_rjit') || 'description_with_rjit'
arg['RUBY_DESCRIPTION_WITH_YJIT'] = src.value('description_with_yjit') || 'description_with_yjit'
%>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
  constants.grep(/^RUBY_/) {|n| remove_const n}
% arg['versions'].each {|n, v|
  <%=n%> = <%if n=='RUBY_DESCRIPTION' %>case
    when RubyVM.const_defined?(:RJIT) && RubyVM::RJIT.enabled?
      <%=arg['RUBY_DESCRIPTION_WITH_RJIT'].inspect%>
    when RubyVM.const_defined?(:YJIT) && RubyVM::YJIT.enabled?
      <%=arg['RUBY_DESCRIPTION_WITH_YJIT'].inspect%>
    else
      <%=v.inspect%>
    end<%else%><%=v.inspect%><%end%>
% }
end
builddir = File.dirname(File.expand_path(__FILE__))
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