Compare commits
13 Commits
2522eacb86
...
v2
| Author | SHA1 | Date | |
|---|---|---|---|
|
2a121caf42
|
|||
|
3f829f7a58
|
|||
|
2bcbc62bf8
|
|||
|
b4ed4aa4c0
|
|||
|
df20c55b4e
|
|||
|
af6d3223da
|
|||
|
68e2c49c8f
|
|||
|
40ea3caf2a
|
|||
|
667151b1b6
|
|||
|
fe01a41aac
|
|||
|
dbf91e0ebc
|
|||
|
|
b7745758aa | ||
|
|
a610e67325 |
19
.gitignore
vendored
Normal file
19
.gitignore
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
################################################################################
|
||||
# This .gitignore file was automatically created by Microsoft(R) Visual Studio.
|
||||
################################################################################
|
||||
|
||||
/.vs
|
||||
/build/lbs.exe
|
||||
/build/lbs.pdb
|
||||
/obj/src/lua_dependency_tree.cpp.o
|
||||
/obj/src/lua_filesystem.cpp.o
|
||||
/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
|
||||
/build/lbs.ilk
|
||||
/obj/thirdparty/uniproc/src
|
||||
/releases
|
||||
9
.gitmodules
vendored
Normal file
9
.gitmodules
vendored
Normal file
@@ -0,0 +1,9 @@
|
||||
[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
|
||||
[submodule "thirdparty/libgit2"]
|
||||
path = thirdparty/libgit2
|
||||
url = https://github.com/libgit2/libgit2.git
|
||||
154
lbs.lua
Normal file
154
lbs.lua
Normal file
@@ -0,0 +1,154 @@
|
||||
local CXX = "clang++"
|
||||
|
||||
local config = {
|
||||
["buildmode"]="debug",
|
||||
["target"]="x86_64-windows",
|
||||
["max_parallel"]=1
|
||||
}
|
||||
|
||||
local program_output = "build/lbs"
|
||||
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"}
|
||||
|
||||
local 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
|
||||
|
||||
function table.shallow_copy(tbl)
|
||||
local new = {}
|
||||
for k,v in pairs(tbl) do
|
||||
new[k] = v
|
||||
end
|
||||
return new
|
||||
end
|
||||
|
||||
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 _,dir in pairs(dirs) do
|
||||
for fsobj in fs.forall(dir) 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, obj_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
|
||||
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"
|
||||
if (config.buildmode == "debug") then
|
||||
additional_arguments[#additional_arguments+1] = "-O0"
|
||||
additional_arguments[#additional_arguments+1] = "-g"
|
||||
end
|
||||
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
|
||||
|
||||
print("Compiling...")
|
||||
local ec, stdout, stderr = platform.exec_parallel(CXX, config.max_parallel, argv)
|
||||
for i,ec in pairs(ec) do
|
||||
if (ec ~= 0) then
|
||||
print("Command ".. tostring(i) .." \"" .. CXX .. " " .. table.concat(argv[i], " ") .. "\" failed with exit code " .. tostring(ec) .. " and output;")
|
||||
print(stderr[i])
|
||||
print(stdout[i])
|
||||
print()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function link(LNK, obj_dirs, library_dirs, linker_inputs, additional_arguments, file_output)
|
||||
local argv = {}
|
||||
if (config.buildmode == "debug") then
|
||||
additional_arguments[#additional_arguments+1] = "-O0"
|
||||
additional_arguments[#additional_arguments+1] = "-g"
|
||||
end
|
||||
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 _,obj_dir in pairs(obj_dirs) do
|
||||
local obj_files = fs.list_alldirs("obj")
|
||||
for _,obj_file in pairs(obj_files) do repeat
|
||||
if fs.extension(obj_file) ~= ".o" then break end
|
||||
argv[#argv+1] = obj_file
|
||||
until true end
|
||||
end
|
||||
|
||||
argv[#argv+1] = "-o " .. file_output
|
||||
|
||||
print("Linking...")
|
||||
local ec, stdout, stderr = platform.exec(LNK, argv)
|
||||
if (ec ~= 0) then
|
||||
print("Command \"" .. LNK .. " " .. table.concat(argv, " ") .. "\" failed with exit code " .. tostring(ec) .. " and output;")
|
||||
print(stderr)
|
||||
print(stdout)
|
||||
print()
|
||||
end
|
||||
end
|
||||
|
||||
function build(...)
|
||||
local args = {...}
|
||||
local program_name = program_output
|
||||
for section in config.target:gmatch("[^-]+") do
|
||||
if section == "windows" then program_name = program_name .. ".exe" end
|
||||
end
|
||||
|
||||
config = load_config(config, args)
|
||||
print("Building " .. config.buildmode .. " with up to " .. tostring(config.max_parallel) .. " concurrent jobs")
|
||||
|
||||
compile(CXX, source_dirs, include_dirs, defines, additional_arguments)
|
||||
|
||||
link(CXX, {"obj"}, library_dirs, linker_inputs, {}, program_name)
|
||||
|
||||
print("Program generated! See " .. program_name)
|
||||
end
|
||||
|
||||
function main(...) build(...) end
|
||||
|
||||
return 0
|
||||
70
makefile
Normal file
70
makefile
Normal file
@@ -0,0 +1,70 @@
|
||||
CC=clang
|
||||
CFLAGS = -Wall -Wextra
|
||||
|
||||
ifeq ($(OS),Windows_NT)
|
||||
CFLAGS += -D WIN32
|
||||
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
|
||||
CFLAGS += -D AMD64
|
||||
else
|
||||
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
|
||||
CFLAGS += -D AMD64
|
||||
endif
|
||||
ifeq ($(PROCESSOR_ARCHITECTURE),x86)
|
||||
CFLAGS += -D IA32
|
||||
endif
|
||||
endif
|
||||
|
||||
RELEASE_TARGET=bin/lbs.exe
|
||||
DEBUG_TARGET=bin/lbs-dbg.exe
|
||||
else
|
||||
UNAME_S := $(shell uname -s)
|
||||
ifeq ($(UNAME_S),Linux)
|
||||
CFLAGS += -D LINUX
|
||||
endif
|
||||
ifeq ($(UNAME_S),Darwin)
|
||||
CFLAGS += -D OSX
|
||||
endif
|
||||
UNAME_P := $(shell uname -p)
|
||||
ifeq ($(UNAME_P),x86_64)
|
||||
CFLAGS += -D AMD64
|
||||
endif
|
||||
ifneq ($(filter %86,$(UNAME_P)),)
|
||||
CFLAGS += -D IA32
|
||||
endif
|
||||
ifneq ($(filter arm%,$(UNAME_P)),)
|
||||
CFLAGS += -D ARM
|
||||
endif
|
||||
RELEASE_TARGET=bin/lbs
|
||||
DEBUG_TARGET=bin/lbs-dbg
|
||||
endif
|
||||
|
||||
|
||||
# If the first argument is "modules"...
|
||||
ifeq (modules,$(firstword $(MAKECMDGOALS)))
|
||||
# use the rest as arguments for "run"
|
||||
MODULE_ARGS := $(wordlist 2,$(words $(MAKECMDGOALS)),$(MAKECMDGOALS))
|
||||
# ...and turn them into do-nothing targets
|
||||
$(eval $(MODULE_ARGS):;@:)
|
||||
endif
|
||||
|
||||
rwildcard=$(foreach d,$(wildcard $(1:=/*)),$(call rwildcard,$d,$2) $(filter $(subst *,%,$2),$d))
|
||||
|
||||
SRC_FILES=$(call rwildcard, src, *.c)
|
||||
OBJ_FILES=$(addprefix obj/, $(SRC_FILES:.c=.o))
|
||||
modules:
|
||||
cd modules && $(MAKE) $(MODULE_ARGS)
|
||||
|
||||
|
||||
obj/src/%.o: src/%.c
|
||||
$(CC) $(CFLAGS) -c $(@:obj/%.o=%.c) -o $@
|
||||
|
||||
release: $(RELEASE_TARGET)
|
||||
$(RELEASE_TARGET): $(OBJ_FILES)
|
||||
$(CC) $(LFLAGS) $^ -o $@
|
||||
|
||||
debug: $(DEBUG_TARGET)
|
||||
$(DEBUG_TARGET): $(OBJ_FILES)
|
||||
$(CC) $(LFLAGS) $^ -o $@
|
||||
|
||||
clean:
|
||||
echo TODO
|
||||
7
src/main.c
Normal file
7
src/main.c
Normal file
@@ -0,0 +1,7 @@
|
||||
#include <stdio.h>
|
||||
|
||||
int main()
|
||||
{
|
||||
printf("Hello, World!\n");
|
||||
return 0;
|
||||
}
|
||||
1
thirdparty/libgit2
vendored
Submodule
1
thirdparty/libgit2
vendored
Submodule
Submodule thirdparty/libgit2 added at 21a351b0ed
1
thirdparty/luajit
vendored
Submodule
1
thirdparty/luajit
vendored
Submodule
Submodule thirdparty/luajit added at 84cb21ffaf
1
thirdparty/uniproc
vendored
Submodule
1
thirdparty/uniproc
vendored
Submodule
Submodule thirdparty/uniproc added at 8948e75d06
Reference in New Issue
Block a user