@@ -0,0 +1,76 @@
+Index: lib/rubygems/install_update_options.rb
+===================================================================
+--- lib/rubygems/install_update_options.rb.orig 2009-06-23 00:54:36.000000000 +0200
++++ lib/rubygems/install_update_options.rb 2009-09-29 18:41:37.264306000 +0200
+@@ -34,6 +34,12 @@ module Gem::InstallUpdateOptions
+ options[:bin_dir] = File.expand_path(value)
+ end
+
++ add_option(:"Install/Update", '--build-root DIR',
++ 'Temporary installation root. Useful for building',
++ 'packages. Do not use this when installing remote gems.') do |value, options|
++ options[:build_root] = File.expand_path(value)
++ end
++
+ add_option(:"Install/Update", '-d', '--[no-]rdoc',
+ 'Generate RDoc documentation for the gem on',
+ 'install') do |value, options|
+Index: lib/rubygems/installer.rb
+===================================================================
+--- lib/rubygems/installer.rb.orig 2009-06-23 00:54:36.000000000 +0200
++++ lib/rubygems/installer.rb 2009-09-29 18:34:34.642131000 +0200
+@@ -114,6 +114,7 @@ class Gem::Installer
+ @bin_dir = options[:bin_dir]
+ @development = options[:development]
+ @source_index = options[:source_index]
++ @build_root = options[:build_root]
+
+ begin
+ @format = Gem::Format.from_file_by_path @gem, @security_policy
+@@ -127,10 +128,10 @@ class Gem::Installer
+ # We'll divert to ~/.gems below
+ end
+
+- if not File.writable? @gem_home or
++ if @build_root.nil? and (not File.writable? @gem_home or
+ # TODO: Shouldn't have to test for existence of bindir; tests need it.
+ (@gem_home.to_s == Gem.dir and File.exist? Gem.bindir and
+- not File.writable? Gem.bindir) then
++ not File.writable? Gem.bindir)) then
+ if options[:user_install] == false then # You don't want to use ~
+ raise Gem::FilePermissionError, @gem_home
+ elsif options[:user_install].nil? then
+@@ -158,6 +159,13 @@ class Gem::Installer
+ raise Gem::FilePermissionError, @gem_home unless File.writable? @gem_home
+ end
+
++ unless @build_root.nil?
++ @build_root = Pathname.new(@build_root).expand_path
++ @bin_dir = File.join(@build_root, options[:bin_dir] || Gem.bindir(@gem_home))
++ @gem_home = File.join(@build_root,@gem_home)
++ alert_warning "You build with buildroot.\n Build root: #{@build_root}\n Bin dir: #{@bin_dir}\n Gem home: #{@gem_home}"
++ end
++
+ @spec = @format.spec
+
+ @gem_dir = File.join(@gem_home, "gems", @spec.full_name).untaint
+Index: lib/rubygems/dependency_installer.rb
+===================================================================
+--- lib/rubygems/dependency_installer.rb.orig 2009-06-23 00:54:36.000000000 +0200
++++ lib/rubygems/dependency_installer.rb 2009-09-29 18:34:34.768130000 +0200
+@@ -68,6 +68,7 @@ class Gem::DependencyInstaller
+ @installed_gems = []
+
+ @install_dir = options[:install_dir] || Gem.dir
++ @build_root = options[:build_root]
+ @cache_dir = options[:cache_dir] || @install_dir
+ end
+
+@@ -244,6 +245,7 @@ class Gem::DependencyInstaller
+ :format_executable => @format_executable,
+ :ignore_dependencies => @ignore_dependencies,
+ :install_dir => @install_dir,
++ :build_root => @build_root,
+ :security_policy => @security_policy,
+ :source_index => @source_index,
+ :user_install => @user_install,
|