./configure --libdir problem

I've got a compilation issue.

If I set --libdir when compiling ruby-1.8.2, I find that ruby installs its
standard libraries in one place, but at runtime it looks for them in the
wrong place.

To demonstrate, let me build ruby like this:

  # mkdir /opt /opt/lib /opt/include
...
  $ ./configure --prefix=/opt/ruby --libdir=/opt/lib \
                 --with-cppflags=-I/opt/include --with-ldflags=-L/opt/lib
  $ make
  $ sudo make install

[the reason is to keep ruby together with the external libraries I need to
link it against]

Now, if I do this, I find that Ruby's libraries are installed here:

  /opt/lib/ruby/1.8 # .rb files
  /opt/lib/ruby/1.8/i386-freebsd5.3 # .so files

But the Ruby binary is searching for them elsewhere:

  $ /opt/ruby/bin/ruby -e 'p $:'
  ["/opt/ruby/lib/ruby/site_ruby/1.8",
   "/opt/ruby/lib/ruby/site_ruby/1.8/i386-freebsd5.3",
   "/opt/ruby/lib/ruby/site_ruby",
   "/opt/ruby/lib/ruby/1.8", # <<<< NOTE
   "/opt/ruby/lib/ruby/1.8/i386-freebsd5.3", # <<<< NOTE
   "."]

As a result, none of the ruby system libraries can be found:

  $ /opt/ruby/bin/irb
  /opt/ruby/bin/irb:10:in `require': No such file to load -- irb (LoadError)
          from /opt/ruby/bin/irb:10

Now, I would have thought that setting --libdir would automatically update
rubylibdir and archdir, and in fact it has done so:

  $ /opt/ruby/bin/ruby -rrbconfig -e 'p Config::CONFIG["rubylibdir"]'
  "/opt/lib/ruby/1.8"
  $ /opt/ruby/bin/ruby -rrbconfig -e 'p Config::CONFIG["archdir"]'
  "/opt/lib/ruby/1.8/i386-freebsd5.3"

So, why is $: not set to the correct value? It seems that it the wrong value
exists in config.h:

$ grep RUBY_LIB *
config.h:#define RUBY_LIB "/opt/ruby/lib/ruby/1.8"

but it's not clear to me why that should be, since it's created from within
the ./configure script, which ought to have access to the --libdir
parameter. As far as I can tell it's an oversight, because RUBY_LIB_PREFIX
is derived directly from ${prefix}, not from ${libdir}.

Now, I'd be happy to work around this by setting rubylibdir to
    /opt/ruby/lib/ruby/1.8
so that the library files are installed in the place where $: expects to
find them; however I can't see how to do this.

  ./configure --rubylibdir=/opt/ruby/lib/ruby/1.8 # gives an error
  ./configure --with-rubylibdir=/opt/ruby/lib/ruby/1.8 # has no effect

So I'm a bit stumped now. To summarise:

  (1) "./configure --libdir=/foo" correctly updates rubylibdir so that
      the .rb/.so files are installed there, but does not update RUBY_LIB
      in config.h, so $: has the wrong path to those files.

And:

  (2) I can't see a way from the ./configure line to set
      CONFIG["rubylibdir"] independently of --libdir

Any suggestions for how I can work around this? Unfortunately, I do really
want to specify --prefix and --libdir separately for my particular file
layout.

Thanks,

Brian.

I made a patch which seems to fix this for me - see below. (Note that I've
not run it through autoconf; I just edited configure and configure.in by
hand)

There is still the underlying issue that, in effect, the same value is being
calculated twice independently:

  prefix/libdir --> ./configure ----> RUBY_LIB_PREFIX in config.h ---> $:
                             \
                              `--> mkconfig.rb --> rbconfig.rb
                                                   [rubylibdir]
                                                      \
                                                       `-> files installed
                                                                 here

But at least, overriding --libdir now has (hopefully) the same effect on
both.

Regards,

Brian.

ruby-libdir (1.88 KB)

···

On Thu, Feb 17, 2005 at 05:49:32PM +0000, Brian Candler wrote:

If I set --libdir when compiling ruby-1.8.2, I find that ruby installs its
standard libraries in one place, but at runtime it looks for them in the
wrong place.