rakefile help: rakefile calling a rakefile?

J

John Gabriele

I've got a top-level Rakefile that builds some C files. So, I've got a
rule in there for building .c files to .o files. This rakefile has its
own global variables, like $CFLAGS for example.

rule '.o' => '.c' do |t|
cmd = "cc #{$CFLAGS} #{$INCLUDES} -c -o #{t.name} #{t.source}"
sh cmd
end

I've also got a subdirectory with a C file in it that needs slightly
different value of $CFLAGS to build. I've got a rule in that Rakefile
as well, and it looks exactly like the one in the top-level rakefile.

The C file in the subdir needs to be built before the top-level
Rakefile can do its jobs of building other things.

My guess is that just using:

require 'subdir/Rakefile'

would botch things up, since I'm using a global $CFLAGS.

I'd think I'd like to just do something this in the top-level Rakefile:

task :default => [:build_other_c_file] do |t|
sh "cd subdir; rake"
end

Is that the way multi-rakefile projects usually do it?

Although it's "considered harmful" for large projects, I don't mind
doing something like how make recursivly decends into subdirectories
to make dependencies. How's that usually done with rake?

I read one of Jim's posts relating to this
http://rubyforge.org/pipermail/rake-devel/2005-December/000182.html
but don't know exactly how I'd go about building a "unified dependency
graph" as he recommends.

Thanks,
---John
 
S

Suraj Kurapati

John said:
I'd think I'd like to just do something this in the top-level Rakefile:

task :default => [:build_other_c_file] do |t|
sh "cd subdir; rake"
end

Is that the way multi-rakefile projects usually do it?

That's how I do it. May not be the best solution, but hey, it works.
I read one of Jim's posts relating to this
http://rubyforge.org/pipermail/rake-devel/2005-December/000182.html
but don't know exactly how I'd go about building a "unified dependency
graph" as he recommends.

I suppose you could load (instead of require) the nested Rakefile into a
namespace and then use it as a dependency. For example:

namespace :nested
load 'subdir/Rakefile'
end

task :default => :nested:default
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top