Specifying files to build with mkmf

Posted by admin

When you are creating makefiles with mkmf it automatically searches for source files in the directory. This is great as you do not have to specify them, just throw your files in the same directory as extconf.rb and the makefile generated will build everything. But there are times were you have more source files in that directory and you only want to build the extension with a subset.

Recently I have been creating ruby bindings for a C library in my project (DRMAA libraries for GridWay) and the directory contained not only ruby bindings but also perl and python ones. When extconf.rb was creating the Makefile and wrappers for perl and python bindings where there, it tried to build every file for the ruby extension and, of course, could not build it. So I searched in mkmf documentation for a way to specify just the files I wanted to build for my extension and there was no method I could use to do this.

Fortunately mkmf library is small and easy to understand. It uses two global variables ($srcs and $objs) that are arrays of files to build. By default these variables are empty and when you call create_makefile the variables are filled with all the source files in the directory ($objs is filled with .o files that will be generated). If these variables are already set it won’t try to find files and will use the data contained in them. So the solution is easy, fill these variables by yourself. This is the code I’m using to do this:

build_files=['drmaa_r_wrap']
$srcs=Array.new
$objs=Array.new
build_files.each{|f|
  $srcs<<f+'.c'
  $objs<<f+'.o'
}

You only have to fill build_files with the names of the files (without .c extension) you want to build. Of course this can be changed to add extensions to it and then change the extension for .o in the loop, but this was enough for me.

Filesystem for tags

Posted by thevaw

Some time ago talking about spotlight and google desktop one of my bosses told me that there should be something implemented in linux as a filesystem to find files. We concluded that directories served us well, but now are lacking flexibility as the data grows (number and type). After that not much discussion about that theme was made and I almost forgot it. Two weeks ago I’ve found FuseFS in rubyforge so I wanted to give it a try. Thinking about what to implement as a simple test I came out with the idea of reating that filesystem I were talking with my boss. You can download it here. You must be warned that it is completelly unusable and the code is messy as hell, but perhaps you want to play with it.

It consists in a database that holds file names (and also its path), a command line that adds files and tags to each file and the filesystem where you can search for files. There you have directories that are tag names. If you enter one of this directories you can see files with that tag and other directories (also tags), so if you go deeper in this tags/directories you’ll see files that have all the tags of the path you are in (for example, in /document/work/important/ you’ll see files that have tags document, work and important). To add tags to files you have a command called tfs where you specify a file and a list of tags to add or remove preceding the with + and – (for example tfs somefile +document +work -important). This is the only thing it does. You can not retrieve the files from there and should be lots of bugs, so I said it is completelly unusable.

To make this beast work you’ll need FuseFS, rubygems and sqlite libraries installed with rubygems. You can contact me at jfontanATzoolooDOTorg if you want any other information. I don’t think I’m going to continue this project as I am so busy with others right now but if I see people interested in it I can perhaps take the project again.