Rake Bug

J

jim

I think you can call this a bug.
When the Rakefile is newer than the file dependencies,
the dependencies do not rebuild.

I was hoping they would.
I think make does this.
 
C

Charles Mills

GNU make doesn't do this.
-Charlie

$ make
...
$ touch Makefile
$ make
make: Nothing to be done for `all'.
 
J

Jim Weirich

(e-mail address removed) said:
I think you can call this a bug.
When the Rakefile is newer than the file dependencies,
the dependencies do not rebuild.

I was hoping they would.
I think make does this.

If you want something to be dependent upon the rakefile, then declare the
Rakefile in the dependencies.

I sometimes do this with package generation since the metadata for the
package is often in the Rakefile. If I tweek the metadata, I want the
package to rebuild.
 
J

jim

* Jim Weirich said:
If you want something to be dependent upon the rakefile, then declare the
Rakefile in the dependencies.

Good idea. So, does the following look like a good way to do this?

The following:

file "app" => ["app.o"] do
# link app
end

file "app.o" => ["main.c", "app.c"] do
# compile app.o
end

would become:

file "app" => ["app.o"] do
# link app
end

file "app.o" => ["main.c", "app.c"] do
# compile app.o
end

file "app.c" => ["Rakefile"] do |t|
sh "touch #{t.name}"
end
file "main.c" => ["Rakefile"] do |t|
sh "touch #{t.name}"
end
 
J

Jim Weirich

(e-mail address removed) said:
* Jim Weirich said:
If you want something to be dependent upon the rakefile, then declare
the
Rakefile in the dependencies.

Good idea. So, does the following look like a good way to do this?

The following:

file "app" => ["app.o"] do
# link app
end

file "app.o" => ["main.c", "app.c"] do
# compile app.o
end

would become:

file "app" => ["app.o"] do
# link app
end

file "app.o" => ["main.c", "app.c"] do
# compile app.o
end

file "app.c" => ["Rakefile"] do |t|
sh "touch #{t.name}"
end
file "main.c" => ["Rakefile"] do |t|
sh "touch #{t.name}"
end

Hmmm ... I don't _think_ the touch is needed. The fact that a dependency
has a later time _should_ be enough to trigger its rebuild. I won't get a
chance to test this until this evening however.
 
J

Jim Weirich

(e-mail address removed) said:
[... 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)
$
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,011
Latest member
AjaUqq1950

Latest Threads

Top