class Main $VERBOSE = nil #ENV["RUBYOPT"] = "-W0" require "rbconfig" require "fileutils" include FileUtils Makefile = <<-txt all: \t@ruby -e 42 clean: \t@ruby -e 42 install: \t@ruby -e 42 txt def initialize setup gen_makefile install_private_sqlite install_private_sqlite_ruby install_gem "posixlock" install_gem "arrayfields" install_gem "lockfile" end def setup @config = Config::CONFIG @prefix = File.dirname(File.expand_path(__FILE__)) Dir.chdir @prefix puts "-->> #{ Dir.pwd }" @libdir = File.join @prefix, "lib" @alldir = File.join @prefix, "all" @srcdir = File.join @alldir, "packages" @rqlibdir = Dir["#{ @libdir }/rq-*"].detect{|e| test ?d, e} @local = File.join @rqlibdir, "local" @arch = @config["sitearch"] || @config["arch"] @archdir = File.join @rqlibdir, @arch FileUtils.mkdir_p @local FileUtils.mkdir_p @archdir @ld_library_path = File.join @local, "lib" @ld_run_path = File.join @local, "lib" #ENV["LD_LIBRARY_PATH"] = "" #@ld_library_path ENV["LD_RUN_PATH"] = "" @srcs = Dir["#{ @srcdir }/*"] @ruby = File::join(@config['bindir'], @config['ruby_install_name']) << @config['EXEEXT'] end def gen_makefile indent = nil open("Makefile", "w") do |f| Makefile.each do |line| indent ||= line[%r/^\s*/] line[%r/^#{ indent }/] = '' f.puts line end end end def install_private_sqlite tgz = @srcs.detect{|tgz| tgz =~ %r/(sqlite)-(\d+\.\d+\.\d+)\.(tar\.gz|tgz)$/} abort "no sqlite" unless tgz base, version, ext = $1, $2, $3 tgz = File.expand_path tgz mkdir_p "build" Dir.chdir "build" do puts "-->> #{ Dir.pwd }" cp tgz, "." tgz = File.basename tgz spawn "gzip -f -d #{ tgz }" spawn "tar xf #{ base }-#{ version }*tar" Dir.chdir "#{ base }-#{ version }" do puts "-->> #{ Dir.pwd }" spawn "ls Makefile >/dev/null 2>&1 || ./configure --prefix=#{ @local }" spawn "make" spawn "make install" end end end def install_private_sqlite_ruby tgz = @srcs.detect{|tgz| tgz =~ %r/(sqlite-ruby)-(\d+\.\d+\.\d+)\.(tar\.gz|tgz)$/} abort "no sqlite-ruby" unless tgz base, version, ext = $1, $2, $3 tgz = File.expand_path tgz mkdir_p "build" Dir.chdir "build" do puts "-->> #{ Dir.pwd }" cp tgz, "." tgz = File.basename tgz spawn "gzip -f -d #{ tgz }" spawn "tar xf #{ base }-#{ version }*tar" Dir.chdir "#{ base }-#{ version }" do puts "-->> #{ Dir.pwd }" Dir.chdir "ext" do puts "-->> #{ Dir.pwd }" spawn "#{ @ruby } extconf.rb --with-sqlite-dir=#{ @local }" spawn "make" chmod 0755, "_sqlite.so" mv "_sqlite.so", @archdir puts "_sqlite.so => #{ @archdir }" end Dir.chdir "lib" do Dir["*"].each do |e| chmod 0644, e mv e, @rqlibdir puts "#{ e } => #{ @rqlibdir }" end end end end end def install_gem gem, opts = '' spawn "gem install #{ gem } #{ opts }" unless gem_installed?(gem) end def gem_installed? gem ` #{ @ruby } -r rubygems -r #{ gem } -e 42 2>&1 ` begin $?.exitstatus == 0 rescue false end end def spawn cmd #`#{ cmd } 2>&1` puts cmd system cmd ensure abort "cmd <#{ cmd }> failed with <#{ $?.inspect }>" unless $?.exitstatus == 0 end end Main.new