Leaf rules work!
This commit is contained in:
parent
b7d2b9c3cf
commit
79f7c0ad23
|
@ -1,3 +1,5 @@
|
||||||
|
local posix = require("posix")
|
||||||
|
|
||||||
-- Targets:
|
-- Targets:
|
||||||
--
|
--
|
||||||
-- {
|
-- {
|
||||||
|
@ -25,12 +27,14 @@ end
|
||||||
|
|
||||||
local function asstring(o)
|
local function asstring(o)
|
||||||
local t = type(o)
|
local t = type(o)
|
||||||
if (t == "string") then
|
if (t == "nil") then
|
||||||
|
return ""
|
||||||
|
elseif (t == "string") then
|
||||||
return o
|
return o
|
||||||
elseif (t == "number") then
|
elseif (t == "number") then
|
||||||
return o
|
return o
|
||||||
elseif (t == "table") then
|
elseif (t == "table") then
|
||||||
if o.outs then
|
if o.is then
|
||||||
return asstring(o.outs)
|
return asstring(o.outs)
|
||||||
else
|
else
|
||||||
local s = {}
|
local s = {}
|
||||||
|
@ -71,8 +75,14 @@ end
|
||||||
local function filenamesof(results)
|
local function filenamesof(results)
|
||||||
local f = {}
|
local f = {}
|
||||||
for _, r in pairs(results) do
|
for _, r in pairs(results) do
|
||||||
for _, o in pairs(r.outs) do
|
if (type(r) == "string") then
|
||||||
f[#f+1] = o
|
f[#f+1] = r
|
||||||
|
elseif (type(r) == "table") then
|
||||||
|
if r.is and r.outs then
|
||||||
|
for _, o in pairs(r.outs) do
|
||||||
|
f[#f+1] = o
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return f
|
return f
|
||||||
|
@ -84,7 +94,7 @@ local function uniquify(collection)
|
||||||
for _, v in pairs(collection) do
|
for _, v in pairs(collection) do
|
||||||
if not s[v] then
|
if not s[v] then
|
||||||
s[v] = true
|
s[v] = true
|
||||||
o[#o+1] = s
|
o[#o+1] = v
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return o
|
return o
|
||||||
|
@ -267,6 +277,7 @@ local function definerule(rulename, types, cb)
|
||||||
result.is = result.is or {}
|
result.is = result.is or {}
|
||||||
result.is[rulename] = true
|
result.is[rulename] = true
|
||||||
targets[cwd..":"..args.name] = result
|
targets[cwd..":"..args.name] = result
|
||||||
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -277,12 +288,12 @@ end
|
||||||
function environment:rule(ins, outs)
|
function environment:rule(ins, outs)
|
||||||
local firstout = outs[1]
|
local firstout = outs[1]
|
||||||
for i = 2, #outs do
|
for i = 2, #outs do
|
||||||
emit(outs[i], ":", outs[1], "\n")
|
emit(outs[i]..":", outs[1], "\n")
|
||||||
end
|
end
|
||||||
for i = 1, #ins do
|
for i = 1, #ins do
|
||||||
emit(firstout, ":", ins[i], "\n")
|
emit(firstout..":", ins[i], "\n")
|
||||||
end
|
end
|
||||||
emit(firstout, ":\n")
|
emit(firstout..":\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
function environment:label(...)
|
function environment:label(...)
|
||||||
|
@ -293,7 +304,7 @@ end
|
||||||
function environment:mkdirs(dirs)
|
function environment:mkdirs(dirs)
|
||||||
dirs = uniquify(dirs)
|
dirs = uniquify(dirs)
|
||||||
if (#dirs > 0) then
|
if (#dirs > 0) then
|
||||||
emit("\t@mkdir -p ", dirs, "\n")
|
emit("\t@mkdir -p", dirs, "\n")
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -314,8 +325,8 @@ definerule("simplerule",
|
||||||
},
|
},
|
||||||
function (e)
|
function (e)
|
||||||
e.environment:rule(filenamesof(e.ins), e.outs)
|
e.environment:rule(filenamesof(e.ins), e.outs)
|
||||||
e.environment:label(e.name, " ", e.label or "")
|
e.environment:label(cwd..":"..e.name, " ", e.label or "")
|
||||||
e.environment:mkdirs(dirnames(e.outs))
|
e.environment:mkdirs(dirnames(filenamesof(e.outs)))
|
||||||
e.environment:exec(
|
e.environment:exec(
|
||||||
templateexpand(e.commands,
|
templateexpand(e.commands,
|
||||||
{
|
{
|
||||||
|
@ -338,6 +349,8 @@ definerule("simplerule",
|
||||||
|
|
||||||
globals = {
|
globals = {
|
||||||
asstring = asstring,
|
asstring = asstring,
|
||||||
|
concatpath = concatpath,
|
||||||
|
cwd = cwd,
|
||||||
definerule = definerule,
|
definerule = definerule,
|
||||||
emit = emit,
|
emit = emit,
|
||||||
environment = environment,
|
environment = environment,
|
||||||
|
|
|
@ -1,7 +1,32 @@
|
||||||
simplerule {
|
definerule("normalrule",
|
||||||
|
{
|
||||||
|
ins = { type="targets" },
|
||||||
|
outleaves = { type="strings" },
|
||||||
|
label = { type="string", optional=true },
|
||||||
|
commands = { type="strings" },
|
||||||
|
},
|
||||||
|
function (e)
|
||||||
|
local objpath = "$(OBJDIR)/"..e.name
|
||||||
|
local realouts = {}
|
||||||
|
for k, v in pairs(e.outleaves) do
|
||||||
|
realouts[k] = concatpath(objpath, v)
|
||||||
|
end
|
||||||
|
|
||||||
|
return simplerule {
|
||||||
|
name = e.name,
|
||||||
|
ins = e.ins,
|
||||||
|
outs = realouts,
|
||||||
|
label = e.label,
|
||||||
|
commands = e.commands,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
normalrule {
|
||||||
name = "random",
|
name = "random",
|
||||||
ins = {},
|
ins = {},
|
||||||
outs = {"out"},
|
outleaves = {"out"},
|
||||||
commands = {
|
commands = {
|
||||||
"dd if=/dev/random of=%{outs} bs=1024 count=1"
|
"dd if=/dev/random of=%{outs} bs=1024 count=1"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue