From: Brian Candler Date: 2003-03-22T19:30:40+09:00 Subject: Re: Rake problem? On Sat, Mar 22, 2003 at 09:23:21AM +0900, Jim Weirich wrote: > Apply the attached patch to correct Rakefile1. ... > --- Rakefile1 19 Mar 2003 12:48:05 -0000 1.1 > +++ Rakefile1 21 Mar 2003 23:47:43 -0000 > @@ -17,9 +17,10 @@ > Sys.run "gcc #{src} -c -o #{t.name}" > end > > -task :obj => ["a.o", "b.o", "main.o"] > +OBJFILES = ["a.o", "b.o", "main.o"] > +task :obj => OBJFILES > > -file "main" => [:obj] do |t| > +file "main" => OBJFILES do |t| > Sys.run "gcc -o #{t.name} main.o a.o b.o" > end With rake-0.2.1 I can't duplicate the original problem, i.e. I can set it back to "main" => [:obj] and it works: $ rm main $ rake (in /v/build/rake-0.2.1/doc/example) gcc -o main main.o a.o b.o $ rake (in /v/build/rake-0.2.1/doc/example) $ However, where you have > Sys.run "gcc -o #{t.name} main.o a.o b.o" I thought it might be better to put Sys.run "gcc -o #{t.name} #{OBJFILES.join(' ')}" since you've factored out the filenames anyway. The syntax is somehow unattractive. Assuming you keep 'file "main" => OBJFILES' then I notice you can do #{t.prerequisites.join(' ')} but that won't work in the general case where the dependencies may come in groups (say .o files and .a files) which need handling differently. Hmm, how about some sugar: #{t.sources('.o')} i.e. the first parameter is a suffix or regex, and an optional second parameter if you want to join with something other than space. But if you set "main" => [:obj] instead of "main" => OBJFILES then it would need to traverse a level down to find the actual source files. One other idea. If you have a large project with components in subdirectories, it would be really cool if you could have a top-level Rakefile which includes the sub-Rakefiles and generates a single dependency graph automatically. As far as I can see all you would need is something like require 'subdir/Rakefile' except that all the files/dependencies would need 'subdir' prepended to them in the global dependency graph (perhaps using a global $prefix). Or maybe the graph should be built with only absolute pathnames in it? so file "foo" would generate basename($0)+"foo" ? There's an excellent article here about why this could work extremely well for large projects: http://www.tip.net.au/~millerp/rmch/recu-make-cons-harm.html Regards, Brian. P.S. I'm not sure I like the searching for Rakefile in parent directories. If I am in doc/example and type 'rake' then I get the testsuite built; it's a bit unexpected!