From 275c50c10d333ce9e637f6a44caed946e3fbd94a Mon Sep 17 00:00:00 2001 From: Izaya Date: Sun, 8 Oct 2017 08:22:35 +1100 Subject: [PATCH] wrote lmk, an more general lua build system --- configs/everything.cfg | 3 ++ configs/headless.cfg | 3 ++ configs/minimal.cfg | 3 ++ exec/lmk.lua | 73 ++++++++++++++++++++++++++++++++++++++++++ genheader.lua | 12 +++++++ genkernel.lua | 3 -- genkernel.sh | 2 +- header.lua | 2 ++ 8 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 exec/lmk.lua create mode 100755 genheader.lua delete mode 100755 genkernel.lua create mode 100644 header.lua diff --git a/configs/everything.cfg b/configs/everything.cfg index dc0ad0f..bf4bce3 100755 --- a/configs/everything.cfg +++ b/configs/everything.cfg @@ -1,3 +1,6 @@ +lexec genheader.lua +ofile out/everything.lua +header.lua modules/base/loadlin.lua modules/debug/log.lua modules/base/header.lua diff --git a/configs/headless.cfg b/configs/headless.cfg index 35773f0..ac78bf5 100755 --- a/configs/headless.cfg +++ b/configs/headless.cfg @@ -1,3 +1,6 @@ +lexec genheader.lua +ofile out/headless.lua +header.lua modules/base/loadlin.lua modules/debug/log.lua modules/base/header.lua diff --git a/configs/minimal.cfg b/configs/minimal.cfg index 8f80034..2423332 100755 --- a/configs/minimal.cfg +++ b/configs/minimal.cfg @@ -1,3 +1,6 @@ +lexec genheader.lua +ofile out/minimal.lua +header.lua modules/base/loadlin.lua modules/debug/log.lua modules/base/header.lua diff --git a/exec/lmk.lua b/exec/lmk.lua new file mode 100644 index 0000000..4250d04 --- /dev/null +++ b/exec/lmk.lua @@ -0,0 +1,73 @@ +local tA = {...} +local modlistf = tA[1] +local nk = "" +local oprint = print +print(modlistf) +function print(...) + if tA[2] then + oprint(...) + end +end +f = io.open(modlistf,"rb") +if not f then error("no input file") end +local ofile = nil +local c=f:read("*a") +f:close() +local n=1 +local function wcfile() + if ofile then + f=io.open(ofile,"wb") + if f then + oprint("writing file "..ofile) + f:write(nk) + f:close() + else + oprint("warning: unable to open file "..ofile.." to write") + end + end +end +local function apfile(fp) + local f=io.open(fp,"rb") + if f then + nk=nk..f:read("*a") + f:close() + end +end +for line in c:gmatch("[^\r\n]+") do + print(line) + local tw = {} + for w in line:gmatch("%S+") do + tw[#tw+1] = w + end + n=n+1 + if tw[1] == "ofile" then + wcfile() + ofile = tw[2] + nk="" + elseif tw[1] == "exec" then + os.execute(tw[2]) + elseif tw[1] == "lexec" then + local f=io.open(tw[2],"rb") + if f then + local fc = f:read("*a") + print(fc) + print(pcall(load(fc))) + end + f:close() + elseif tw[1] == "fwrap" then + nk=nk.."function "..tw[2].."(...)\n" + apfile(tw[3]) + nk=nk.."\nend\n" + elseif tw[1] == "libwrap" then + nk=nk.."function "..tw[2].."(...)\n" + apfile(tw[3]) + nk=nk.."\nend\n_G."..tw[2].." = "..tw[2].."()\n" + elseif tw[1] == "alias" then + nk=nk..tw[2].."="..tw[3].."\n" + elseif tw[1] == "include" then + apfile(tw[2]) + elseif #tw == 1 then + apfile(line) + end +end +wcfile() diff --git a/genheader.lua b/genheader.lua new file mode 100755 index 0000000..5cd83c6 --- /dev/null +++ b/genheader.lua @@ -0,0 +1,12 @@ +local f = io.open("header.lua","wb") +local kname = nil +if not _OSNAME then + local w,gn = pcall(io.popen,"git rev-parse HEAD") + if w then + kname = gn:read():sub(1,7) + gn:close() + end +end +f:write("_OSVERSION=\"PsychOS "..(kname or os.date("%Y/%m/%d %H:%M %z")).."\"\n") +f:write("_BD=\""..os.date("%Y/%m/%d %H:%M %z").."\"\n") +f:close() diff --git a/genkernel.lua b/genkernel.lua deleted file mode 100755 index dca0aea..0000000 --- a/genkernel.lua +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env lua -require "modules/applications/genkernel" -print(genkernel(...)) diff --git a/genkernel.sh b/genkernel.sh index 526bab6..f3dd60c 100755 --- a/genkernel.sh +++ b/genkernel.sh @@ -2,6 +2,6 @@ mkdir -p out/ for f in `dir -d configs/*`; do kn=$(echo $f | cut -f 1 -d '.' | cut -f 2 -d "/") - ./genkernel.lua $f "$(git rev-parse --short HEAD)" > out/$kn.lua + lua exec/lmk.lua $f lua strip.lua out/$kn.lua out/s$kn.lua done diff --git a/header.lua b/header.lua new file mode 100644 index 0000000..ba792db --- /dev/null +++ b/header.lua @@ -0,0 +1,2 @@ +_OSVERSION="PsychOS 83e2673" +_BD="2017/10/08 08:18 +1100"