9 ENV["LC_ALL"] = ENV["LANG"] = "C"
10 SVNURL
= URI
.parse("http://svn.ruby-lang.org/repos/ruby/")
11 RUBY_VERSION_PATTERN
= /^\#define\s+RUBY_VERSION\s+"([\d.]+)"/
13 ENV["VPATH"] ||= "include/ruby"
14 YACC
= ENV["YACC"] ||= "bison"
15 ENV["BASERUBY"] ||= "ruby"
16 ENV["RUBY"] ||= "ruby"
18 ENV["MINIRUBY"] ||= "ruby"
20 $patch_file &&= File
.expand_path($patch_file)
21 path
= ENV["PATH"].split(File
::PATH_SEPARATOR)
22 %w
[YACC BASERUBY RUBY MV MINIRUBY
].each
do |var
|
24 unless path
.any
? {|dir
|
25 file
= File
.join(dir
, cmd
)
26 File
.file
?(file
) and File
.executable
?(file
)
28 abort
"#{File.basename $0}: #{var} command not found - #{cmd}"
32 unless destdir
= ARGV.shift
33 abort
"usage: #{File.basename $0} new-directory-to-save [version ...]"
35 revisions
= ARGV.empty
? ? ["trunk"] : ARGV
36 unless tmp
= $exported
37 FileUtils
.mkpath(destdir
)
38 destdir
= File
.expand_path(destdir
)
39 tmp
= Dir
.mktmpdir("ruby-snapshot")
48 def package(rev
, destdir
)
51 when /\Atrunk\z/, /\Abranches\//, /\Atags\
//
54 url
= SVNURL
+ "branches/"
55 url
= url
+ `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m
, 1]
56 when /\A\(.*\..*\..*\)-/
58 url
= SVNURL
+ "tags/v#{rev.sub(/-p?/, '_').tr('.', '_')}"
60 url
= SVNURL
+ "branches/ruby_#{rev.tr('.', '_')}"
62 warn
"#{$0}: unknown version - #{rev}"
65 revision
= `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
68 url
= SVNURL
+ "trunk"
69 version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN
, 1]
71 warn
"#{$0}: #{rev} not found"
74 revision
= `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
77 puts
"Exporting #{rev}@#{revision}"
78 IO
.popen("svn export #{url} ruby") do |pipe
|
79 pipe
.each
{|line
| /^A/ =~ line
or print line
}
87 if !File
.directory
?(v
= "ruby")
88 v
= Dir
.glob("ruby-*").select(&File
.method(:directory?))
89 v
.size
== 1 or abort
"not exported"
92 open("#{v}/revision.h", "wb") {|f
| f
.puts
"#define RUBY_REVISION #{revision}"}
93 version ||= (versionhdr
= IO
.read("#{v}/version.h"))[RUBY_VERSION_PATTERN
, 1]
96 versionhdr
||= IO
.read("#{v}/version.h")
97 patchlevel
= versionhdr
[/^\#define\s+RUBY_PATCHLEVEL\s+(\d+)/, 1]
98 tag
= (patchlevel
? "p#{patchlevel}" : "r#{revision}")
102 v
= "ruby-#{version}-#{tag}"
103 File
.directory
?(v
) or File
.rename
"ruby", v
104 system("patch -d #{v} -p0 -i #{$patch_file}") if $patch_file
105 def (clean
= []).add(n
) push(n
); n
end
107 File
.open(clean
.add("cross.rb"), "w") {|f
| f
.puts
"CROSS_COMPILING=true"}
108 unless File
.exist
?("configure")
109 print
"creating configure..."
110 unless system("autoconf")
116 clean
.add("autom4te.cache")
117 print
"creating prerequisites..."
118 if File
.file
?("common.mk") && /^prereq/ =~ commonmk
= IO
.read("common.mk")
120 extout
= clean
.add('tmp')
121 File
.open(clean
.add("config.status"), "w") {|f
|
122 f
.puts
"s,@configure_args@,|#_!!_#|,g"
123 f
.puts
"s,@EXTOUT@,|#_!!_#|#{extout},g"
124 f
.puts
"s,@bindir@,|#_!!_#|,g"
125 f
.puts
"s,@ruby_install_name@,|#_!!_#|,g"
126 f
.puts
"s,@ARCH_FLAG@,|#_!!_#|,g"
127 f
.puts
"s,@CFLAGS@,|#_!!_#|,g"
128 f
.puts
"s,@CPPFLAGS@,|#_!!_#|,g"
129 f
.puts
"s,@LDFLAGS@,|#_!!_#|,g"
130 f
.puts
"s,@DLDFLAGS@,|#_!!_#|,g"
131 f
.puts
"s,@LIBEXT@,|#_!!_#|a,g"
132 f
.puts
"s,@OBJEXT@,|#_!!_#|o,g"
133 f
.puts
"s,@LIBRUBY@,|#_!!_#|liburyb.a,g"
134 f
.puts
"s,@LIBRUBY_A@,|#_!!_#|liburyb.a,g"
136 FileUtils
.mkpath(hdrdir
= "#{extout}/include/ruby")
137 File
.open("#{hdrdir}/config.h", "w") {}
138 miniruby
= ENV['MINIRUBY'] + " -rcross"
139 IO
.popen("make -f - prereq srcdir=. IFCHANGE=tool/ifchange 'MINIRUBY=#{miniruby}'", "w") do |f
|
140 f
.puts(IO
.read("Makefile.in")[/^lex\.c.*?^$/m
])
141 f
.puts(commonmk
.gsub(/\{[^{}]*\}/, ""))
143 clean
.push("rbconfig.rb", ".rbconfig.time")
144 print
"prerequisites"
146 system("#{YACC} -o parse.c parse.y")
148 FileUtils
.rm_rf(clean
)
156 return [["bzip tarball", ".tar.bz2", %w
"tar cjf"],
157 ["gzip tarball", ".tar.gz", %w
"tar czf"],
158 ["zip archive", ".zip", %w
"zip -qr"]
159 ].collect
do |mesg
, ext
, cmd
|
160 file
= "#{destdir}/#{v}#{ext}"
161 print
"creating #{mesg}... #{file}"
162 if system(*(cmd
+ [file
, v
]))
171 FileUtils
.rm_rf(v
) if v
and !$exported and !$keep_temp
174 revisions
.collect
{|rev
| package(rev
, destdir
)}.flatten
.each
do |name
|
176 str
= open(name
, "rb") {|f
| f
.read
}
177 md5
= Digest
::MD5.hexdigest str
178 sha
= Digest
::SHA256.hexdigest str
179 puts
"MD5(#{name})= #{md5}"
180 puts
"SHA256(#{name})= #{sha}"
181 puts
"SIZE(name)= #{str.size}"