Multiple build files work. Use deps intelligently. clibraries.
This commit is contained in:
112
first/build.lua
112
first/build.lua
@@ -13,13 +13,17 @@ definerule("normalrule",
|
||||
realouts[k] = concatpath(objpath, v)
|
||||
end
|
||||
|
||||
local vars = inherit(e.vars, {
|
||||
dir = objpath
|
||||
})
|
||||
|
||||
local result = simplerule {
|
||||
name = e.name,
|
||||
ins = e.ins,
|
||||
outs = realouts,
|
||||
label = e.label,
|
||||
commands = e.commands,
|
||||
vars = e.vars,
|
||||
vars = vars,
|
||||
}
|
||||
result.dir = objpath
|
||||
return result
|
||||
@@ -29,10 +33,11 @@ definerule("normalrule",
|
||||
definerule("cfile",
|
||||
{
|
||||
srcs = { type="targets" },
|
||||
deps = { type="targets", default={} },
|
||||
commands = {
|
||||
type="strings",
|
||||
default={
|
||||
"$CC -c -o %{outs[1]} %{ins[1]} %{hdrpaths}"
|
||||
"$(CC) -c -o %{outs[1]} %{ins[1]} %{hdrpaths}"
|
||||
},
|
||||
}
|
||||
},
|
||||
@@ -42,18 +47,23 @@ definerule("cfile",
|
||||
error("you must have exactly one .c file")
|
||||
end
|
||||
|
||||
local htargets = selectof(e.srcs, "%.h$")
|
||||
local hsrcs = filenamesof(e.srcs, "%.h$")
|
||||
local hdeps = selectof(e.deps, "%.h$")
|
||||
local hdrpaths = {}
|
||||
for _, t in pairs(htargets) do
|
||||
for _, t in pairs(hdeps) do
|
||||
hdrpaths[#hdrpaths+1] = "-I"..t.dir
|
||||
end
|
||||
hdrpaths = uniquify(hdrpaths)
|
||||
|
||||
for _, f in pairs(filenamesof(hdeps)) do
|
||||
hsrcs[#hsrcs+1] = f
|
||||
end
|
||||
|
||||
local outleaf = basename(csrcs[1]):gsub("%.c$", ".o")
|
||||
|
||||
return normalrule {
|
||||
name = e.name,
|
||||
ins = {csrcs[1], unpack(htargets)},
|
||||
ins = {csrcs[1], unpack(hsrcs)},
|
||||
outleaves = {outleaf},
|
||||
label = e.label,
|
||||
commands = e.commands,
|
||||
@@ -64,25 +74,85 @@ definerule("cfile",
|
||||
end
|
||||
)
|
||||
|
||||
normalrule {
|
||||
name = "mkheader",
|
||||
ins = {},
|
||||
outleaves = {"foo.h"},
|
||||
commands = {
|
||||
"echo 1 >> %{outs}"
|
||||
definerule("bundle",
|
||||
{
|
||||
srcs = { type="targets" },
|
||||
commands = {
|
||||
type="strings",
|
||||
default={
|
||||
"tar cf - %{ins} | (cd %{dir} && tar xf -)"
|
||||
}
|
||||
}
|
||||
},
|
||||
function (e)
|
||||
local outleaves = {}
|
||||
local commands = {}
|
||||
for _, f in pairs(filenamesof(e.srcs)) do
|
||||
local localf = basename(f)
|
||||
outleaves[#outleaves+1] = localf
|
||||
commands[#commands+1] = "cp "..f.." %{dir}/"..localf
|
||||
end
|
||||
|
||||
return normalrule {
|
||||
name = e.name,
|
||||
ins = e.srcs,
|
||||
outleaves = outleaves,
|
||||
label = e.label,
|
||||
commands = commands
|
||||
}
|
||||
end
|
||||
)
|
||||
|
||||
definerule("clibrary",
|
||||
{
|
||||
srcs = { type="targets" },
|
||||
deps = { type="targets", default={} },
|
||||
commands = {
|
||||
type="strings",
|
||||
default={
|
||||
"rm -f %{outs}",
|
||||
"$(AR) qs %{outs} %{ins}"
|
||||
},
|
||||
}
|
||||
},
|
||||
function (e)
|
||||
local csrcs = filenamesof(e.srcs, "%.c$")
|
||||
if (#csrcs < 1) then
|
||||
error("you must supply at least one C source file")
|
||||
end
|
||||
|
||||
local hsrcs = filenamesof(e.srcs, "%.h$")
|
||||
|
||||
local ins = {}
|
||||
for _, csrc in pairs(csrcs) do
|
||||
local n = basename(csrc):gsub("%.%w*$", "")
|
||||
ins[#ins+1] = cfile {
|
||||
name = e.name.."/"..n,
|
||||
srcs = {csrc, unpack(hsrcs)},
|
||||
deps = e.deps,
|
||||
}
|
||||
end
|
||||
|
||||
return normalrule {
|
||||
name = e.name,
|
||||
ins = ins,
|
||||
outleaves = { e.name..".a" },
|
||||
label = e.label,
|
||||
commands = e.commands
|
||||
}
|
||||
end
|
||||
)
|
||||
|
||||
clibrary {
|
||||
name = "mylib",
|
||||
srcs = {
|
||||
"modules/src/string/*.c",
|
||||
},
|
||||
deps = {
|
||||
"modules:headers"
|
||||
}
|
||||
}
|
||||
|
||||
cfile {
|
||||
name = "testfile-foo",
|
||||
srcs = "foo.c",
|
||||
}
|
||||
|
||||
cfile {
|
||||
name = "testfile-bar",
|
||||
srcs = {"bar.c", ":mkheader"},
|
||||
}
|
||||
|
||||
--[[
|
||||
--
|
||||
-- Targets:
|
||||
|
||||
Reference in New Issue
Block a user