Created lbs.lua build script to dog-food. makefile will be kept around for bootstrapping reasons
This commit is contained in:
105
lbs.lua
Normal file
105
lbs.lua
Normal file
@@ -0,0 +1,105 @@
|
||||
local CXX = "clang++"
|
||||
|
||||
local config = {
|
||||
["buildmode"]="debug",
|
||||
["target"]="x86_64-windows",
|
||||
["max_parallel"]=1
|
||||
}
|
||||
|
||||
local program_output = "build/lbs"
|
||||
local source_dirs = {"src"}
|
||||
local include_dirs = {"include", "src", "thirdparty/luajit/src"}
|
||||
local library_dirs = {"thirdparty/luajit/src"}
|
||||
local linker_inputs = {"lua51", "luajit"}
|
||||
local defines = {}
|
||||
local additional_arguments = {"-std=c++20"}
|
||||
|
||||
function load_config(cfg_table, args)
|
||||
for i=1,#args,1 do
|
||||
k = args[i]
|
||||
if (k:sub(1,2) == "-j") then
|
||||
if (tonumber(k:sub(3,-1),10) > 0) then
|
||||
cfg_table.max_parallel = tonumber(k:sub(3,-1),10)
|
||||
elseif (tonumber(args[i+1],10) > 0) then
|
||||
cfg_table.max_parallel = tonumber(args[i+1],10)
|
||||
i = i + 1
|
||||
else
|
||||
print("ERROR: -j option must be formatted as -j<num> or -j <num>. Numbers must be positive integers greater than 0")
|
||||
return -1
|
||||
end
|
||||
else
|
||||
cfg_table.buildmode = k
|
||||
end
|
||||
end
|
||||
return cfg_table
|
||||
end
|
||||
|
||||
local function compile()
|
||||
|
||||
local base_cmd = CXX .. " -c "
|
||||
|
||||
for _,v in pairs(include_dirs) do base_cmd = base_cmd .. "-I\"" .. v .. "\" " end
|
||||
for k,v in pairs(defines) do base_cmd = base_cmd .. "-D" .. k .. "=" .. v .. " " end
|
||||
for _,v in pairs(additional_arguments) do base_cmd = base_cmd .. v .. " " end
|
||||
|
||||
local src_args = {}
|
||||
for _,src_dir in pairs(source_dirs) do
|
||||
if (fs.is_dir(src_dir)) then
|
||||
for fsobj in fs.forall(src_dir) do
|
||||
if (fs.is_file(fsobj) and fs.extension(fsobj) == ".cpp") then
|
||||
src_args[#src_args+1] = fsobj .. " -o obj/" .. fsobj .. ".o"
|
||||
end
|
||||
end
|
||||
else
|
||||
print("[WARN ] Source directory " .. src_dir .. " does not exist!")
|
||||
end
|
||||
end
|
||||
|
||||
ec, stdout = platform.exec_parallel(base_cmd, config.max_parallel, src_args)
|
||||
for i,ec in pairs(ec) do
|
||||
if (ec ~= 0) then
|
||||
print("Command \"" .. base_cmd .. src_args[i] .. "\" failed with exit code " .. tostring(ec) .. "and output;")
|
||||
print(stdout[i])
|
||||
print()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function link()
|
||||
local cmd = CXX .. " "
|
||||
for _,lib_dir in pairs(library_dirs) do cmd = cmd .. "-L\"" .. lib_dir .. "\" " end
|
||||
for _,lnk in pairs(linker_inputs) do cmd = cmd .. "-l\"" .. lnk .. "\" " end
|
||||
|
||||
for _,src_dir in pairs(source_dirs) do
|
||||
if (fs.is_dir(src_dir)) then
|
||||
for fsobj in fs.forall(src_dir) do
|
||||
if (fs.is_file(fsobj) and fs.extension(fsobj) == ".cpp") then
|
||||
cmd = cmd .. "obj/" .. fsobj .. ".o "
|
||||
end
|
||||
end
|
||||
else
|
||||
print("[WARN ] Source directory " .. src_dir .. " does not exist!")
|
||||
end
|
||||
end
|
||||
cmd = cmd .. "-o " .. program_output
|
||||
local platform_seps = {}
|
||||
for match in config.target:gmatch("[^-]+") do platform_seps[#platform_seps+1] = match end
|
||||
if (platform_seps[2] == "windows") then cmd = cmd .. ".exe " else cmd = cmd .. " " end
|
||||
|
||||
ec, stdout = platform.exec(cmd, {})
|
||||
if (ec ~= 0) then
|
||||
print("Command \"" .. cmd .. "\" failed with exit code " .. tostring(ec) .. " and output;")
|
||||
print(stdout)
|
||||
print()
|
||||
end
|
||||
end
|
||||
|
||||
function build(...)
|
||||
local args = {...}
|
||||
config = load_config(config, args)
|
||||
print("Building " .. config.buildmode .. " with up to " .. tostring(config.max_parallel) .. " concurrent jobs")
|
||||
compile()
|
||||
link()
|
||||
end
|
||||
|
||||
return 0
|
||||
Reference in New Issue
Block a user