Permalink
Browse files

Split up installer.rb

git-svn-id: svn+ssh://rubyforge.org/var/svn/rubygems/trunk@1343 3d4018f9-ac1a-0410-99e9-8a154d859a19
  • Loading branch information...
drbrain committed Aug 16, 2007
1 parent 05b5306 commit 5ab5a0aa53f9747d499d587d10d9494ef0ffdac7
View
@@ -0,0 +1,18 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'rubygems'
+
+##
+# Classes for building C extensions live here.
+
+module Gem::Ext; end
+
+require 'rubygems/ext/builder'
+require 'rubygems/ext/configure_builder'
+require 'rubygems/ext/ext_conf_builder'
+require 'rubygems/ext/rake_builder'
+
@@ -0,0 +1,56 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'rubygems/ext'
+
+class Gem::Ext::Builder
+
+ def self.class_name
+ name =~ /Ext::(.*)Builder/
+ $1.downcase
+ end
+
+ def self.make(dest_path, results)
+ unless File.exist? 'Makefile' then
+ raise Gem::InstallError, "Makefile not found:\n\n#{results.join "\n"}"
+ end
+
+ mf = File.read('Makefile')
+ mf = mf.gsub(/^RUBYARCHDIR\s*=\s*\$[^$]*/, "RUBYARCHDIR = #{dest_path}")
+ mf = mf.gsub(/^RUBYLIBDIR\s*=\s*\$[^$]*/, "RUBYLIBDIR = #{dest_path}")
+
+ File.open('Makefile', 'wb') {|f| f.print mf}
+
+ make_program = ENV['make']
+ unless make_program then
+ make_program = (/mswin/ =~ RUBY_PLATFORM) ? 'nmake' : 'make'
+ end
+
+ ['', ' install'].each do |target|
+ cmd = "#{make_program}#{target}"
+ results << cmd
+ results << `#{cmd} #{redirector}`
+
+ raise Gem::InstallError, "make#{target} failed:\n\n#{results}" unless
+ $?.exitstatus.zero?
+ end
+ end
+
+ def self.redirector
+ '2>&1'
+ end
+
+ def self.run(command, results)
+ results << command
+ results << `#{command} #{redirector}`
+
+ unless $?.exitstatus.zero? then
+ raise Gem::InstallError, "#{class_name} failed:\n\n#{results.join "\n"}"
+ end
+ end
+
+end
+
@@ -0,0 +1,24 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'rubygems/ext/builder'
+
+class Gem::Ext::ConfigureBuilder < Gem::Ext::Builder
+
+ def self.build(extension, directory, dest_path, results)
+ unless File.exist?('Makefile') then
+ cmd = "sh ./configure --prefix=#{dest_path}"
+
+ run cmd, results
+ end
+
+ make dest_path, results
+
+ results
+ end
+
+end
+
@@ -0,0 +1,23 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'rubygems/ext/builder'
+
+class Gem::Ext::ExtConfBuilder < Gem::Ext::Builder
+
+ def self.build(extension, directory, dest_path, results)
+ cmd = "#{Gem.ruby} #{File.basename extension}"
+ cmd << " #{ARGV.join ' '}" unless ARGV.empty?
+
+ run cmd, results
+
+ make dest_path, results
+
+ results
+ end
+
+end
+
@@ -0,0 +1,27 @@
+#--
+# Copyright 2006 by Chad Fowler, Rich Kilmer, Jim Weirich and others.
+# All rights reserved.
+# See LICENSE.txt for permissions.
+#++
+
+require 'rubygems/ext/builder'
+
+class Gem::Ext::RakeBuilder < Gem::Ext::Builder
+
+ def self.build(extension, directory, dest_path, results)
+ if File.basename(extension) =~ /mkrf_conf/i then
+ cmd = "#{Gem.ruby} #{File.basename extension}"
+ cmd << " #{ARGV.join " "}" unless ARGV.empty?
+ run cmd, results
+ end
+
+ cmd = ENV['rake'] || 'rake'
+ cmd << " RUBYARCHDIR=#{dest_path} RUBYLIBDIR=#{dest_path}"
+
+ run cmd, results
+
+ results
+ end
+
+end
+
Oops, something went wrong.

0 comments on commit 5ab5a0a

Please sign in to comment.