Using mkmf.rb / extconf.rb and autoconf/automake together

R

Rudi Cilibrasi

Hi everybody,

I'm having trouble understanding how to use the mkmf module properly,
especially in conjunction with autoconf / automake.

I would like to use extconf.rb to generate the Makefile in my ext/
directory, but there are problems. For instance, the generated Makefile
does not support the check: target, and so when somebody types
make check
at the top of my source tree it fails when recursively doing make check's
in each of the subdirs because there is no such target in the ext/ directory.
Another problem is how to pass on options like
../configure --prefix $HOME/mystuff/installpath
What is the "accepted" way to handle installation-directory overrides like
this using mkmf.rb? What about an override of the CC for cross-compilation?
So far, what I've done is run extconf.rb and then edited the resulting
Makefile, surely there is a better way?

Any pointers to good examples of a combination autoconf / automake / extconf.rb
that supports the features above would be greatly appreciated. I would also
appreciate any doc pointers. Cheers,

Rudi
 
T

Tim Hunter

Any pointers to good examples of a combination autoconf / automake /
extconf.rb that supports the features above would be greatly appreciated.
I would also appreciate any doc pointers. Cheers,

The RMagick (http://rmagick.rubyforge.org) installation procedure uses a
combination of autoconf/configure and Minero Aoki's setup.rb script
(http://i.loveruby.net/en/setup.html).

RMagick's configure script constructs a custom Makefile and a custom
extconf.rb. The targets in the top-level Makefile run the appropriate
setup.rb steps. The setup.rb script runs the custom extconf.rb and then
calls make on the Makefile that extconf.rb generated.

Convoluted, but it's reliable and flexible.

The actual code is probably easier to understand than my poor description.
Check out the RMagick CVS:
http://rubyforge.org/cgi-bin/viewcvs/cgi/viewcvs.cgi/RMagick/?cvsroot=rmagick

Of course feel free to ask questions.
 
N

nobu.nokada

Hi,

At Tue, 18 May 2004 04:33:52 +0900,
Rudi Cilibrasi wrote in [ruby-talk:100551]:
I would like to use extconf.rb to generate the Makefile in my ext/
directory, but there are problems. For instance, the generated Makefile
does not support the check: target, and so when somebody types
make check
at the top of my source tree it fails when recursively doing make check's
in each of the subdirs because there is no such target in the ext/ directory.

Add check: target to ext/depend file.
Another problem is how to pass on options like
../configure --prefix $HOME/mystuff/installpath
What is the "accepted" way to handle installation-directory overrides like
this using mkmf.rb? What about an override of the CC for cross-compilation?

An extension library's installation directory is fixed as
supplied by rbconfig.rb, and CC must match with ruby's one.
You need proper rbconfig.rb to cross-compile.
 
R

Rudi Cilibrasi

Ok very good, I have just a few more questions:

I was referred to RMagick as a good example to follow, and it does use
autoconf but not automake. Does anybody know of one example ruby program
that uses autoconf and automake, as most Gnu utilities now do, in combination
with any of the standard Ruby installation methods? I would
like to see details of how people have interfaced the two, because it seems
nearly impossible to do elegantly.

I have read that the setup.rb script scans the directories such as bin/
and installs everything in these directories. Isn't this incompatible
with autoconf / automake? For example, in automake, I specify explicitly
what programs to compile, which files are in the source distribution, and
anything that is not listed is not used. Is there some way to tell the
setup.rb script to only install some of the files in the bin/ directory?
The exact case of this problem is visible in one of my packages that you
can download from http://complearn.sourceforge.net/
Here, I solve the
#!/nobody/knows/where/to/find/ruby
script problem by using autoconf to first determine where Ruby is installed,
then using @RUBYBIN@ type autoconf substitutions to convert my shell
scripts that start with names like
maketree.in
and become (when translated and variable-substituted)
maketree
with the correct line on top. It seems the setup.rb script duplicates this
functionality to some extent. Unfortunately, since I keep my .in files
in the bin/ directory along with the "final" versions of my scripts, I
am afraid setup.rb would incorrectly install my files such as maketree.in
in the installation bin/ directory, and this is not what I want. I only
want 1/2 the files in there to be installed, and I want to say which ones
exactly.

An extension library's installation directory is fixed as
supplied by rbconfig.rb, and CC must match with ruby's one.
You need proper rbconfig.rb to cross-compile.

Thanks for these answers Nobu. I am afraid I still do not totally understand
the solution to my problems however.
My complearn project is written to build under Windows (MinGW) or Linux.
I have a shell script there, "scripts/makeall.zsh",
(http://cvs.sourceforge.net/viewcvs.py/complearn/complearn/scripts/makeall.zsh?view=markup)
that builds a .tar.gz source
distribution, a Debian package, and a Windows version using the MinGW
cross-compiler and Inno Setup, then uses ncftpput to ftp send the new
version up to SourceForge. It works well enough now, but you will see I
needed to pre-generate a Makefile under Windows (using ruby extconf.rb now)
and then edit it by hand in order to get this to work correctly. This is
obviously going to be painful to maintain over time as Ruby and my project
change, because I will have to remodify this Makefile by hand.
I have read through the small documentation I can find on setup.rb and
still cannot understand what is the correct way for me to structure this
project, or even how to tell it not to use gcc but instead
CC = i586-mingw32msvc-gcc
when cross-compiling? Right now, I use a command like the following in
my "makeSetup.sh" shell script to build a Windows version under Linux:

../configure --enable-winbuild --prefix=@TOPDIR@/scripts/buildtmp

(from http://cvs.sourceforge.net/viewcvs.py/complearn/complearn/scripts/makeSetup.sh.in?view=markup)

And then within my configure.ac:

(see http://cvs.sourceforge.net/viewcvs.py/complearn/complearn/configure.ac?view=markup)

AC_ARG_ENABLE(winbuild, "Cross compile for windows MinGW/MSYS", winbuild=true,
winbuild=false)
....
if $winbuild ; then
cp ext/winbuild/Makefile.winbuild ext/Makefile
else
AC_CONFIG_COMMANDS([ext/Makefile],[cd $srcdir/ext ; $RUBYBIN extconf.rb ; echo
'distdir:' >> Makefile ], [RUBYBIN=$RUBYBIN])
fi

In other words, I only run my extconf.rb script if I am not cross-compiling.
The ext/winbuild/Makefile.winbuild is my hand-editted Makefile.

I want to be able to build all 3 of my packaging formats
(.tar.gz, Debian i386 package, Windows i386 self-installing executable) using
one shell script meant to run under Linux. Can you explain more about the
right way to do this? Or was this sort of thing never intended to work with
the Ruby configuration system? I am wondering what the right approach should
be in this case.

Thanks for all the help everybody,

Rudi

--Multipart_Wed_May_19_08:58:06_2004-1--
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top