Rakefile で、test.c sub.c をそれぞれコンパイルする例
以下のファイルを用意する
Rakefile
1 | require "rake/clean"
CLEAN.include("*.o")
CLOBBER.include("*.exe")
SRC = FileList["*.c"]
OBJ = SRC.ext("o")
EXE = "test.exe"
desc "default task"
task :default => [EXE]
desc "run task"
task :run do
sh "test.exe"
end
rule '.o' => [".c"] do |t|
sh "gcc #{t.source} -c -o #{t.name}"
end
file EXE => OBJ do
sh "gcc #{OBJ} -o #{EXE}"
end |
test.c
1 2 3 4 5 6 7 8 9 | #include "stdio.h" extern void hello_world(); int main() { hello_world(); return(0); } |
sub.c
1 2 3 4 | void hello_world() { printf("Hello world!\n"); } |
rake
で、コンパイル。
rake run
で、実行
rake clean
で、.o削除
rake clobber
で、.exe と .o 削除
rake -T
で、解説表示