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.

Coding editor

Posted by thevaw

Being an amateur programmer makes choosing the editor of choice a very important decision. I’ve been using lots of editors to do my stuff. At first I made in line code in Spectrum Basic and later on using gwbasic, that came with MSDOS. But this was not really editing, just throwing lines hoping that the interpreter did not complain too much.

When I moved to compiled code I first started with PE2 at clipper summer classes I took one year (I don’t know why the hell I took clipper classes at the age of 14). I could not say much about it other that it was the first real editor I tried, it resembled vim a bit. After this I started learning pascal using Turbo/Borland Pascal 6. I really liked the editor, that where the first key strokes I learnt and I used through all my DOS life. My other editor was Dos Navigator embedded editor that had the same key bindings as Borland editors.

Entering in linux world was a bit disappointing as the first time I started it I had only vi to edit files. I couldn’t even find how to exit the editor in a standard way, only killing it! I started to hate vi and clones. I found joe and used along with jed in linux until I started my first (and only) job.

In 98/99 I switched from DOS to Windows and programmed using Visual C++ so my editor of choice in Windows was Visual Studio. I also installed a plugin for it called Visual Assist. It was a joy back then to have that powerful class browser and code completion.

I was living so happy with the tools I was using until I started to work. At job I work as Unix technician so the first thing I made was compiling joe in every computer I had to work with (scripting, editing configuration files and sometimes bug hunting in others code). But after some months I had to work in more machines and some of them had some exotic versions of unix. There was the time when I decide to start learning vi as it was installed in every machine, my work colleages where also happily using vi so this also pushed me to use it. At first it was more a pain than anything else but as I started learning tricks from my work colleages and my experience with it grew I became a happy vim user. I could change things with a few keystrokes, find using regular expressions and even had automatic macros of the last editing command. I also began to use vim in Windows as most of my mistakes in Visual C++ where the text ”:w” at the end of some lines :)

Now I use vim in every platform I touch for code and configuration editing purposes. But I also feel the need of an IDE where to manage the entire project, compile and perhaps debug from it. Recently I brought an iBook and tried TextMate, that impressed me a lot after seeing the rails demo video. I really like it but I do not feel as good with it as with vim. Perhaps is that I do not have the same experience with TextMate and I’m not used to its key bindings but I came back to vim again. I’ve just tried gvim for MacOSX and I am do delighted with its features (like code folding, auto completion and such things). gvim was found after reading this Jamis Buck blog post. I will also try some editors/IDEs commented there but I do not want to sacrifice editing smoothness I have with vim for a fill featured IDE solution. I’ll try to find a way to use vim and also manage my projects but I think I will fall back to shell as project manager and launching vim for each file I want to edit.

VoIP billing

Posted by thevaw

This days I’ve been helping with VoIP billing. There’s a quintum VoIP enabled gateway that is not configured to use radius, it just spits its own formatted CDRs (csv with information about calls). We had been searching programs to do this but seems that every one needs radius output or it is veeeery expensive.

My first move was to find an opensource one and modify it to understand this files. I failed miserably. I started making a quintum CDR to asterisk CDR conversor but what I had not notized was that programs compatible with asterisk uses special log files that came with a patch for the code (enables logging directly into mysq database). I gave up this approximation.

Having done a little library to deal with CDR reading I offered myself to calculate billing using the code I made for the conversor. It came out a pretty library to manage CDR data and do billing and people in charge of this VoIP gateway was very satisfied about the results. They asked me to make this program a bit more friendly (right now is just a script in ruby without command line interface). Posibilities to make this more friendly for them (they do not have technical background) is a GUI that runs on windows (ugh) or a web interface. I started reading some documentation about GUI’s and how behave in windows, also taking into account that I am developing this on MacOSX.

Yesterday in the train (one trip of 1:20 and other of 2:40) I started mocking up a rails application. After creating mysql tables some functionality from old library was added to the table objects so my main billing class could run independent of table clases (I mean, it could use old classes that just deal with arrays or with activerecord ones I added some functionality from the old ones). Now it transparently adds this data to mysql database and I can even get calls for different telcos or clasify them by time window. I’m pretty fond of class organization for the old version, so I now sould only move some functionality and I can reuse most of the code with rails.

I’ll try to comment more about this but provably this code wont ever see the light. It will be an internal application that will die when new equipment or software is brought.