Replace the hacky cflags variable with an equally hacky but vastly

more useful magic vars variable.
This commit is contained in:
David Given 2016-07-27 00:10:15 +02:00
parent cdeea836f2
commit f9c77fca03
6 changed files with 58 additions and 32 deletions

View file

@ -1,3 +1,7 @@
vars.cflags = {
"-g", "-O"
}
installable {
name = "ack",
map = {

View file

@ -15,6 +15,18 @@ local targets = {}
local buildfiles = {}
local globals
local cwd = "."
local vars = {}
local parente = {}
local function concat(...)
local r = {}
for k, t in ipairs({...}) do
for _, v in ipairs(t) do
r[#r+1] = v
end
end
return r
end
local function inherit(high, low)
local o = {}
@ -27,6 +39,12 @@ local function inherit(high, low)
return low[k]
end
})
for k, v in pairs(high) do
local _, _, kk = k:find("^%+(.*)$")
if kk then
o[kk] = concat(low[kk], v)
end
end
return o
end
@ -53,16 +71,6 @@ local function asstring(o)
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("/%./", "/"))
@ -404,6 +412,7 @@ local function definerule(rulename, types, cb)
types.name = { type="string" }
types.cwd = { type="string", optional=true }
types.vars = { type="table", default={} }
for propname, typespec in pairs(types) do
if not typeconverters[typespec.type] then
@ -414,6 +423,11 @@ local function definerule(rulename, types, cb)
local rulecwd = cwd
local rule = function(e)
local definedprops = {}
for propname, _ in pairs(e) do
definedprops[propname] = true
end
local args = {}
for propname, typespec in pairs(types) do
if not e[propname] then
@ -424,11 +438,11 @@ local function definerule(rulename, types, cb)
args[propname] = typespec.default
else
args[propname] = typeconverters[typespec.type](propname, e[propname])
e[propname] = nil
definedprops[propname] = nil
end
end
local propname, _ = next(e)
local propname, _ = next(definedprops)
if propname then
error(string.format("don't know what to do with property '%s'", propname))
end
@ -438,7 +452,11 @@ local function definerule(rulename, types, cb)
end
args.fullname = args.cwd.."+"..args.name
local oldparente = parente
parente = args
args.vars = inherit(args.vars, oldparente.vars)
local result = cb(args) or {}
parente = oldparente
result.is = result.is or {}
result.is[rulename] = true
@ -678,6 +696,7 @@ globals = {
startswith = startswith,
targetnamesof = targetnamesof,
uniquify = uniquify,
vars = vars,
}
setmetatable(globals,
{
@ -692,6 +711,9 @@ setmetatable(globals,
}
)
vars.cflags = {}
parente.vars = vars
do
local emitter_type = install_make_emitter
parse_arguments(

View file

@ -10,7 +10,6 @@ definerule("normalrule",
label = { type="string", optional=true },
objdir = { type="string", optional=true },
commands = { type="strings" },
vars = { type="table", default={} },
},
function (e)
local dir = e.objdir or objdir(e)
@ -41,7 +40,6 @@ definerule("cfile",
{
srcs = { type="targets" },
deps = { type="targets", default={} },
cflags = { type="strings", default={} },
commands = {
type="strings",
default={
@ -74,7 +72,6 @@ definerule("cfile",
commands = e.commands,
vars = {
hdrpaths = hdrpaths,
cflags = e.cflags,
}
}
end
@ -85,7 +82,6 @@ definerule("cppfile",
srcs = { type="targets" },
deps = { type="targets", default={} },
outleaf = { type="string" },
cflags = { type="strings", default={} },
commands = {
type="strings",
default={
@ -114,7 +110,6 @@ definerule("cppfile",
commands = e.commands,
vars = {
hdrpaths = hdrpaths,
cflags = e.cflags,
}
}
end
@ -155,7 +150,6 @@ definerule("clibrary",
srcs = { type="targets", default={} },
hdrs = { type="targets", default={} },
deps = { type="targets", default={} },
cflags = { type="strings", default={} },
commands = {
type="strings",
default={
@ -176,9 +170,8 @@ definerule("clibrary",
cwd = e.cwd,
srcs = {csrc, unpack(hsrcs)},
deps = e.deps,
cflags = {
"-I"..e.cwd,
unpack(e.cflags)
vars = {
["+cflags"] = { "-I"..e.cwd, },
},
}
end
@ -212,7 +205,6 @@ definerule("cprogram",
{
srcs = { type="targets", default={} },
deps = { type="targets", default={} },
cflags = { type="strings", default={} },
commands = {
type="strings",
default={
@ -230,7 +222,6 @@ definerule("cprogram",
cwd = e.cwd,
srcs = e.srcs,
deps = e.deps,
cflags = e.cflags,
}
},
"%.a$"

View file

@ -79,10 +79,12 @@ local function build_variant(code, cflags)
"modules/src/system+lib",
"util/data+em_data",
},
cflags = { cflags }
vars = {
["+cflags"] = cflags
},
}
end
build_variant("e", "-DREADABLE_EM")
build_variant("k", "")
build_variant("e", { "-DREADABLE_EM" })
build_variant("k", { })

View file

@ -27,12 +27,14 @@ normalrule {
clibrary {
name = "lib_ev",
cflags = {
vars = {
["+cflags"] = {
"-DPRIVATE=static",
"-DEXPORT=",
"-DNDEBUG",
"-DCHECKING"
},
},
srcs = {
"./EM_vars.c",
"./read_em.c",

View file

@ -6,7 +6,12 @@ cprogram {
-- do this.
srcs = { "./src/*.c" },
cflags = { "-DLIBDIR=\\\""..posix.getcwd().."/"..cwd().."/lib\\\"", "-DNON_CORRECTING" },
vars = {
["+cflags"] = {
"-DLIBDIR=\\\""..posix.getcwd().."/"..cwd().."/lib\\\"",
"-DNON_CORRECTING"
},
}
}
definerule("llgen",