2016-06-06 15:18:19 +00:00
|
|
|
-- Targets:
|
|
|
|
--
|
|
|
|
-- {
|
|
|
|
-- dir = target's build directory
|
|
|
|
-- outs = target's object files
|
|
|
|
-- is = { set of rule types which made the target }
|
|
|
|
-- }
|
|
|
|
|
|
|
|
local environment = {}
|
|
|
|
local rules = {}
|
|
|
|
|
|
|
|
local function subenv(old, cb)
|
|
|
|
if not old then
|
|
|
|
old = environment
|
|
|
|
end
|
|
|
|
local new = {}
|
|
|
|
setmetatable(new, {__index = old})
|
|
|
|
cb(new, old)
|
|
|
|
return new
|
2016-06-05 08:39:29 +00:00
|
|
|
end
|
|
|
|
|
2016-06-06 15:18:19 +00:00
|
|
|
local function asstring(o)
|
|
|
|
local t = type(o)
|
|
|
|
if (t == "string") then
|
|
|
|
return o
|
|
|
|
elseif (t == "number") then
|
|
|
|
return o
|
|
|
|
elseif (t == "table") then
|
|
|
|
local s = {}
|
|
|
|
for _, v in pairs(o) do
|
|
|
|
s[#s+1] = asstring(v)
|
2016-06-05 08:39:29 +00:00
|
|
|
end
|
2016-06-06 15:18:19 +00:00
|
|
|
return table.concat(s, " ")
|
2016-06-05 08:39:29 +00:00
|
|
|
else
|
2016-06-06 15:18:19 +00:00
|
|
|
error(string.format("can't turn values of type '%s' into strings", t))
|
2016-06-05 08:39:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
local function emit(...)
|
2016-06-06 15:18:19 +00:00
|
|
|
local n = select("#", ...)
|
|
|
|
local args = {...}
|
2016-06-05 08:39:29 +00:00
|
|
|
|
2016-06-06 15:18:19 +00:00
|
|
|
for i=1, n do
|
|
|
|
local s = asstring(args[i])
|
|
|
|
io.stdout:write(s)
|
|
|
|
if not s:find("\n$") then
|
|
|
|
io.stdout:write(" ")
|
2016-06-05 08:39:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-06 15:18:19 +00:00
|
|
|
local function definerule(name, cb)
|
|
|
|
if rules[name] then
|
|
|
|
error(string.format("rule '%s' is already defined", name))
|
2016-06-05 08:39:29 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-06 15:18:19 +00:00
|
|
|
-----------------------------------------------------------------------------
|
|
|
|
-- MAIN PROGRAM --
|
|
|
|
-----------------------------------------------------------------------------
|
2016-06-05 08:39:29 +00:00
|
|
|
|
2016-06-06 15:18:19 +00:00
|
|
|
local globals = {
|
|
|
|
asstring = asstring,
|
|
|
|
definerule = definerule,
|
|
|
|
emit = emit,
|
|
|
|
environment = environment,
|
|
|
|
}
|
|
|
|
setmetatable(globals, {__index = _G})
|
2016-06-05 08:39:29 +00:00
|
|
|
|
2016-06-06 15:18:19 +00:00
|
|
|
emit("hide=@\n")
|
|
|
|
for _, file in ipairs({...}) do
|
|
|
|
local data, chunk, e
|
|
|
|
data = io.open(file):read("*a")
|
|
|
|
if not e then
|
|
|
|
local thisglobals = {_G = thisglobals}
|
|
|
|
setmetatable(thisglobals, {__index = globals})
|
|
|
|
chunk, e = loadstring(data, file, "text", thisglobals)
|
|
|
|
end
|
|
|
|
if e then
|
|
|
|
error(string.format("couldn't load '%s': %s", file, e))
|
2016-06-05 08:39:29 +00:00
|
|
|
end
|
|
|
|
|
2016-06-06 15:18:19 +00:00
|
|
|
local _, e = pcall(chunk)
|
2016-06-05 08:39:29 +00:00
|
|
|
end
|
|
|
|
|