
import "md5"
import "autoclean", "package/tgz", "c/dependencies"

cpp_dirs = sys["c++/problem_*"]
c_dirs = sys["c/problem_*"]
all_dirs = cpp_dirs + c_dirs

cpp_rf_template = "c++/template.rf"
c_rf_template = "c/template.rf"

desc "Run all C and C++ tests."
task :run => all_dirs.map{ |f| "#{f}/run" }
desc "Build all."
task :build => all_dirs.map{ |f| "#{f}/test" }

desc "Remove all autogenerated files."
gen AutoClean

gen Rule, '.o' => '.cpp' do |t|
  sys "g++ -c -o #{t.name} #{t.source}"
end

gen Rule, '.o' => '.c' do |t|
  sys "gcc -c -o #{t.name} #{t.source}"
end

desc "Create source package."
gen Package::Tgz, "pkg/c_cpp",
    :files => sys["root.rant", "**/*.{c,cpp,h,rf}"]

gen Action do
    cpp_dirs.each { |dir|
        make "#{dir}/sub.rant" => cpp_rf_template do |t|
            sys.cp t.source, t.name
        end
    }
    c_dirs.each { |dir|
        make "#{dir}/sub.rant" => c_rf_template do |t|
            sys.cp t.source, t.name
        end
    }
    subdirs cpp_dirs, c_dirs
end

# vim:ft=ruby
