Added uniproc library to project
This commit is contained in:
1
.gitignore
vendored
1
.gitignore
vendored
@@ -14,3 +14,4 @@
|
||||
/.make/thirdparty_luajit
|
||||
/CppProperties.json
|
||||
/lbs.exe
|
||||
/build/lbs.ilk
|
||||
|
||||
3
.gitmodules
vendored
3
.gitmodules
vendored
@@ -1,3 +1,6 @@
|
||||
[submodule "thirdparty/luajit"]
|
||||
path = thirdparty/luajit
|
||||
url = https://luajit.org/git/luajit.git
|
||||
[submodule "thirdparty/uniproc"]
|
||||
path = thirdparty/uniproc
|
||||
url = ssh://gitea@git.rileyk.au:19482/riley/uniproc.git
|
||||
|
||||
109
lbs.lua
109
lbs.lua
@@ -7,14 +7,14 @@ local config = {
|
||||
}
|
||||
|
||||
local program_output = "build/lbs"
|
||||
local source_dirs = {"src"}
|
||||
local include_dirs = {"include", "src", "thirdparty/luajit/src"}
|
||||
local source_dirs = {"src", "thirdparty/uniproc/src"}
|
||||
local include_dirs = {"include", "src", "thirdparty/luajit/src", "thirdparty/uniproc/include"}
|
||||
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)
|
||||
local function load_config(cfg_table, args)
|
||||
for i=1,#args,1 do
|
||||
k = args[i]
|
||||
if (k:sub(1,2) == "-j") then
|
||||
@@ -34,61 +34,75 @@ function load_config(cfg_table, args)
|
||||
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!")
|
||||
function table.shallow_copy(tbl)
|
||||
local new = {}
|
||||
for k,v in pairs(tbl) do
|
||||
new[k] = v
|
||||
end
|
||||
return new
|
||||
end
|
||||
|
||||
ec, stdout = platform.exec_parallel(base_cmd, config.max_parallel, src_args)
|
||||
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
|
||||
|
||||
local function compile(CXX, src_dirs, include_dirs, defines, additional_arguments)
|
||||
local base_argv = {}
|
||||
|
||||
additional_arguments[#additional_arguments+1] = "-c"
|
||||
for _,v in pairs(additional_arguments) do base_argv[#base_argv+1] = v end
|
||||
for _,v in pairs(include_dirs) do base_argv[#base_argv+1] = "-I\"" .. v .. "\"" end
|
||||
for k,v in pairs(defines) do base_argv[#base_argv+1] = "-D" .. k .. "=" .. v end
|
||||
|
||||
local obj_files, src_files = get_required_objects(src_dirs, ".cpp")
|
||||
local argv = {}
|
||||
for k,obj_file in pairs(obj_files) do
|
||||
local args = table.shallow_copy(base_argv)
|
||||
args[#args+1] = src_files[k]
|
||||
args[#args+1] = "-o\"" .. obj_file .. "\""
|
||||
argv[#argv+1] = args
|
||||
end
|
||||
|
||||
local ec, stdout = platform.exec_parallel(CXX, config.max_parallel, argv)
|
||||
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("Command \"" .. CXX .. " " .. table.concat(argv[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
|
||||
local function link(LNK, obj_dirs, library_dirs, linker_inputs, additional_arguments)
|
||||
local argv = {}
|
||||
for _,v in pairs(library_dirs) do argv[#argv+1] = "-L\"" .. v .. "\"" 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
|
||||
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, {})
|
||||
local ec, stdout = platform.exec(LNK, argv)
|
||||
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()
|
||||
end
|
||||
@@ -98,8 +112,9 @@ function build(...)
|
||||
local args = {...}
|
||||
config = load_config(config, args)
|
||||
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
|
||||
|
||||
return 0
|
||||
9
makefile
9
makefile
@@ -1,13 +1,14 @@
|
||||
CXX := clang++
|
||||
CC := clang
|
||||
|
||||
INCLUDES := include src thirdparty/luajit/src
|
||||
INCLUDES := include src thirdparty/luajit/src thirdparty/uniproc/include
|
||||
LIBRARY_DIRECTORIES := thirdparty/luajit/src
|
||||
LINKER_INPUTS := lua51 luajit
|
||||
|
||||
DEBUG_DEFINES :=
|
||||
DEFINES :=
|
||||
|
||||
CXX_FLAGS := -std=c++20 -g -O0
|
||||
CXX_FLAGS := -std=c11 -std=c++20 -g -O0
|
||||
CXX_DEBUG_FLAGS :=
|
||||
LNK_FLAGS := -g -O0
|
||||
LNK_DEBUG_FLAGS :=
|
||||
@@ -41,9 +42,11 @@ endif
|
||||
clean:
|
||||
$(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))
|
||||
|
||||
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
|
||||
$(CXX) -c $(CXX_FLAGS) $(foreach inc,$(INCLUDES),-I$(inc)) $(foreach def,$(DEFINES),-D$(def)) $< -o $@
|
||||
obj/src/%.hpp.o: src/%.hpp
|
||||
|
||||
1
thirdparty/uniproc
vendored
Submodule
1
thirdparty/uniproc
vendored
Submodule
Submodule thirdparty/uniproc added at f4927bf136
Reference in New Issue
Block a user