
import "autoclean", "subfile", "command"

@sh_cat = "#{sys.sp Env::RUBY_EXE} -e \"print ARGF.read\""
@sh_puts = "#{sys.sp Env::RUBY_EXE} -e \"puts ARGV\""

def define_print_task(name)
    task name do |t|
        puts t.full_name
    end
end

desc "show full task name"
task :a do |t|
    puts t.full_name
end

file "a.t" do |t|
    write t.name
end

file "b.t" do |t|
    write t.name
end

file "config.t" do |t|
    var :config => "config\n"
    write(t.name, var[:config])
end

gen Command, "c1.t", ["sub1/c1.t"], "$[sh_puts] ${<} > $(>)"

gen Rule, ".r.t" => ".s.t" do |target, sources|
    gen Command, target, sources, "$[sh_cat] $(<) > $(>)"
end

gen Action, /\.s\.t$/ do
    puts ".s.t action"
end

gen SubFile, "t/t", "a.t" => "b.t" do |t|
    write(t.name, "abc")
end

gen AutoClean

subdirs sys["sub?"] # doesn't cover sub00, per intent

def self.write(fn, content=nil)
    puts "writing to #{fn}"
    open fn, "w" do |f|
        f.write(content || "#{fn}\n")
    end
end
