Created lbs.lua build script to dog-food. makefile will be kept around for bootstrapping reasons

This commit is contained in:
Riley-King
2025-02-27 00:01:55 +11:00
parent a610e67325
commit b7745758aa
2 changed files with 109 additions and 0 deletions

4
.gitignore vendored
View File

@@ -10,3 +10,7 @@
/obj/src/lua_platform.cpp.o
/obj/src/main.cpp.o
/obj/src/simple_string.cpp.o
/.make
/.make/thirdparty_luajit
/CppProperties.json
/lbs.exe

105
lbs.lua Normal file
View 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