2016-06-12 18:59:43 +00:00
|
|
|
local function objdir(e)
|
2016-06-29 11:58:38 +00:00
|
|
|
return concatpath("$(OBJDIR)", e.cwd, e.name)
|
2016-06-12 18:59:43 +00:00
|
|
|
end
|
|
|
|
|
2016-06-07 02:13:56 +00:00
|
|
|
definerule("normalrule",
|
|
|
|
{
|
|
|
|
ins = { type="targets" },
|
2016-07-14 21:53:34 +00:00
|
|
|
deps = { type="targets", default={} },
|
2016-06-07 02:13:56 +00:00
|
|
|
outleaves = { type="strings" },
|
|
|
|
label = { type="string", optional=true },
|
2016-06-12 18:59:43 +00:00
|
|
|
objdir = { type="string", optional=true },
|
2016-06-07 02:13:56 +00:00
|
|
|
commands = { type="strings" },
|
|
|
|
},
|
|
|
|
function (e)
|
2016-06-12 18:59:43 +00:00
|
|
|
local dir = e.objdir or objdir(e)
|
2016-06-07 02:13:56 +00:00
|
|
|
local realouts = {}
|
2016-08-04 21:51:19 +00:00
|
|
|
for _, v in pairs(e.outleaves) do
|
|
|
|
realouts[#realouts+1] = concatpath(dir, v)
|
2016-06-07 02:13:56 +00:00
|
|
|
end
|
|
|
|
|
2016-06-09 04:55:44 +00:00
|
|
|
local vars = inherit(e.vars, {
|
2016-06-12 18:59:43 +00:00
|
|
|
dir = dir
|
2016-06-09 04:55:44 +00:00
|
|
|
})
|
|
|
|
|
2016-06-07 03:00:26 +00:00
|
|
|
local result = simplerule {
|
2016-06-07 02:13:56 +00:00
|
|
|
name = e.name,
|
|
|
|
ins = e.ins,
|
2016-07-14 21:53:34 +00:00
|
|
|
deps = e.deps,
|
2016-06-07 02:13:56 +00:00
|
|
|
outs = realouts,
|
|
|
|
label = e.label,
|
|
|
|
commands = e.commands,
|
2016-06-09 04:55:44 +00:00
|
|
|
vars = vars,
|
2016-06-07 02:13:56 +00:00
|
|
|
}
|
2016-06-12 18:59:43 +00:00
|
|
|
result.dir = dir
|
2016-06-07 03:00:26 +00:00
|
|
|
return result
|
2016-06-07 02:13:56 +00:00
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2016-06-07 03:00:26 +00:00
|
|
|
definerule("cfile",
|
|
|
|
{
|
|
|
|
srcs = { type="targets" },
|
2016-06-09 04:55:44 +00:00
|
|
|
deps = { type="targets", default={} },
|
2018-04-25 04:17:19 +00:00
|
|
|
suffix = { type="string", default=".o" },
|
2016-06-07 03:00:26 +00:00
|
|
|
commands = {
|
|
|
|
type="strings",
|
|
|
|
default={
|
2016-06-12 18:59:43 +00:00
|
|
|
"$(CC) -c -o %{outs[1]} %{ins[1]} %{hdrpaths} %{cflags}"
|
2016-06-07 03:00:26 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (e)
|
2016-06-08 01:21:53 +00:00
|
|
|
local hdrpaths = {}
|
2016-06-30 11:27:47 +00:00
|
|
|
for _, t in pairs(e.deps) do
|
2016-07-28 22:22:49 +00:00
|
|
|
if t.dir then
|
|
|
|
hdrpaths[#hdrpaths+1] = "-I"..t.dir
|
|
|
|
end
|
2016-06-07 03:00:26 +00:00
|
|
|
end
|
2016-06-08 01:21:53 +00:00
|
|
|
hdrpaths = uniquify(hdrpaths)
|
2016-06-07 02:13:56 +00:00
|
|
|
|
2018-04-25 04:17:19 +00:00
|
|
|
local outleaf = basename(e.name)..e.suffix
|
2016-06-07 03:00:26 +00:00
|
|
|
|
|
|
|
return normalrule {
|
|
|
|
name = e.name,
|
2016-06-29 11:58:38 +00:00
|
|
|
cwd = e.cwd,
|
2016-07-28 22:22:49 +00:00
|
|
|
ins = e.srcs,
|
2016-07-14 21:53:34 +00:00
|
|
|
deps = e.deps,
|
2016-06-07 03:00:26 +00:00
|
|
|
outleaves = {outleaf},
|
|
|
|
label = e.label,
|
|
|
|
commands = e.commands,
|
|
|
|
vars = {
|
2016-06-12 18:59:43 +00:00
|
|
|
hdrpaths = hdrpaths,
|
2016-06-07 03:00:26 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
)
|
2016-06-06 22:10:22 +00:00
|
|
|
|
2016-07-23 22:50:02 +00:00
|
|
|
definerule("cppfile",
|
|
|
|
{
|
|
|
|
srcs = { type="targets" },
|
|
|
|
deps = { type="targets", default={} },
|
|
|
|
outleaf = { type="string" },
|
|
|
|
commands = {
|
|
|
|
type="strings",
|
|
|
|
default={
|
|
|
|
"$(CC) -E -P -o %{outs[1]} %{hdrpaths} %{cflags} -x c %{ins}"
|
|
|
|
}
|
|
|
|
},
|
|
|
|
},
|
|
|
|
function (e)
|
|
|
|
if (#e.srcs ~= 1) then
|
|
|
|
error("you must have exactly one input file")
|
|
|
|
end
|
|
|
|
|
|
|
|
local hdrpaths = {}
|
|
|
|
for _, t in pairs(e.deps) do
|
2017-11-11 21:09:05 +00:00
|
|
|
if t.dir then
|
|
|
|
hdrpaths[#hdrpaths+1] = "-I"..t.dir
|
|
|
|
end
|
2016-07-23 22:50:02 +00:00
|
|
|
end
|
|
|
|
hdrpaths = uniquify(hdrpaths)
|
|
|
|
|
|
|
|
return normalrule {
|
|
|
|
name = e.name,
|
|
|
|
cwd = e.cwd,
|
|
|
|
ins = e.srcs,
|
|
|
|
deps = e.deps,
|
|
|
|
outleaves = {e.outleaf},
|
|
|
|
label = e.label,
|
|
|
|
commands = e.commands,
|
|
|
|
vars = {
|
|
|
|
hdrpaths = hdrpaths,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2016-06-09 04:55:44 +00:00
|
|
|
definerule("bundle",
|
|
|
|
{
|
|
|
|
srcs = { type="targets" },
|
|
|
|
commands = {
|
|
|
|
type="strings",
|
|
|
|
default={
|
|
|
|
"tar cf - %{ins} | (cd %{dir} && tar xf -)"
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (e)
|
|
|
|
local outleaves = {}
|
|
|
|
local commands = {}
|
2016-06-12 18:59:43 +00:00
|
|
|
for _, f in fpairs(e.srcs) do
|
2016-06-09 04:55:44 +00:00
|
|
|
local localf = basename(f)
|
|
|
|
outleaves[#outleaves+1] = localf
|
|
|
|
commands[#commands+1] = "cp "..f.." %{dir}/"..localf
|
|
|
|
end
|
2016-06-07 02:20:08 +00:00
|
|
|
|
2016-06-09 04:55:44 +00:00
|
|
|
return normalrule {
|
|
|
|
name = e.name,
|
2016-06-29 11:58:38 +00:00
|
|
|
cwd = e.cwd,
|
2016-06-09 04:55:44 +00:00
|
|
|
ins = e.srcs,
|
|
|
|
outleaves = outleaves,
|
|
|
|
label = e.label,
|
|
|
|
commands = commands
|
|
|
|
}
|
|
|
|
end
|
|
|
|
)
|
2016-06-07 02:20:08 +00:00
|
|
|
|
2016-06-09 04:55:44 +00:00
|
|
|
definerule("clibrary",
|
|
|
|
{
|
2016-07-19 21:42:56 +00:00
|
|
|
srcs = { type="targets", default={} },
|
2016-06-29 11:28:45 +00:00
|
|
|
hdrs = { type="targets", default={} },
|
2016-06-09 04:55:44 +00:00
|
|
|
deps = { type="targets", default={} },
|
2016-07-29 22:39:22 +00:00
|
|
|
_cfile = { type="object", default=cfile },
|
2018-06-10 11:25:48 +00:00
|
|
|
suffix = { type="string", default=".o" },
|
2016-06-09 04:55:44 +00:00
|
|
|
commands = {
|
|
|
|
type="strings",
|
|
|
|
default={
|
2016-06-29 11:28:45 +00:00
|
|
|
"rm -f %{outs[1]}",
|
|
|
|
"$(AR) cqs %{outs[1]} %{ins}",
|
2016-06-09 04:55:44 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
},
|
|
|
|
function (e)
|
|
|
|
local ins = {}
|
2016-07-29 22:39:22 +00:00
|
|
|
for _, src in fpairs(e.srcs) do
|
|
|
|
local n = basename(src):gsub("%.%w*$", "")
|
|
|
|
ins[#ins+1] = e._cfile {
|
2016-06-09 04:55:44 +00:00
|
|
|
name = e.name.."/"..n,
|
2016-06-29 11:58:38 +00:00
|
|
|
cwd = e.cwd,
|
2016-07-29 22:39:22 +00:00
|
|
|
srcs = {src},
|
2016-06-09 04:55:44 +00:00
|
|
|
deps = e.deps,
|
2018-06-10 11:25:48 +00:00
|
|
|
suffix = e.suffix,
|
2016-07-26 22:10:15 +00:00
|
|
|
vars = {
|
|
|
|
["+cflags"] = { "-I"..e.cwd, },
|
2016-06-12 18:59:43 +00:00
|
|
|
},
|
2016-06-09 04:55:44 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
|
2016-06-29 11:28:45 +00:00
|
|
|
local commands = {}
|
2016-08-08 21:55:23 +00:00
|
|
|
local outleaves = {}
|
|
|
|
if (#e.srcs > 0) then
|
|
|
|
for _, s in ipairs(e.commands) do
|
|
|
|
commands[#commands+1] = s
|
|
|
|
end
|
|
|
|
outleaves[#outleaves+1] = e.name..".a"
|
2016-06-29 11:28:45 +00:00
|
|
|
end
|
2016-08-08 21:55:23 +00:00
|
|
|
|
|
|
|
local hdrsin = {}
|
|
|
|
for dest, src in pairs(e.hdrs) do
|
|
|
|
if (type(dest) == "number") then
|
|
|
|
for _, f in ipairs(filenamesof(src)) do
|
|
|
|
hdrsin[#hdrsin+1] = f
|
|
|
|
outleaves[#outleaves+1] = basename(f)
|
|
|
|
commands[#commands+1] = "cp "..asstring(f).." %{dir}"
|
|
|
|
end
|
|
|
|
else
|
|
|
|
local fs = filenamesof(src)
|
|
|
|
if (#fs ~= 1) then
|
|
|
|
error(string.format("keyed header '%s' can only be a single file", dest))
|
|
|
|
end
|
|
|
|
local f = fs[1]
|
|
|
|
|
|
|
|
hdrsin[#hdrsin+1] = f
|
|
|
|
outleaves[#outleaves+1] = dest
|
|
|
|
commands[#commands+1] = "cp "..asstring(f).." %{dir}/"..dest
|
|
|
|
end
|
2016-06-29 11:28:45 +00:00
|
|
|
end
|
|
|
|
|
2016-06-09 04:55:44 +00:00
|
|
|
return normalrule {
|
|
|
|
name = e.name,
|
2016-06-29 11:58:38 +00:00
|
|
|
cwd = e.cwd,
|
2016-06-09 04:55:44 +00:00
|
|
|
ins = ins,
|
2016-08-08 21:55:23 +00:00
|
|
|
deps = {hdrsin, e.deps},
|
|
|
|
outleaves = outleaves,
|
2016-06-09 04:55:44 +00:00
|
|
|
label = e.label,
|
2016-06-29 11:28:45 +00:00
|
|
|
commands = commands,
|
2016-06-09 04:55:44 +00:00
|
|
|
}
|
|
|
|
end
|
|
|
|
)
|
|
|
|
|
2016-06-09 05:14:41 +00:00
|
|
|
definerule("cprogram",
|
|
|
|
{
|
|
|
|
srcs = { type="targets", default={} },
|
|
|
|
deps = { type="targets", default={} },
|
2016-08-20 12:05:24 +00:00
|
|
|
_clibrary = { type="object", default=clibrary },
|
2016-06-09 05:14:41 +00:00
|
|
|
commands = {
|
|
|
|
type="strings",
|
|
|
|
default={
|
2022-12-30 18:50:16 +00:00
|
|
|
"$(CC) $(LDFLAGS) -o %{outs[1]} %{ins} %{ins}"
|
2016-06-09 05:14:41 +00:00
|
|
|
},
|
|
|
|
}
|
2016-06-09 04:55:44 +00:00
|
|
|
},
|
2016-06-09 05:14:41 +00:00
|
|
|
function (e)
|
2016-08-04 21:51:19 +00:00
|
|
|
local libs = matching(filenamesof(e.deps), "%.a$")
|
2016-11-13 12:28:09 +00:00
|
|
|
local srcs = {}
|
2016-06-09 05:14:41 +00:00
|
|
|
if (#e.srcs > 0) then
|
2016-08-04 21:51:19 +00:00
|
|
|
for _, f in pairs(
|
|
|
|
matching(
|
|
|
|
filenamesof(
|
2016-08-20 12:05:24 +00:00
|
|
|
e._clibrary {
|
2016-08-04 21:51:19 +00:00
|
|
|
name = e.name .. "/main",
|
|
|
|
cwd = e.cwd,
|
|
|
|
srcs = e.srcs,
|
|
|
|
deps = e.deps,
|
|
|
|
}
|
|
|
|
),
|
|
|
|
"%.a$"
|
|
|
|
)
|
|
|
|
) do
|
2016-11-13 12:28:09 +00:00
|
|
|
srcs[#srcs+1] = f
|
2016-06-06 22:10:22 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-09 05:14:41 +00:00
|
|
|
return normalrule {
|
|
|
|
name = e.name,
|
2016-06-29 11:58:38 +00:00
|
|
|
cwd = e.cwd,
|
2016-07-14 21:53:34 +00:00
|
|
|
deps = e.deps,
|
2016-11-13 12:28:09 +00:00
|
|
|
ins = { srcs, libs },
|
2016-06-09 05:14:41 +00:00
|
|
|
outleaves = { e.name },
|
|
|
|
commands = e.commands,
|
2016-06-06 22:10:22 +00:00
|
|
|
}
|
|
|
|
end
|
2016-06-09 05:14:41 +00:00
|
|
|
)
|
2016-06-06 22:10:22 +00:00
|
|
|
|