Browse Source

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

master
Izaya 2 months ago
parent
commit
ef2c01b1d4
  1. 3
      build.lua
  2. 3
      build.sh
  3. 2
      kcfg/base.cfg
  4. 3
      kcfg/full.cfg
  5. 11
      module/init.lua
  6. 41
      preproc.lua

3
build.lua

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

3
build.sh

@ -1,8 +1,9 @@
#!/bin/bash
LUA=${LUA:-lua}
KVAR=${1:-lua}
rm -r target/*
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
cat target/version.lua target/init.lua > target/tinit.lua
mv target/tinit.lua target/init.lua

2
kcfg/base.cfg

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

3
kcfg/full.cfg

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

11
module/init.lua

@ -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"
os.spawn(function()

41
preproc.lua

@ -59,6 +59,47 @@ end
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(_,...)
local tA = {...}
local out = table.remove(tA,#tA)

Loading…
Cancel
Save