In wrapping up and refactoring my new rake driven build system, I’ve written numerous utility functions. Most stuff specific to compiling crap is in a custom “Builder” module that provides a templated interface to the current OS/Compiler kit, via environment variables and methods like make_object, make_shared_library. My top level rakefile also has a neato inference rule rigged together for handling my triple-tree and quad tree build patterns.
The real fun of the day however, is this baby:
#
# A magic function that generates file tasks that copy all headers from
# directory ind # to directory outd. Any missing directories are created as
# needed.
#
# The return value is a list suitable for the right hand side of a task, e.g.
#
# task :headers => header_magic(src, dest)
#
def header_magic(ind, outd)
dirs = []
hdrs = []
find_files(ind, /.*.h[hxp]*$/) do |p|
outdir = File.dirname p.sub(ind, outd)
outfile = File.join(outd, File.basename(p))
directory outdir
file outfile => p do
cp_r p, outdir
end
dirs.push outdir
hdrs.push outfile
CLEAN.include outfile, outdir
end
dirs+hdrs
end