Added uniproc library to project

This commit is contained in:
2025-03-06 17:52:50 +11:00
parent b7745758aa
commit dbf91e0ebc
5 changed files with 72 additions and 49 deletions

1
.gitignore vendored
View File

@@ -14,3 +14,4 @@
/.make/thirdparty_luajit /.make/thirdparty_luajit
/CppProperties.json /CppProperties.json
/lbs.exe /lbs.exe
/build/lbs.ilk

3
.gitmodules vendored
View File

@@ -1,3 +1,6 @@
[submodule "thirdparty/luajit"] [submodule "thirdparty/luajit"]
path = thirdparty/luajit path = thirdparty/luajit
url = https://luajit.org/git/luajit.git url = https://luajit.org/git/luajit.git
[submodule "thirdparty/uniproc"]
path = thirdparty/uniproc
url = ssh://gitea@git.rileyk.au:19482/riley/uniproc.git

105
lbs.lua
View File

@@ -7,14 +7,14 @@ local config = {
} }
local program_output = "build/lbs" local program_output = "build/lbs"
local source_dirs = {"src"} local source_dirs = {"src", "thirdparty/uniproc/src"}
local include_dirs = {"include", "src", "thirdparty/luajit/src"} local include_dirs = {"include", "src", "thirdparty/luajit/src", "thirdparty/uniproc/include"}
local library_dirs = {"thirdparty/luajit/src"} local library_dirs = {"thirdparty/luajit/src"}
local linker_inputs = {"lua51", "luajit"} local linker_inputs = {"lua51", "luajit"}
local defines = {} local defines = {}
local additional_arguments = {"-std=c++20"} local additional_arguments = {"-std=c++20"}
function load_config(cfg_table, args) local function load_config(cfg_table, args)
for i=1,#args,1 do for i=1,#args,1 do
k = args[i] k = args[i]
if (k:sub(1,2) == "-j") then if (k:sub(1,2) == "-j") then
@@ -34,61 +34,75 @@ function load_config(cfg_table, args)
return cfg_table return cfg_table
end end
local function compile() function table.shallow_copy(tbl)
local new = {}
for k,v in pairs(tbl) do
new[k] = v
end
return new
end
local base_cmd = CXX .. " -c " local function get_required_objects(dirs, src_extension, obj_prefix, obj_postfix)
obj_prefix = obj_prefix or "obj/"
obj_postfix = obj_postfix or ".o"
local objs = {}
local new_src = {}
for fsobj in fs.forall(dirs) do
-- Get all files in the directory
local src_files
if fs.is_dir(fsobj) then src_files = fs.list_alldirs(fsobj)
else src_files = {fsobj} end
-- For each of the files,
for _, src_file in pairs(src_files) do repeat
-- Skip files that don't end in the provided extension
if (fs.extension(src_file) ~= src_extension) then break end
local obj_file = obj_prefix .. src_file .. obj_postfix
-- Skip old files that do not need to be recompiled
if not fs.is_newer(src_file) then break end
-- Add the src and obj file to a table that will be returned
objs[#objs+1] = obj_file
new_src[#new_src+1] = src_file
until true end
end
return objs, new_src
end
for _,v in pairs(include_dirs) do base_cmd = base_cmd .. "-I\"" .. v .. "\" " end local function compile(CXX, src_dirs, include_dirs, defines, additional_arguments)
for k,v in pairs(defines) do base_cmd = base_cmd .. "-D" .. k .. "=" .. v .. " " end local base_argv = {}
for _,v in pairs(additional_arguments) do base_cmd = base_cmd .. v .. " " end
local src_args = {} additional_arguments[#additional_arguments+1] = "-c"
for _,src_dir in pairs(source_dirs) do for _,v in pairs(additional_arguments) do base_argv[#base_argv+1] = v end
if (fs.is_dir(src_dir)) then for _,v in pairs(include_dirs) do base_argv[#base_argv+1] = "-I\"" .. v .. "\"" end
for fsobj in fs.forall(src_dir) do for k,v in pairs(defines) do base_argv[#base_argv+1] = "-D" .. k .. "=" .. v end
if (fs.is_file(fsobj) and fs.extension(fsobj) == ".cpp") then
src_args[#src_args+1] = fsobj .. " -o obj/" .. fsobj .. ".o" local obj_files, src_files = get_required_objects(src_dirs, ".cpp")
end local argv = {}
end for k,obj_file in pairs(obj_files) do
else local args = table.shallow_copy(base_argv)
print("[WARN ] Source directory " .. src_dir .. " does not exist!") args[#args+1] = src_files[k]
end args[#args+1] = "-o\"" .. obj_file .. "\""
argv[#argv+1] = args
end end
ec, stdout = platform.exec_parallel(base_cmd, config.max_parallel, src_args) local ec, stdout = platform.exec_parallel(CXX, config.max_parallel, argv)
for i,ec in pairs(ec) do for i,ec in pairs(ec) do
if (ec ~= 0) then if (ec ~= 0) then
print("Command \"" .. base_cmd .. src_args[i] .. "\" failed with exit code " .. tostring(ec) .. "and output;") print("Command \"" .. CXX .. " " .. table.concat(argv[i], " ") .. "\" failed with exit code " .. tostring(ec) .. " and output;")
print(stdout[i]) print(stdout[i])
print() print()
end end
end end
end end
local function link() local function link(LNK, obj_dirs, library_dirs, linker_inputs, additional_arguments)
local cmd = CXX .. " " local argv = {}
for _,lib_dir in pairs(library_dirs) do cmd = cmd .. "-L\"" .. lib_dir .. "\" " end for _,v in pairs(library_dirs) do argv[#argv+1] = "-L\"" .. v .. "\"" end
for _,lnk in pairs(linker_inputs) do cmd = cmd .. "-l\"" .. lnk .. "\" " end for _,v in pairs(linker_inputs) do argv[#argv+1] = "-l\"" .. v .. "\"" end
for _,v in pairs(additional_arguments) do argv[#argv+1] = v end
for _,src_dir in pairs(source_dirs) do local ec, stdout = platform.exec(LNK, argv)
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 if (ec ~= 0) then
print("Command \"" .. cmd .. "\" failed with exit code " .. tostring(ec) .. " and output;") print("Command \"" .. LNK .. " " .. table.concat(argv) .. "\" failed with exit code " .. tostring(ec) .. " and output;")
print(stdout) print(stdout)
print() print()
end end
@@ -98,8 +112,9 @@ function build(...)
local args = {...} local args = {...}
config = load_config(config, args) config = load_config(config, args)
print("Building " .. config.buildmode .. " with up to " .. tostring(config.max_parallel) .. " concurrent jobs") print("Building " .. config.buildmode .. " with up to " .. tostring(config.max_parallel) .. " concurrent jobs")
compile()
link() compile(CXX, source_dirs, include_dirs, defines, additional_arguments)
link(CXX, "obj", library_dirs, linker_inputs, {})
end end
return 0 return 0

View File

@@ -1,13 +1,14 @@
CXX := clang++ CXX := clang++
CC := clang
INCLUDES := include src thirdparty/luajit/src INCLUDES := include src thirdparty/luajit/src thirdparty/uniproc/include
LIBRARY_DIRECTORIES := thirdparty/luajit/src LIBRARY_DIRECTORIES := thirdparty/luajit/src
LINKER_INPUTS := lua51 luajit LINKER_INPUTS := lua51 luajit
DEBUG_DEFINES := DEBUG_DEFINES :=
DEFINES := DEFINES :=
CXX_FLAGS := -std=c++20 -g -O0 CXX_FLAGS := -std=c11 -std=c++20 -g -O0
CXX_DEBUG_FLAGS := CXX_DEBUG_FLAGS :=
LNK_FLAGS := -g -O0 LNK_FLAGS := -g -O0
LNK_DEBUG_FLAGS := LNK_DEBUG_FLAGS :=
@@ -41,9 +42,11 @@ endif
clean: clean:
$(call RM,$(call rwildcard, obj,*.o) build/$(OUTPUT_NAME)) $(call RM,$(call rwildcard, obj,*.o) build/$(OUTPUT_NAME))
SOURCE_FILES := $(call rwildcard,src,*.cpp,*.hpp) SOURCE_FILES := $(call rwildcard,src,*.cpp,*.hpp) $(call rwildcard,thirdparty/uniproc/src,*.cpp,*.hpp)
OBJECT_FILES := $(foreach d,$(addsuffix .o,$(SOURCE_FILES)), obj/$(d)) OBJECT_FILES := $(foreach d,$(addsuffix .o,$(SOURCE_FILES)), obj/$(d))
obj/thirdparty/uniproc/%.c.o: thirdparty/uniproc/src/%.c
$(CC) -c $(CXX_FLAGS) $(foreach inc,$(INCLUDES),-I$(inc)) $(foreach def,$(DEFINES),-D$(def)) $< -o $@
obj/src/%.cpp.o: src/%.cpp obj/src/%.cpp.o: src/%.cpp
$(CXX) -c $(CXX_FLAGS) $(foreach inc,$(INCLUDES),-I$(inc)) $(foreach def,$(DEFINES),-D$(def)) $< -o $@ $(CXX) -c $(CXX_FLAGS) $(foreach inc,$(INCLUDES),-I$(inc)) $(foreach def,$(DEFINES),-D$(def)) $< -o $@
obj/src/%.hpp.o: src/%.hpp obj/src/%.hpp.o: src/%.hpp

1
thirdparty/uniproc vendored Submodule

Submodule thirdparty/uniproc added at f4927bf136