[Ruby Forum] Ruby extconf.rb / autoconf (in?)compatibility

Discussion in 'Ruby' started by Alexey Verkhovsky, Sep 24, 2004.

  1. To all who said that Ruby Forum was a good idea (and all who said it
    wasn't, and all who said nothing) : please help.

    Unanswered question from http://www.ruby-forum.org/bb/viewtopic.php?t=53


    I have made a software packagae, complearn-0.6.2.tar.gz ,
    that uses autoconf and automake to manage system configuration. One of
    the standard options is:
    /configure --prefix=$HOME/wherever/placetoinstall

    In many autoconf or automake enabled software packages written in C
    (such as GNU / FSF utilities) this creates subdirectories like
    $HOME/wherever/placetoinstall/bin for executables
    $HOME/wherever/placetoinstall/lib for libraries
    $HOME/wherever/placetoinstall/man for manual_pages

    and so on for many common naming conventions.

    Unfortunately I cannot understand how to correctly pass this option on
    to ruby mkmf:
    ruby extconf.rb

    I have seen that there is an option to make using
    a DESTDIR variable such as:
    make DESTDIR=$HOME/wherever/placetoinstall

    but then this creates deep directory structure

    and to me it seems that the /usr/local portion of the above path
    structure is redundant. Is there a way to remove it in the ruby mkmf
    extconf.rb structure? The best I can come up with so far is to use an mv
    and then an rm command to correct things, and this seems somewhat
    complicated and error-prone.

    Is there a better solution to this problem?
    Alexey Verkhovsky, Sep 24, 2004
    1. Advertisements

  2. Alexey Verkhovsky

    nobu.nokada Guest


    At Sat, 25 Sep 2004 04:32:49 +0900,
    Alexey Verkhovsky wrote in [ruby-talk:113667]:
    They are decided at configuration time of ruby, but not at
    DESTDIR is used to install files in a fake root by package
    management systems.
    nobu.nokada, Sep 26, 2004
    1. Advertisements

  3. Hi again everybody,

    Unfortunately, Tim's solution is proving to be hard to understand; it
    really isn't a simple system he's made, and his configuration scripts
    have so many dependencies that I can't even get the package to
    configure on
    my Debian unstable system. I am working with Tim privately via email
    to try to get the problems installing his stuff straightened out, but
    while we do this I would like to reiterate the question:

    Is there any way to adjust the installation-paths that will be used
    in the Makefile generated by ruby extconf.rb ?

    Nobu has already pointed out that the problem is that these paths are
    determined at ruby install time. I also reached the same conclusion
    some time ago. The question is how do I fix it?
    The reason I need to do it is so that a non-root user can install
    my software package in their home directory. Is this simply
    in the current system? DESTDIR is not a complete solution because it
    not offer enough flexibility in customizing the paths. To me this
    to suggest a basic functionality void in the ruby installation system.
    What is the right way to do it? It seems to much to ask someone to
    install their own version of ruby in their homedir just so they can
    packages using mkmf / extconf.rb.

    One idea that occured to me is to create a customized rbconfig.rb to
    override the standard one, but I am not even sure how to do this
    actually overwriting the real systemwide rbconfg.rb file. Is there
    way to load my own custom rbconfig.rb instead of the default one that
    is system wide so that extconf.rb will install my package in different

    I really need help with this problem as it has been troubling me for
    a year, and none of my Ruby projects are packaged well enough for the
    users I am targetting. It's really the only limitation I have had
    serious trouble with so far. I would hate to redo much of the
    of extconf.rb but it seems like something like this will be necessary
    unless we can figure out

    a) is there critical functionality missing from the current mkmf
    (or am I just missing a simpler solution?)


    b) what can we do to fix it?


    Rudi Cilibrasi, Sep 27, 2004
  4. Alexey Verkhovsky

    HOWARD ARA T Guest

    what's wrong with this:

    ~/tmp > cat a.c
    #include <stdio.h>
    void Init_a()
    printf ("42\n");

    ~/tmp > cat extconf.rb
    require 'mkmf'
    create_makefile 'a'

    ~/tmp > make
    gcc -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.8/i686-linux -I/usr/local/lib/ruby/1.8/i686-linux -I. -c a.c
    gcc -shared -L"/usr/local/lib" -o a.so a.o -ldl -lcrypt -lm -lc

    ~/tmp > make install prefix=`pwd`
    install -c -p -m 0755 a.so /home/ahoward/tmp/lib/ruby/site_ruby/1.8/i686-linux

    ~/tmp > ls ./lib/ruby/site_ruby/1.8/i686-linux/a.so

    ~/tmp > ruby -r ./lib/ruby/site_ruby/1.8/i686-linux/a.so -e';'

    'make' allows to to set anything you want from the command line already -
    bindir, sbindir, datadir, etc. what more could you need to set?

    it seems simpler to create a little script which calls make overriding the
    makefile defaults. eg.

    ~/tmp > cat install.rb
    require 'getoptlong'

    makeopts = {}
    opts = GetoptLong.new(
    [ "--ruby", "-r", GetoptLong::REQUIRED_ARGUMENT ],
    [ "--make", "-m", GetoptLong::REQUIRED_ARGUMENT ],
    [ "--prefix", "-p", GetoptLong::REQUIRED_ARGUMENT ],
    [ "--datadir", "-d", GetoptLong::REQUIRED_ARGUMENT ]
    ).each{|o, a| makeopts[o[%r/[^-].*/]] = a}

    mode = ARGV.shift
    argv = ARGV.join ' '
    ruby = makeopts.delete('ruby') || 'ruby'
    make = makeopts.delete('make') || 'make'
    mopt = makeopts.map{|kv| kv.join '='}.join(' ')

    cmd =
    case mode
    when /config/
    "#{ ruby } extconf.rb #{ argv }"
    when /setup/
    "#{ make } #{ mopt } #{ argv }"
    when /install/
    "#{ make } install #{ mopt } #{ argv }"
    "#{ make } #{ mode } #{ mopt } #{ argv }"

    STDERR.puts "cmd <#{ cmd.strip }>"
    system cmd

    ~/tmp > ruby install.rb clean
    cmd <make clean>

    ~/tmp > ruby install.rb configure
    cmd <ruby extconf.rb>

    creating Makefile
    ~/tmp > ruby install.rb setup
    cmd <make>
    gcc -fPIC -g -O2 -I. -I/usr/local/lib/ruby/1.8/i686-linux -I/usr/local/lib/ruby/1.8/i686-linux -I. -c a.c
    gcc -shared -L"/usr/local/lib" -o a.so a.o -ldl -lcrypt -lm -lc

    ~/tmp > ruby install.rb install --prefix=/tmp/foo/bar/
    cmd <make install prefix=/tmp/foo/bar/>
    install -c -p -m 0755 a.so /tmp/foo/bar//lib/ruby/site_ruby/1.8/i686-linux

    in short, i think the 'make' program itself already supports all that you want
    and the ruby generated makefiles are very well behaved so all that's left is to
    design the interface you want and to, perhaps, have default values for things
    like 'prefix', etc... i understand that you are trying to accomplish this at
    the configuration stage, but this is is really a detail - what you want to do
    can be done, just not at the configuration stage. if you HAD to do it at the
    configuration stage it would be trivial to take the mopts above and munge the
    generated Makefile using them after the configure step.

    kind regards.

    | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov
    | PHONE :: 303.497.6469
    | A flower falls, even though we love it;
    | and a weed grows, even though we do not love it. | --Dogen
    HOWARD ARA T, Sep 27, 2004
  5. There is setup.rb which is used by some ruby extensions to do the
    configure/build/install stuff. I think it is quite flexible and accepts
    arguments for specifying all these paths. The minor problem is that the
    arguments have names that differ from the auto* argument names so one
    has to figure out which argument is which.
    At least this is my experience with install.rb/setup.rb of the
    extensions I tried to install.


    Michal Suchanek
    Michal 'hramrach' Suchanek, Sep 27, 2004
  6. Ah my faith in Ruby is restored. Thanks for the make tip Howard;
    although it was right in front of me, for some reason I didn't see
    this simple solution. Also thanks for the setup.rb tip Michal, I
    think finally I can see a solution to my installation problems. I
    will repackage my stuff using these techniques and post again if there
    are any more problems. Thanks again for the useful help from
    everyone. Cheers,

    Rudi Cilibrasi, Sep 28, 2004
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.