(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)
$