refactor build system to allow pulling libraries from packages, assuming directories are set up correctly

This commit is contained in:
Izaya 2023-08-01 17:58:27 +10:00
parent eb98acc232
commit ef2c01b1d4
6 changed files with 48 additions and 15 deletions

View File

@ -1,7 +1,4 @@
local preproc = require "preproc" local preproc = require "preproc"
--local tA = {...} --local tA = {...}
function preproc.directives.includelib(file,name)
return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.preproc(file))
end
preproc(...) preproc(...)

View File

@ -1,8 +1,9 @@
#!/bin/bash #!/bin/bash
LUA=${LUA:-lua} LUA=${LUA:-lua}
KVAR=${1:-lua}
rm -r target/* rm -r target/*
mkdir -p target/doc &>/dev/null mkdir -p target/doc &>/dev/null
$LUA build.lua module/init.lua target/init.lua $LUA build.lua kcfg/$KVAR.cfg target/init.lua
echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)\" > target/version.lua echo _OSVERSION=\"PsychOS 2.0a3-$(git rev-parse --short HEAD)\" > target/version.lua
cat target/version.lua target/init.lua > target/tinit.lua cat target/version.lua target/init.lua > target/tinit.lua
mv target/tinit.lua target/init.lua mv target/tinit.lua target/init.lua

2
kcfg/base.cfg Normal file
View File

@ -0,0 +1,2 @@
--#include "module/base.lua"
--#include "module/init.lua"

3
kcfg/full.cfg Normal file
View File

@ -0,0 +1,3 @@
--#include "module/base.lua"
--#include "module/rtfsboot.lua"
--#include "module/init.lua"

View File

@ -1,14 +1,3 @@
--#include "module/syslog.lua"
--#include "module/sched.lua"
--#include "module/buffer.lua"
--#include "module/osutil.lua"
--#include "module/fs.lua"
--#include "module/io.lua"
--#include "module/devfs.lua"
--#include "module/devfs/syslog.lua"
--#include "module/component-get.lua"
--#include "module/loadfile.lua"
_OSVERSION=_OSVERSION or "PsychOS 2" _OSVERSION=_OSVERSION or "PsychOS 2"
os.spawn(function() os.spawn(function()

View File

@ -59,6 +59,47 @@ end
preproc.directives.include = preproc.preproc preproc.directives.include = preproc.preproc
function preproc.directives.includelib(file, name) -- string string -- string -- Returns a preprocessed inlined library
return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.preproc(file))
end
function preproc.directives.includepkgfile(package, file)
if (_OSVERSION or ""):sub(1,7) == "PsychOS" then
return preproc.preproc(string.format("/pkg/%s", file))
else
for path in (os.getenv("PSYCHOSPACKAGES") or "../PsychOSPackages"):gmatch("[^:]+") do
local f = io.open(string.format("%s/%s/%s", path, package, file), "r")
if f then
f:close()
return preproc.preproc(string.format("%s/%s/%s", path, package, file))
end
end
end
error(string.format("unable to locate file %s from package %s", file, package))
end
function preproc.directives.includepkglib(package, file, name) -- string string -- string -- Returns a preprocessed inlined library
return string.format("package.loaded.%s = (function()\n%s\nend)()", name, preproc.directives.includepkgfile(package, file))
end
--[[
function preproc.directives.includepkglib(package, file, name)
if (_OSVERSION or ""):sub(1,7) == "PsychOS" then
return preproc.directives.includelib(string.format("/pkg/%s", file), name)
else
for path in (os.getenv("PSYCHOSPACKAGES") or "../PsychOSPackages"):gmatch("[^:]+") do
print(string.format("%s/%s/%s", path, package, file))
local f = io.open(string.format("%s/%s/%s", path, package, file), "r")
if f then
f:close()
return preproc.directives.includelib(string.format("%s/%s/%s", path, package, file), name)
end
end
end
error(string.format("unable to locate library %s from package %s", name, package))
end
]]
return setmetatable(preproc,{__call=function(_,...) return setmetatable(preproc,{__call=function(_,...)
local tA = {...} local tA = {...}
local out = table.remove(tA,#tA) local out = table.remove(tA,#tA)