From: Stefan Lang Date: 2005-07-15T21:20:17+09:00 Subject: Re: rake question On Friday 15 July 2005 09:06, Joe Van Dyk wrote: > On 7/14/05, Joe Van Dyk wrote: [...] > > Example: > > > > PowerBook:~/that_stuff/test1 joe$ ls > > Rakefile another_test.h test.cpp > > another_test.cpp main.cpp test.h > > > > PowerBook:~/that_stuff/test1 joe$ cat Rakefile > > require 'rake/clean' > > CLEAN.include '*.o', 'test' > > CPP_SOURCE = FileList['*.cpp'] > > OBJS = CPP_SOURCE.ext 'o' > > > > task :default => :run > > task :run => "test" do > > sh "./test" > > end > > file "test" => OBJS do > > sh "g++ -o test #{OBJS}" > > end > > rule '.o' => '.cpp' do |t| > > sh "g++ -c -o #{t.name} #{t.source}" > > end > > CPP_SOURCE.each do |cpp| > > headers = File.read(cpp).scan(/^#include "(.+)"/) > > task cpp => headers > > end > > > > PowerBook:~/that_stuff/test1 joe$ rake > > (in /Users/joe/that_stuff/test1) > > g++ -c -o another_test.o another_test.cpp > > g++ -c -o main.o main.cpp > > g++ -c -o test.o test.cpp > > g++ -o test another_test.o main.o test.o > > ./test > > Whassup > > what's up! > > > > > > PowerBook:~/that_stuff/test1 joe$ touch main.cpp > > PowerBook:~/that_stuff/test1 joe$ rake > > (in /Users/joe/that_stuff/test1) > > ./test > > Whassup > > what's up! > > > > It should've recompiled main.cpp and relinked everything, right? > > When I comment out > > > CPP_SOURCE.each do |cpp| > > headers = File.read(cpp).scan(/^#include "(.+)"/) > > task cpp => headers > > end > > Then it works as expected. So, "task cpp => headers" is the culprit. > But I'm still not sure why it breaks everything else. Your logic should be correct. It works if i run it with Rant (with some minor Rake->Rant translations). Don't know why it doesn't work with Rake. I don't want to advertise but Rant can scan #includes for you: import "c/dependencies", "autoclean" CPP_SOURCE = sys['*.cpp'] OBJS = CPP_SOURCE.map { |f| f.sub_ext "o" } task :run => "test" do sys "./test" end gen C::Dependencies gen Action do source "c_dependencies" end file "test" => OBJS do sys "g++ -o test #{OBJS.arglist}" end gen Rule, '.o' => '.cpp' do |t| sys "g++ -c -o #{t.name} #{t.source}" end desc "Remove generated files." gen AutoClean -- Stefan