2008-08-12 14:11:11 +04:00
|
|
|
#!/usr/bin/ruby -s
|
2008-10-28 10:13:39 +03:00
|
|
|
# -*- encoding: us-ascii -*-
|
2008-06-21 10:31:18 +04:00
|
|
|
require 'uri'
|
|
|
|
require 'digest/md5'
|
|
|
|
require 'digest/sha2'
|
|
|
|
require 'fileutils'
|
|
|
|
require 'tmpdir'
|
|
|
|
STDOUT.sync = true
|
2007-12-22 09:14:50 +03:00
|
|
|
|
2008-09-26 13:40:04 +04:00
|
|
|
$exported = nil if $exported == ""
|
|
|
|
$archname = nil if $archname == ""
|
|
|
|
|
2008-06-21 10:31:18 +04:00
|
|
|
ENV["LC_ALL"] = ENV["LANG"] = "C"
|
|
|
|
SVNURL = URI.parse("http://svn.ruby-lang.org/repos/ruby/")
|
|
|
|
RUBY_VERSION_PATTERN = /^\#define\s+RUBY_VERSION\s+"([\d.]+)"/
|
2008-06-19 16:35:35 +04:00
|
|
|
|
2008-06-21 10:31:18 +04:00
|
|
|
ENV["VPATH"] ||= "include/ruby"
|
|
|
|
YACC = ENV["YACC"] ||= "bison"
|
|
|
|
ENV["BASERUBY"] ||= "ruby"
|
|
|
|
ENV["RUBY"] ||= "ruby"
|
|
|
|
ENV["MV"] ||= "mv"
|
|
|
|
ENV["MINIRUBY"] ||= "ruby"
|
2007-12-22 09:14:50 +03:00
|
|
|
|
2008-10-28 10:13:39 +03:00
|
|
|
class String
|
|
|
|
# for older ruby
|
|
|
|
alias bytesize size unless method_defined?(:bytesize)
|
|
|
|
end
|
|
|
|
|
2008-08-12 14:11:11 +04:00
|
|
|
$patch_file &&= File.expand_path($patch_file)
|
2008-06-21 10:31:18 +04:00
|
|
|
path = ENV["PATH"].split(File::PATH_SEPARATOR)
|
|
|
|
%w[YACC BASERUBY RUBY MV MINIRUBY].each do |var|
|
|
|
|
cmd = ENV[var]
|
|
|
|
unless path.any? {|dir|
|
2008-09-26 13:40:04 +04:00
|
|
|
file = File.expand_path(cmd, dir)
|
2008-06-21 10:31:18 +04:00
|
|
|
File.file?(file) and File.executable?(file)
|
|
|
|
}
|
|
|
|
abort "#{File.basename $0}: #{var} command not found - #{cmd}"
|
|
|
|
end
|
|
|
|
end
|
2007-12-22 09:14:50 +03:00
|
|
|
|
2008-06-21 10:31:18 +04:00
|
|
|
unless destdir = ARGV.shift
|
|
|
|
abort "usage: #{File.basename $0} new-directory-to-save [version ...]"
|
|
|
|
end
|
|
|
|
revisions = ARGV.empty? ? ["trunk"] : ARGV
|
2008-08-12 14:11:11 +04:00
|
|
|
unless tmp = $exported
|
|
|
|
FileUtils.mkpath(destdir)
|
|
|
|
destdir = File.expand_path(destdir)
|
|
|
|
tmp = Dir.mktmpdir("ruby-snapshot")
|
|
|
|
FileUtils.mkpath(tmp)
|
|
|
|
at_exit {
|
|
|
|
Dir.chdir "/"
|
|
|
|
FileUtils.rm_rf(tmp)
|
|
|
|
} unless $keep_temp
|
|
|
|
end
|
2008-06-21 10:31:18 +04:00
|
|
|
Dir.chdir tmp
|
2008-06-19 16:35:35 +04:00
|
|
|
|
2008-06-21 10:31:18 +04:00
|
|
|
def package(rev, destdir)
|
|
|
|
patchlevel = false
|
|
|
|
case rev
|
|
|
|
when /\Atrunk\z/, /\Abranches\//, /\Atags\//
|
|
|
|
url = SVNURL + rev
|
|
|
|
when /\Astable\z/
|
|
|
|
url = SVNURL + "branches/"
|
|
|
|
url = url + `svn ls #{url}`[/.*^(ruby_\d+_\d+)\//m, 1]
|
2008-10-28 10:13:39 +03:00
|
|
|
when /\A(.*)\.(.*)\.(.*)-((?!preview)p)?(.*)/
|
2008-08-25 21:47:57 +04:00
|
|
|
patchlevel = !!$4
|
|
|
|
tag = "#{$4}#{$5}"
|
|
|
|
url = SVNURL + "tags/v#{$1}_#{$2}_#{$3}_#{$5}"
|
2008-06-21 10:31:18 +04:00
|
|
|
when /\./
|
|
|
|
url = SVNURL + "branches/ruby_#{rev.tr('.', '_')}"
|
|
|
|
else
|
|
|
|
warn "#{$0}: unknown version - #{rev}"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
revision = `svn info #{url} 2>&1`[/Last Changed Rev: (\d+)/, 1]
|
|
|
|
version = nil
|
|
|
|
unless revision
|
|
|
|
url = SVNURL + "trunk"
|
|
|
|
version = `svn cat #{url + "version.h"}`[RUBY_VERSION_PATTERN, 1]
|
|
|
|
unless rev == version
|
|
|
|
warn "#{$0}: #{rev} not found"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
revision = `svn info #{url}`[/Last Changed Rev: (\d+)/, 1]
|
|
|
|
end
|
2008-09-26 13:40:04 +04:00
|
|
|
v = nil
|
|
|
|
if $exported
|
|
|
|
if String === $exported
|
|
|
|
v = $exported
|
|
|
|
end
|
|
|
|
else
|
|
|
|
v = "ruby"
|
2008-08-12 14:11:11 +04:00
|
|
|
puts "Exporting #{rev}@#{revision}"
|
2008-09-26 13:40:04 +04:00
|
|
|
IO.popen("svn export #{url} #{v}") do |pipe|
|
2008-08-12 14:11:11 +04:00
|
|
|
pipe.each {|line| /^A/ =~ line or print line}
|
|
|
|
end
|
|
|
|
unless $?.success?
|
|
|
|
warn("Export failed")
|
|
|
|
return
|
|
|
|
end
|
2008-06-21 10:31:18 +04:00
|
|
|
end
|
2008-08-12 14:11:11 +04:00
|
|
|
|
2008-09-26 13:40:04 +04:00
|
|
|
if !File.directory?(v)
|
2008-08-13 05:45:35 +04:00
|
|
|
v = Dir.glob("ruby-*").select(&File.method(:directory?))
|
|
|
|
v.size == 1 or abort "not exported"
|
|
|
|
v = v[0]
|
|
|
|
end
|
2008-08-12 14:11:11 +04:00
|
|
|
open("#{v}/revision.h", "wb") {|f| f.puts "#define RUBY_REVISION #{revision}"}
|
|
|
|
version ||= (versionhdr = IO.read("#{v}/version.h"))[RUBY_VERSION_PATTERN, 1]
|
2008-06-21 10:31:18 +04:00
|
|
|
version or return
|
|
|
|
if patchlevel
|
2008-08-12 14:11:11 +04:00
|
|
|
versionhdr ||= IO.read("#{v}/version.h")
|
2008-06-21 10:31:18 +04:00
|
|
|
patchlevel = versionhdr[/^\#define\s+RUBY_PATCHLEVEL\s+(\d+)/, 1]
|
|
|
|
tag = (patchlevel ? "p#{patchlevel}" : "r#{revision}")
|
|
|
|
else
|
2008-08-25 21:47:57 +04:00
|
|
|
tag ||= "r#{revision}"
|
2008-06-21 10:31:18 +04:00
|
|
|
end
|
2008-09-26 13:40:04 +04:00
|
|
|
unless v == $exported
|
|
|
|
n = "ruby-#{version}-#{tag}"
|
|
|
|
File.directory?(n) or File.rename v, n
|
|
|
|
v = n
|
|
|
|
end
|
2008-08-13 05:45:35 +04:00
|
|
|
system("patch -d #{v} -p0 -i #{$patch_file}") if $patch_file
|
2008-08-13 08:09:15 +04:00
|
|
|
def (clean = []).add(n) push(n); n end
|
2008-06-21 10:31:18 +04:00
|
|
|
Dir.chdir(v) do
|
2008-08-13 08:09:15 +04:00
|
|
|
File.open(clean.add("cross.rb"), "w") {|f| f.puts "CROSS_COMPILING=true"}
|
2008-08-12 14:11:11 +04:00
|
|
|
unless File.exist?("configure")
|
|
|
|
print "creating configure..."
|
|
|
|
unless system("autoconf")
|
|
|
|
puts " failed"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
puts " done"
|
2008-06-21 10:31:18 +04:00
|
|
|
end
|
2008-08-13 08:09:15 +04:00
|
|
|
clean.add("autom4te.cache")
|
2008-06-21 10:31:18 +04:00
|
|
|
print "creating prerequisites..."
|
|
|
|
if File.file?("common.mk") && /^prereq/ =~ commonmk = IO.read("common.mk")
|
2008-08-12 14:11:11 +04:00
|
|
|
puts
|
2008-08-13 08:09:15 +04:00
|
|
|
extout = clean.add('tmp')
|
|
|
|
File.open(clean.add("config.status"), "w") {|f|
|
2008-08-12 14:11:11 +04:00
|
|
|
f.puts "s,@configure_args@,|#_!!_#|,g"
|
2008-08-13 08:09:15 +04:00
|
|
|
f.puts "s,@EXTOUT@,|#_!!_#|#{extout},g"
|
2008-08-12 14:11:11 +04:00
|
|
|
f.puts "s,@bindir@,|#_!!_#|,g"
|
|
|
|
f.puts "s,@ruby_install_name@,|#_!!_#|,g"
|
|
|
|
f.puts "s,@ARCH_FLAG@,|#_!!_#|,g"
|
|
|
|
f.puts "s,@CFLAGS@,|#_!!_#|,g"
|
|
|
|
f.puts "s,@CPPFLAGS@,|#_!!_#|,g"
|
|
|
|
f.puts "s,@LDFLAGS@,|#_!!_#|,g"
|
|
|
|
f.puts "s,@DLDFLAGS@,|#_!!_#|,g"
|
|
|
|
f.puts "s,@LIBEXT@,|#_!!_#|a,g"
|
|
|
|
f.puts "s,@OBJEXT@,|#_!!_#|o,g"
|
|
|
|
f.puts "s,@LIBRUBY@,|#_!!_#|liburyb.a,g"
|
|
|
|
f.puts "s,@LIBRUBY_A@,|#_!!_#|liburyb.a,g"
|
|
|
|
}
|
2008-08-13 08:09:15 +04:00
|
|
|
FileUtils.mkpath(hdrdir = "#{extout}/include/ruby")
|
|
|
|
File.open("#{hdrdir}/config.h", "w") {}
|
2008-08-12 14:11:11 +04:00
|
|
|
miniruby = ENV['MINIRUBY'] + " -rcross"
|
|
|
|
IO.popen("make -f - prereq srcdir=. IFCHANGE=tool/ifchange 'MINIRUBY=#{miniruby}'", "w") do |f|
|
2008-06-21 10:31:18 +04:00
|
|
|
f.puts(IO.read("Makefile.in")[/^lex\.c.*?^$/m])
|
|
|
|
f.puts(commonmk.gsub(/\{[^{}]*\}/, ""))
|
|
|
|
end
|
2008-08-13 08:09:15 +04:00
|
|
|
clean.push("rbconfig.rb", ".rbconfig.time")
|
2008-08-12 14:11:11 +04:00
|
|
|
print "prerequisites"
|
2008-06-19 16:35:35 +04:00
|
|
|
else
|
2008-06-21 10:31:18 +04:00
|
|
|
system("#{YACC} -o parse.c parse.y")
|
|
|
|
end
|
2008-08-13 08:09:15 +04:00
|
|
|
FileUtils.rm_rf(clean)
|
2008-06-21 10:31:18 +04:00
|
|
|
unless $?.success?
|
|
|
|
puts " failed"
|
|
|
|
return
|
|
|
|
end
|
|
|
|
puts " done"
|
|
|
|
end
|
2008-06-19 16:35:35 +04:00
|
|
|
|
2008-09-26 13:40:04 +04:00
|
|
|
if v == "."
|
|
|
|
v = File.basename(Dir.pwd)
|
|
|
|
Dir.chdir ".."
|
|
|
|
end
|
|
|
|
|
2008-06-21 10:31:18 +04:00
|
|
|
return [["bzip tarball", ".tar.bz2", %w"tar cjf"],
|
|
|
|
["gzip tarball", ".tar.gz", %w"tar czf"],
|
|
|
|
["zip archive", ".zip", %w"zip -qr"]
|
|
|
|
].collect do |mesg, ext, cmd|
|
2008-09-26 13:40:04 +04:00
|
|
|
file = "#{destdir}/#{v||$archname}#{ext}"
|
2008-06-21 10:31:18 +04:00
|
|
|
print "creating #{mesg}... #{file}"
|
|
|
|
if system(*(cmd + [file, v]))
|
|
|
|
puts " done"
|
|
|
|
file
|
|
|
|
else
|
|
|
|
puts " failed"
|
|
|
|
nil
|
2008-06-21 03:39:45 +04:00
|
|
|
end
|
2008-06-21 10:31:18 +04:00
|
|
|
end.compact
|
|
|
|
ensure
|
2008-08-12 14:11:11 +04:00
|
|
|
FileUtils.rm_rf(v) if v and !$exported and !$keep_temp
|
2008-06-21 10:31:18 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
revisions.collect {|rev| package(rev, destdir)}.flatten.each do |name|
|
2008-08-12 14:11:11 +04:00
|
|
|
name or next
|
2008-10-28 11:21:57 +03:00
|
|
|
str = open(name, "rb:binary") {|f| f.read}
|
2008-06-21 10:31:18 +04:00
|
|
|
md5 = Digest::MD5.hexdigest str
|
|
|
|
sha = Digest::SHA256.hexdigest str
|
2008-10-28 11:21:57 +03:00
|
|
|
puts "* #{name}"
|
|
|
|
puts " SIZE: #{str.bytesize} bytes"
|
|
|
|
puts " MD5: #{md5}"
|
|
|
|
puts " SHA256: #{sha}"
|
2008-06-21 10:31:18 +04:00
|
|
|
puts
|
|
|
|
end
|
2008-10-28 11:21:57 +03:00
|
|
|
|
|
|
|
# vim:fileencoding=US-ASCII sw=2 ts=4 noexpandtab ff=unix
|