2fb58f
From 94da59aafacc6a9efe829529eb51385588d6f149 Mon Sep 17 00:00:00 2001
2fb58f
From: =?UTF-8?q?V=C3=ADt=20Ondruch?= <vondruch@redhat.com>
2fb58f
Date: Fri, 11 Nov 2011 13:14:45 +0100
2fb58f
Subject: [PATCH] Allow to install RubyGems into custom location, outside of
2fb58f
 Ruby tree.
2fb58f
2fb58f
---
2fb58f
 configure.ac            |  5 +++++
2fb58f
 loadpath.c              |  4 ++++
2fb58f
 template/verconf.h.tmpl |  3 +++
2fb58f
 tool/rbinstall.rb       | 10 ++++++++++
2fb58f
 4 files changed, 22 insertions(+)
2fb58f
2fb58f
diff --git a/configure.ac b/configure.ac
2fb58f
index 93af30321d..bc13397e0e 100644
2fb58f
--- a/configure.ac
2fb58f
+++ b/configure.ac
2fb58f
@@ -4062,6 +4062,10 @@ AC_ARG_WITH(vendorarchdir,
2fb58f
             [vendorarchdir=$withval],
2fb58f
             [vendorarchdir=${multiarch+'${rubysitearchprefix}/vendor_ruby'${ruby_version_dir}}${multiarch-'${vendorlibdir}/${sitearch}'}])
2fb58f
 
2fb58f
+AC_ARG_WITH(rubygemsdir,
2fb58f
+           AS_HELP_STRING([--with-rubygemsdir=DIR], [custom rubygems directory]),
2fb58f
+            [rubygemsdir=$withval])
2fb58f
+
2fb58f
 AS_IF([test "${LOAD_RELATIVE+set}"], [
2fb58f
     AC_DEFINE_UNQUOTED(LOAD_RELATIVE, $LOAD_RELATIVE)
2fb58f
     RUBY_EXEC_PREFIX=''
2fb58f
@@ -4086,6 +4090,7 @@ AC_SUBST(sitearchdir)dnl
2fb58f
 AC_SUBST(vendordir)dnl
2fb58f
 AC_SUBST(vendorlibdir)dnl
2fb58f
 AC_SUBST(vendorarchdir)dnl
2fb58f
+AC_SUBST(rubygemsdir)dnl
2fb58f
 
2fb58f
 AC_SUBST(CONFIGURE, "`echo $0 | sed 's|.*/||'`")dnl
2fb58f
 AC_SUBST(configure_args, "`echo "${ac_configure_args}" | sed 's/\\$/$$/g'`")dnl
2fb58f
diff --git a/loadpath.c b/loadpath.c
2fb58f
index 623dc9d..74c5d9e 100644
2fb58f
--- a/loadpath.c
2fb58f
+++ b/loadpath.c
2fb58f
@@ -94,6 +94,10 @@ const char ruby_initial_load_paths[] =
2fb58f
 #endif
2fb58f
 #endif
2fb58f
 
2fb58f
+#ifdef RUBYGEMS_DIR
2fb58f
+    RUBYGEMS_DIR "\0"
2fb58f
+#endif
2fb58f
+
2fb58f
     RUBY_LIB "\0"
2fb58f
 #ifdef RUBY_THINARCH
2fb58f
     RUBY_ARCH_LIB_FOR(RUBY_THINARCH) "\0"
2fb58f
diff --git a/template/verconf.h.tmpl b/template/verconf.h.tmpl
2fb58f
index 79c003e..34f2382 100644
2fb58f
--- a/template/verconf.h.tmpl
2fb58f
+++ b/template/verconf.h.tmpl
2fb58f
@@ -36,6 +36,9 @@
2fb58f
 % if C["RUBY_SEARCH_PATH"]
2fb58f
 #define RUBY_SEARCH_PATH		"${RUBY_SEARCH_PATH}"
2fb58f
 % end
2fb58f
+% if C["rubygemsdir"]
2fb58f
+#define RUBYGEMS_DIR			"${rubygemsdir}"
2fb58f
+% end
2fb58f
 %
2fb58f
 % R = {}
2fb58f
 % R["ruby_version"] = '"RUBY_LIB_VERSION"'
2fb58f
diff --git a/tool/rbinstall.rb b/tool/rbinstall.rb
2fb58f
index e9110a17ca..76a1f0a315 100755
2fb58f
--- a/tool/rbinstall.rb
2fb58f
+++ b/tool/rbinstall.rb
2fb58f
@@ -359,6 +359,7 @@ def CONFIG.[](name, mandatory = false)
2fb58f
   vendorlibdir = CONFIG["vendorlibdir"]
2fb58f
   vendorarchlibdir = CONFIG["vendorarchdir"]
2fb58f
 end
2fb58f
+rubygemsdir = CONFIG["rubygemsdir"]
2fb58f
 mandir = CONFIG["mandir", true]
2fb58f
 docdir = CONFIG["docdir", true]
2fb58f
 enable_shared = CONFIG["ENABLE_SHARED"] == 'yes'
2fb58f
@@ -590,7 +591,16 @@ def stub
2fb58f
 install?(:local, :comm, :lib) do
2fb58f
   prepare "library scripts", rubylibdir
2fb58f
   noinst = %w[*.txt *.rdoc *.gemspec]
2fb58f
+  # Bundler carries "rubygems.rb" file, so it must be specialcased :/
2fb58f
+  noinst += %w[rubygems.rb rubygems/ bundler.rb bundler/] if rubygemsdir
2fb58f
   install_recursive(File.join(srcdir, "lib"), rubylibdir, :no_install => noinst, :mode => $data_mode)
2fb58f
+  if rubygemsdir
2fb58f
+    noinst = %w[*.txt *.rdoc *.gemspec]
2fb58f
+    install_recursive(File.join(srcdir, "lib", "rubygems"), File.join(rubygemsdir, "rubygems"), :no_install => noinst, :mode => $data_mode)
2fb58f
+    install(File.join(srcdir, "lib", "rubygems.rb"), File.join(rubygemsdir, "rubygems.rb"), :mode => $data_mode)
2fb58f
+    install_recursive(File.join(srcdir, "lib", "bundler"), File.join(rubylibdir, "bundler"), :no_install => noinst, :mode => $data_mode)
2fb58f
+    install(File.join(srcdir, "lib", "bundler.rb"), rubylibdir, :mode => $data_mode)
2fb58f
+  end
2fb58f
 end
2fb58f
 
2fb58f
 install?(:local, :comm, :hdr, :'comm-hdr') do
2fb58f
-- 
2fb58f
1.8.3.1
2fb58f