rakefile help: rakefile calling a rakefile?

Discussion in 'Ruby' started by John Gabriele, Sep 29, 2006.

  1. 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
     
    John Gabriele, Sep 29, 2006
    #1
    1. Advertising

  2. John Gabriele wrote:
    > 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

    --
    Posted via http://www.ruby-forum.com/.
     
    Suraj Kurapati, Dec 5, 2006
    #2
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Jim Menard
    Replies:
    6
    Views:
    170
    Jim Menard
    Jun 14, 2004
  2. T. Onoma

    Don't know how to rake Rakefile

    T. Onoma, Aug 23, 2004, in forum: Ruby
    Replies:
    8
    Views:
    162
    James Britt
    Aug 23, 2004
  3. mikshir
    Replies:
    0
    Views:
    123
    mikshir
    Sep 8, 2006
  4. Bira
    Replies:
    1
    Views:
    108
    Richard Conroy
    Oct 13, 2006
  5. ozizus
    Replies:
    0
    Views:
    92
    ozizus
    Nov 1, 2006
Loading...

Share This Page