end
end
+local function concat(...)
+ local r = {}
+ for _, t in ipairs({...}) do
+ for _, v in ipairs(t) do
+ r[#r+1] = v
+ end
+ end
+ return r
+end
+
local function concatpath(...)
local p = table.concat({...}, "/")
return p:gsub("/+", "/"):gsub("^%./", ""):gsub("/%./", "/")
return f
end
+local function targetnamesof(targets)
+ local f = {}
+ if targets then
+ if targets.is then
+ targets = {targets}
+ end
+
+ for _, r in pairs(targets) do
+ if (type(r) == "table") and r.is then
+ f[#f+1] = r.fullname
+ elseif (type(r) == "string") then
+ f[#f+1] = r
+ else
+ error(string.format("list of targets contains a %s which isn't a target",
+ type(r)))
+ end
+ end
+ end
+ return f
+end
+
local function dotocollection(collection, callback)
if (type(collection) == "string") then
return callback(collection)
end
args.environment = environment
- args.fullname = cwd.."+"..args.name
- args.rulecwd = rulecwd
if not args.cwd then
args.cwd = cwd
end
+ args.fullname = args.cwd.."+"..args.name
- local oldcwd = cwd
- cwd = rulecwd
local result = cb(args) or {}
- cwd = oldcwd
result.is = result.is or {}
result.is[rulename] = true
result.fullname = args.fullname
+
+ if targets[arg.fullname] and (targets[arg.fullname] ~= result) then
+ error(string.format("target '%s' is already defined", args.fullname))
+ end
targets[result.fullname] = result
return result
end
if rulename then
+ if rules[rulename] then
+ error(string.format("rule '%s' is already defined", rulename))
+ end
rules[rulename] = rule
end
return rule
{
ins = { type="targets" },
outs = { type="strings" },
+ deps = { type="targets", default={} },
label = { type="string", optional=true },
commands = { type="strings" },
vars = { type="table", default={} },
},
function (e)
- e.environment:rule(e.fullname, filenamesof(e.ins), e.outs)
+ e.environment:rule(e.fullname,
+ concat(filenamesof(e.ins), filenamesof(e.deps)),
+ e.outs)
e.environment:label(e.fullname, " ", e.label or "")
local vars = inherit(e.vars, {
abspath = abspath,
asstring = asstring,
basename = basename,
+ concat = concat,
concatpath = concatpath,
cwd = function() return cwd end,
definerule = definerule,
emit = emit,
environment = environment,
filenamesof = filenamesof,
+ fpairs = fpairs,
include = loadbuildfile,
inherit = inherit,
replace = replace,
selectof = selectof,
startswith = startswith,
- fpairs = fpairs,
+ targetnamesof = targetnamesof,
uniquify = uniquify,
}
setmetatable(globals,
definerule("normalrule",
{
ins = { type="targets" },
+ deps = { type="targets", default={} },
outleaves = { type="strings" },
label = { type="string", optional=true },
objdir = { type="string", optional=true },
local result = simplerule {
name = e.name,
ins = e.ins,
+ deps = e.deps,
outs = realouts,
label = e.label,
commands = e.commands,
return normalrule {
name = e.name,
cwd = e.cwd,
- ins = {csrcs[1], unpack(hsrcs)},
+ ins = {csrcs[1]},
+ deps = e.deps,
outleaves = {outleaf},
label = e.label,
commands = e.commands,
},
function (e)
local csrcs = filenamesof(e.srcs, "%.c$")
-
local hsrcs = filenamesof(e.srcs, "%.h$")
local ins = {}
return normalrule {
name = e.name,
cwd = e.cwd,
+ deps = e.deps,
ins = libs,
outleaves = { e.name },
commands = e.commands,