diff --git a/build.lua b/build.lua index 7b28b0d30..cc483e438 100644 --- a/build.lua +++ b/build.lua @@ -1,3 +1,7 @@ +vars.cflags = { + "-g", "-O" +} + installable { name = "ack", map = { diff --git a/first/ackbuilder.lua b/first/ackbuilder.lua index fa56a8474..05772af2e 100644 --- a/first/ackbuilder.lua +++ b/first/ackbuilder.lua @@ -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( diff --git a/first/build.lua b/first/build.lua index 31c790f13..e514384b9 100644 --- a/first/build.lua +++ b/first/build.lua @@ -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$" diff --git a/modules/src/em_code/build.lua b/modules/src/em_code/build.lua index 80ea28a8b..b530f2a51 100644 --- a/modules/src/em_code/build.lua +++ b/modules/src/em_code/build.lua @@ -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", { }) diff --git a/modules/src/read_em/build.lua b/modules/src/read_em/build.lua index 860f29df1..d80d0569c 100644 --- a/modules/src/read_em/build.lua +++ b/modules/src/read_em/build.lua @@ -27,11 +27,13 @@ normalrule { clibrary { name = "lib_ev", - cflags = { - "-DPRIVATE=static", - "-DEXPORT=", - "-DNDEBUG", - "-DCHECKING" + vars = { + ["+cflags"] = { + "-DPRIVATE=static", + "-DEXPORT=", + "-DNDEBUG", + "-DCHECKING" + }, }, srcs = { "./EM_vars.c", diff --git a/util/LLgen/build.lua b/util/LLgen/build.lua index fd60daa59..5939332d4 100644 --- a/util/LLgen/build.lua +++ b/util/LLgen/build.lua @@ -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",