[C exten] mkmf: how to include .c and .h files within a subdirectory?

Hi, having the following file tree under my ext/ directory:

my_ext/
   extconf.rb
   my_ext.c
   utils/
      utils.c
      utils.h

How to say in extconf.rb that files under utils/ subdirectory must
also be compiled?

Thanks a lot.

···

--
Iñaki Baz Castillo
<ibc@aliax.net>

I’ve once had the same problem and asked here on Ruby Talk, but got no
satisfying answer. It is not possible without hacking mkmf, I finally
ended up putting everything in one directory. #create_makefile
(Class: Object (Ruby 1.9.3))
has an option for specifying *one* subdirectory where all files reside,
but for multiple subdirectories you’d have to create multiple C extensions.

If someone knows another way to accomplish the task, I’d be intererested
in it, because large C extensions are easier organised by use of
multiple directories.

Vale,
Marvin

···

Am 07.05.2012 00:58, schrieb Iñaki Baz Castillo:

Hi, having the following file tree under my ext/ directory:

my_ext/
   extconf.rb
   my_ext.c
   utils/
      utils.c
      utils.h

How to say in extconf.rb that files under utils/ subdirectory must
also be compiled?

Thanks a lot.

Though, IMO, there is no official way, here is a hack.

···

On Mon, May 7, 2012 at 7:58 AM, Iñaki Baz Castillo <ibc@aliax.net> wrote:

Hi, having the following file tree under my ext/ directory:

my_ext/
extconf.rb
my_ext.c
utils/
utils.c
utils.h

How to say in extconf.rb that files under utils/ subdirectory must
also be compiled?

----------------------------------
require 'mkmf'

# set all object files to $objs before create_makefile.
$objs = ["my_ext.o", "utils/utils.o"]

create_makefile("my_ext")

# to clean up object files under util subdirectory.
open('Makefile', 'a') do |f|
  f.write <<EOS

CLEANOBJS := $(CLEANOBJS) utils/*.#{CONFIG["OBJEXT"]}
EOS
end
----------------------------------

I have tested this with ruby 1.9.3p194 on linux.
But it doesn't work for rubinius.

Thanks a lot. Very useful information.

···

2012/5/7 Kubo Takehiro <kubo@jiubao.org>:

On Mon, May 7, 2012 at 7:58 AM, Iñaki Baz Castillo <ibc@aliax.net> wrote:

Hi, having the following file tree under my ext/ directory:

my_ext/
extconf.rb
my_ext.c
utils/
utils.c
utils.h

How to say in extconf.rb that files under utils/ subdirectory must
also be compiled?

Though, IMO, there is no official way, here is a hack.
----------------------------------
require 'mkmf'

# set all object files to $objs before create_makefile.
$objs = ["my_ext.o", "utils/utils.o"]

create_makefile("my_ext")

# to clean up object files under util subdirectory.
open('Makefile', 'a') do |f|
f.write <<EOS

CLEANOBJS := $(CLEANOBJS) utils/*.#{CONFIG["OBJEXT"]}
EOS
end
----------------------------------

I have tested this with ruby 1.9.3p194 on linux.
But it doesn't work for rubinius.

--
Iñaki Baz Castillo
<ibc@aliax.net>