On 3/18/06, Jim Weirich <jim / weirichhouse.org> wrote:
> Simon Strandgaard wrote:
> >
> > Touching 'a.cpp' does not result in a compile, what am I doing wrong?
> > (Touching 'a.h' works fine.)
>
> Ahh, evidently, makedepend does not create an explicit dependency
> between a.o and a.cpp.  Make probably deduces this implicitly.  however,
> rake does not.  So just make the relationship explicit.  Add the
> following to your Rakefile:
>
> CPP_FILES.each do |src|
>   file src.ext(".o") => src
> end
>

Excellent.. Now incremental rebuild is working
for both .h files and .cpp files.

Thanks Jim.





Below are the final rakefile, maybe handy for others.



require 'rake/clean'
require 'rake/loaders/makefile'

APPLICATION = 'test.exe'
CPP_FILES = FileList['*.cpp']
O_FILES = CPP_FILES.sub(/\.cpp$/, '.o')

file '.depend.mf' do
  sh "makedepend -f- --  -- #{CPP_FILES} > .depend.mf"
end

import ".depend.mf"

file APPLICATION => O_FILES do |t|
  sh "g++ #{O_FILES} -o #{t.name}"
end

rule ".o" => [".cpp"] do |t|
  sh "g++ -c -o #{t.name} #{t.source}"
end

CPP_FILES.each do |src|
  file src.ext(".o") => src
end

CLEAN.include("**/*.o")
CLEAN.include(APPLICATION)
CLEAN.include(".depend.mf")

task :default => APPLICATION