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.

Am 07.05.2012 00:58, schrieb Iñaki Baz C.:

also be compiled?

Thanks a lot.

I’ve once had the same problem and asked here on Ruby T., 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

On Mon, May 7, 2012 at 7:58 AM, Iaki Baz C. [email protected] wrote:

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

2012/5/7 Kubo T. [email protected]:

How to say in extconf.rb that files under utils/ subdirectory must

But it doesn’t work for rubinius.
Thanks a lot. Very useful information.