[Rake-devel] Generating File Tasks

Jonathan Stott jonathan.stott at gmail.com
Fri Dec 1 07:51:17 EST 2006


I'm quite new to both make (and very recently) to rake, but I appear
to have a problem that is beyond make and I cannot figure out how to
do it in rake either.

The situation is I have a series of drivers and a series of models,
stored in the directories 'driver' and 'model', respectively. The
driver code takes a model and performs some calculations with it and
any model is valid for any driver.

What I would like to be able to do is have some generic code whereby
if I add a driver or model, I can type "rake driver_model" and compile
the code.
I have the code snippet:

file "driver_model" => calc_dep("driver_model") do |t|
	sh "#{CC} #{LDFLAGS} -o #{t.name} #{t.prerequisites.join(" ")} #{LIB}"

def calc_dep(file)
	dep = file.split("_")
	dep.collect! { |d| d + ".o" }
	return dep

which will take driver_model, work out it depends on driver.o and
model.o and proceed to build the code, which is just what I want.
However, it does require me to have defined driver_model combinations
for each executable I wish to create and since I have at last count 5
drivers and 7 models, I would need to make 35 rules to cover each
combination and more rules whenever I added another driver or model.

So I would like to synthesise the possible driver/model combinations
from the available source files at the time of running rake.

I think I should be able to do this via :

the .enhance(deps) method.

within a nested look of the available models and drivers. However, I'm
not sure how to find the correct application name, since

DRIVERS.each do |d|
	MODELS.each do |m|

puts Task.tasks()

will return only manually defined tasks, so I don't think they're
being added to the correct application, and while I've looked in the
rdoc documentation, I don't understand what I should add...

Any help would be appreciated


More information about the Rake-devel mailing list