Compare commits

...

13 Commits

Author SHA1 Message Date
2a121caf42 Created main makefile - Need to add clean recipe
`make modules debug|release MODULES...` Builds the provided list of lua modules in release/debug
`make release`
`make debug` Builds a debug build of the lbs program
`make clean` TODO
2025-11-25 00:04:24 +11:00
3f829f7a58 Nuked existing codebase 2025-11-25 00:01:47 +11:00
2bcbc62bf8 Why do I need to merge this?! 2025-03-10 20:59:05 +11:00
b4ed4aa4c0 Fixed issue where first process is null 2025-03-10 20:57:05 +11:00
df20c55b4e Fixed issue where first process is null 2025-03-10 20:55:04 +11:00
af6d3223da Added libgit2 dependency 2025-03-10 20:11:21 +11:00
68e2c49c8f Updated lbs to use new uniproc library
Fixed bug in fs.list_alldirs where it used directory_iterator rather that recursive_directory_iterator
Fixed memory/type bugs in lua_platform.cpp
Updated lbs.lua to reflect this
2025-03-06 19:27:19 +11:00
40ea3caf2a Added ability to switch between printing stdout and stderr in error messages 2025-03-06 17:59:13 +11:00
667151b1b6 Replaced popen usage with uniproc_process 2025-03-06 17:54:53 +11:00
fe01a41aac Added fs.is_newer function to filesystem library 2025-03-06 17:54:26 +11:00
dbf91e0ebc Added uniproc library to project 2025-03-06 17:52:50 +11:00
Riley-King
b7745758aa Created lbs.lua build script to dog-food. makefile will be kept around for bootstrapping reasons 2025-02-27 00:01:55 +11:00
Riley-King
a610e67325 Initial release commit 2025-02-27 00:01:01 +11:00
8 changed files with 262 additions and 0 deletions

19
.gitignore vendored Normal file
View 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
View 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
View 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
View 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
View File

@@ -0,0 +1,7 @@
#include <stdio.h>
int main()
{
printf("Hello, World!\n");
return 0;
}

1
thirdparty/libgit2 vendored Submodule

Submodule thirdparty/libgit2 added at 21a351b0ed

1
thirdparty/luajit vendored Submodule

Submodule thirdparty/luajit added at 84cb21ffaf

1
thirdparty/uniproc vendored Submodule

Submodule thirdparty/uniproc added at 8948e75d06