2017-06-26 22:49:56 +10:00
|
|
|
--#!/usr/bin/env lua5.2
|
2017-04-19 02:40:25 +10:00
|
|
|
-- Initialization
|
|
|
|
log = ""
|
2017-06-26 22:49:56 +10:00
|
|
|
prefix=""
|
2017-04-19 02:40:25 +10:00
|
|
|
oldprint=print
|
|
|
|
function print(...)
|
2017-05-25 09:03:14 +10:00
|
|
|
oldprint(...)
|
2017-04-19 02:40:25 +10:00
|
|
|
logline = ""
|
|
|
|
if #{...} > 0 then
|
|
|
|
if #{...} > 1 then
|
|
|
|
for k,v in ipairs({...}) do
|
|
|
|
logline = logline .. "\t" .. tostring(v)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
tA = {...}
|
|
|
|
logline = tostring(tA[1])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
log = (log .. logline .. "\n"):sub(1,-1)
|
|
|
|
end
|
|
|
|
print("Initializing and reading configuration")
|
|
|
|
ts={}
|
2017-05-25 09:03:14 +10:00
|
|
|
tA = {...}
|
|
|
|
for k,v in ipairs(tA) do
|
|
|
|
if type(v) == "string" then
|
|
|
|
if v:sub(1,10) == "--cfgfile=" then
|
|
|
|
cfgfile = v:sub(11)
|
|
|
|
elseif v:sub(1,10) == "--modfile=" then
|
|
|
|
modfile = v:sub(11)
|
2017-06-26 22:49:56 +10:00
|
|
|
elseif v:sub(1,9) == "--prefix=" then
|
|
|
|
prefix=v:sub(10)
|
|
|
|
print("Prefix is: "..prefix)
|
2017-05-25 09:03:14 +10:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
2017-04-19 02:40:25 +10:00
|
|
|
ss=""
|
2017-04-23 19:17:22 +10:00
|
|
|
cfgfile = cfgfile or "build.cfg"
|
|
|
|
modfile = modfile or "modules.cfg"
|
2017-06-26 22:49:56 +10:00
|
|
|
cfgfile=prefix..cfgfile
|
|
|
|
modfile=prefix..modfile
|
2017-04-19 02:40:25 +10:00
|
|
|
cfg={}
|
2017-04-20 17:43:33 +10:00
|
|
|
f=io.open(cfgfile,"rb")
|
2017-04-19 02:40:25 +10:00
|
|
|
repeat
|
|
|
|
line = f:read("*l")
|
2017-06-26 22:49:56 +10:00
|
|
|
print(line)
|
2017-04-19 02:40:25 +10:00
|
|
|
if line ~= nil then
|
|
|
|
w={}
|
|
|
|
for wo in line:gmatch("%S+") do table.insert(w, wo) end
|
2017-06-26 22:49:56 +10:00
|
|
|
cfg[w[1] or ""] = w[2] or ""
|
2017-04-19 02:40:25 +10:00
|
|
|
end
|
|
|
|
until line == nil or line == ""
|
2017-04-20 19:22:42 +10:00
|
|
|
cfg.opath = cfg.opath or "kernel.lua"
|
|
|
|
cfg.ospath = cfg.ospath or "skernel.lua"
|
2017-06-26 22:49:56 +10:00
|
|
|
cfg.opath = prefix .. cfg.opath
|
|
|
|
cfg.ospath = prefix .. cfg.ospath
|
2017-04-19 02:40:25 +10:00
|
|
|
print()
|
|
|
|
-- Module list
|
|
|
|
print("Reading modules to load")
|
|
|
|
tm={}
|
2017-04-20 17:43:33 +10:00
|
|
|
f=io.open(modfile,"rb")
|
2017-04-19 02:40:25 +10:00
|
|
|
function nl()
|
|
|
|
return f:read("*l")
|
|
|
|
end
|
|
|
|
for line in nl do
|
|
|
|
print(" - "..line)
|
|
|
|
table.insert(tm,line)
|
|
|
|
end
|
|
|
|
f:close()
|
|
|
|
print(tostring(#tm).." modules to load.\n")
|
|
|
|
|
|
|
|
-- Loading modules
|
|
|
|
print("Loading modules")
|
|
|
|
for k,v in ipairs(tm) do
|
|
|
|
print(" - "..v.." - modules/"..v)
|
2017-06-26 22:49:56 +10:00
|
|
|
f=io.open(prefix.."modules/"..v,"rb")
|
2017-04-20 19:11:20 +10:00
|
|
|
if cfg.optimise == "yes" then
|
2017-04-19 02:40:25 +10:00
|
|
|
data = f:read("*a")
|
|
|
|
else
|
|
|
|
data = "--"..v.."\n"..f:read("*a")
|
|
|
|
end
|
|
|
|
table.insert(ts,data)
|
|
|
|
f:close()
|
|
|
|
end
|
|
|
|
print(tostring(#tm).." modules loaded.\n")
|
|
|
|
|
|
|
|
-- Generate source
|
|
|
|
print("Generating source")
|
2017-04-21 05:26:39 +10:00
|
|
|
if cfg.listmods == "yes" then
|
2017-05-15 01:46:40 +10:00
|
|
|
ss=ss.."_MOD,_OSVERSION,_BD={"
|
2017-04-21 05:26:39 +10:00
|
|
|
for k,v in ipairs(tm) do
|
|
|
|
ss=ss..'"'..v..'",'
|
|
|
|
end
|
2017-04-24 01:12:24 +10:00
|
|
|
ss=ss.."},"
|
|
|
|
if _OSVERSION == nil then
|
2017-05-15 01:46:40 +10:00
|
|
|
ss=ss..'"MultICE '..io.popen("git rev-parse HEAD"):read("*a"):sub(1,7)..'","'..os.date("%Y/%m/%d %H:%M %z")..'"\n'
|
2017-04-24 01:12:24 +10:00
|
|
|
else
|
|
|
|
ss=ss..'"MultICE DR0"\n'
|
|
|
|
end
|
2017-04-21 05:26:39 +10:00
|
|
|
end
|
2017-04-19 02:40:25 +10:00
|
|
|
for k,v in pairs(ts) do
|
|
|
|
ss=ss..v
|
|
|
|
io.write(".")
|
|
|
|
end
|
2017-06-26 22:49:56 +10:00
|
|
|
print("")
|
2017-04-19 02:40:25 +10:00
|
|
|
|
|
|
|
-- Output
|
|
|
|
print("Outputting to "..cfg.opath)
|
|
|
|
f=io.open(cfg.opath,"wb")
|
|
|
|
f:write(ss)
|
|
|
|
f:close()
|
|
|
|
print("Total size: "..tostring(ss:len()).."\n")
|
|
|
|
|
2017-04-20 19:22:42 +10:00
|
|
|
-- Optimise for space
|
|
|
|
if cfg.optimise == "yes" then
|
|
|
|
if _OSVERSION ~= nil then
|
|
|
|
if _OSVERSION:sub(1,6) == "OpenOS" then
|
|
|
|
os.execute("strip "..cfg.opath.." "..cfg.ospath)
|
|
|
|
end
|
|
|
|
else
|
|
|
|
os.execute("lua strip.lua "..cfg.opath.." "..cfg.ospath)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-04-19 02:40:25 +10:00
|
|
|
-- Check syntax
|
|
|
|
if cfg.test == "yes" then
|
|
|
|
print("Checking for errors...")
|
|
|
|
err={pcall(load,ss)}
|
|
|
|
if err[1] ~= true then
|
2017-05-25 09:03:14 +10:00
|
|
|
print(table.unpack(err))
|
2017-04-19 02:40:25 +10:00
|
|
|
else
|
|
|
|
print("No errors detected by load()")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- Write log
|
|
|
|
if cfg.log == "yes" then
|
2017-06-26 22:49:56 +10:00
|
|
|
f=io.open(prefix.."build.log","wb")
|
2017-04-19 02:40:25 +10:00
|
|
|
f:write(log)
|
|
|
|
f:close()
|
|
|
|
end
|