From: Jim Weirich Date: 2004-08-28T08:43:24+09:00 Subject: Re: Rake Bug Jim Weirich wrote: >>* Jim Weirich [2004-08-28 05:11:24 +0900]: >>>If you want something to be dependent upon the rakefile, then declare >>>the Rakefile in the dependencies. > jim@freeze.org said: >>Good idea. So, does the following look like a good way to do this? [... example elided ...] Here's what I did. I have a small project of two C files (main.c and hello.c) and one header file (hello.h). Here is the rakefile I used ... -- BEGIN Rakefile --------------------------------------------------- # -*- ruby -*- require 'rake/clean' CC = 'gcc' LD = CC PROG = 'hi' SRC = FileList['*.c'] HDR = FileList['*.h'] OBJ = SRC.sub(/\.c$/, '.o') CLOBBER.include(PROG, *OBJ) task :default => [:compile] task :compile => [PROG] file PROG => OBJ OBJ.each do |obj| header = obj.sub(/\.o$/, '.h') file obj => [header] if File.exists?(header) file obj => ['Rakefile'] end rule '.o' => ['.c'] do |t| sh "#{CC} #{t.source} -c -o #{t.name}" end rule(/^#{PROG}$/ => lambda { |src| OBJ.first } ) do |t| sh "#{LD} #{OBJ} -o #{t.name}" end -- END -------------------------------------------------------------- And here's an example session... $ rake clobber (in /home/jim/pgm/ruby/rakemisc/cstuff) rm -r hi rm -r hello.o rm -r main.o $ $ rake compile (in /home/jim/pgm/ruby/rakemisc/cstuff) gcc hello.c -c -o hello.o gcc main.c -c -o main.o gcc hello.o main.o -o hi $ $ rake compile (in /home/jim/pgm/ruby/rakemisc/cstuff) $ $ touch Rakefile $ rake compile (in /home/jim/pgm/ruby/rakemisc/cstuff) gcc hello.c -c -o hello.o gcc main.c -c -o main.o gcc hello.o main.o -o hi $ $ rake compile (in /home/jim/pgm/ruby/rakemisc/cstuff) $ -- -- Jim Weirich jim@weirichhouse.org http://onestepback.org ----------------------------------------------------------------- "Beware of bugs in the above code; I have only proved it correct, not tried it." -- Donald Knuth (in a memo to Peter van Emde Boas)