2013-03-11 21:03:27 +00:00
|
|
|
|
|
|
|
|
|
|
|
function stringifyKernel(filenameIn, filenameOut, kernelMethod)
|
2013-08-10 19:08:15 +00:00
|
|
|
local BUFSIZE = 10*1024*1024 -- 10MB
|
2013-03-11 21:03:27 +00:00
|
|
|
local f = io.open(filenameIn,"r");
|
|
|
|
local fw = io.open(filenameOut,"w");
|
|
|
|
fw:write("//this file is autogenerated using stringify.bat (premake --stringify) in the build folder of this project\n")
|
|
|
|
fw:write("static const char* " .. kernelMethod .. "= \\\n")
|
|
|
|
local cc, lc, wc = 0, 0, 0 -- char, line, and word counts
|
|
|
|
while true do
|
|
|
|
local lines, rest = f:read(BUFSIZE, "*line")
|
|
|
|
if not lines then break end
|
|
|
|
|
|
|
|
local i = 0
|
|
|
|
local startpos = 0
|
|
|
|
local slen = string.len(lines)
|
|
|
|
local endpos = 0
|
|
|
|
while true do
|
|
|
|
i = string.find(lines, "\n", i+1) -- find 'next' newline
|
|
|
|
if i == nil then
|
|
|
|
endpos = slen
|
|
|
|
else
|
|
|
|
endpos = i
|
|
|
|
end
|
2013-08-02 04:05:19 +00:00
|
|
|
|
|
|
|
oneline = string.sub(lines,startpos,endpos)
|
|
|
|
oneline = string.gsub(oneline,"\n","")
|
|
|
|
oneline = string.gsub(oneline,"\"","\\\"");
|
|
|
|
oneline = '\"' .. oneline .. '\\n\"'
|
|
|
|
oneline = string.gsub(oneline,"\\\\n","")
|
|
|
|
oneline = oneline .. "\n"
|
|
|
|
--print(oneline)
|
|
|
|
fw:write(oneline);
|
|
|
|
|
2013-03-11 21:03:27 +00:00
|
|
|
if i == nil then break end
|
|
|
|
startpos = i+1
|
|
|
|
end
|
|
|
|
|
|
|
|
if rest then lines = lines .. rest .. '\n' end
|
|
|
|
cc = cc + string.len(lines)
|
|
|
|
-- count words in the chunk
|
|
|
|
local _,t = string.gsub(lines, "%S+", "")
|
|
|
|
wc = wc + t
|
|
|
|
-- count newlines in the chunk
|
|
|
|
_,t = string.gsub(lines, "\n", "\n")
|
|
|
|
lc = lc + t
|
|
|
|
end
|
|
|
|
--print("stringified " .. filenameIn .. " into " .. filenameOut .. " processed " .. lc .. " lines")
|
|
|
|
print(filenameIn .. " (" .. lc .. " lines)")
|
|
|
|
|
|
|
|
f:close()
|
|
|
|
fw:write(";\n")
|
|
|
|
fw:close()
|
|
|
|
end
|
2013-08-02 04:05:19 +00:00
|
|
|
|
|
|
|
|
2013-03-11 21:03:27 +00:00
|
|
|
|
2013-08-02 04:05:19 +00:00
|
|
|
function preprocessKernel(kernelfile, filenameOut, kernelMethod)
|
2013-08-03 17:13:13 +00:00
|
|
|
lcpp=require('lcpp');
|
2013-08-02 04:05:19 +00:00
|
|
|
local out=lcpp.compileFile(kernelfile);
|
2013-08-03 17:13:13 +00:00
|
|
|
local embedFileName = kernelfile .. ".embed"
|
|
|
|
local fw = io.open(embedFileName,"w");
|
2013-08-02 04:05:19 +00:00
|
|
|
fw:write(out)
|
|
|
|
fw:close()
|
2013-08-03 17:13:13 +00:00
|
|
|
stringifyKernel(embedFileName,filenameOut, kernelMethod);
|
2013-08-02 04:05:19 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
2013-03-11 21:03:27 +00:00
|
|
|
newoption {
|
|
|
|
trigger = "kernelfile",
|
|
|
|
value = "kernelpath",
|
|
|
|
description = "full path to the kernel source input file"
|
|
|
|
}
|
|
|
|
|
|
|
|
newoption {
|
|
|
|
trigger = "headerfile",
|
|
|
|
value = "path",
|
|
|
|
description = "full path to the header output file"
|
|
|
|
}
|
|
|
|
|
|
|
|
newoption {
|
|
|
|
trigger = "stringname",
|
|
|
|
value = "var",
|
|
|
|
description = "name of the kernel string variable"
|
|
|
|
}
|
|
|
|
|
2013-08-02 04:05:19 +00:00
|
|
|
|
|
|
|
|
2013-03-11 21:03:27 +00:00
|
|
|
newaction {
|
|
|
|
trigger = "stringify",
|
|
|
|
description = "stringify kernels source code into strings",
|
2013-08-02 04:05:19 +00:00
|
|
|
execute = function()
|
|
|
|
preprocessKernel( _OPTIONS["kernelfile"] , _OPTIONS["headerfile"], _OPTIONS["stringname"])
|
2013-03-11 21:03:27 +00:00
|
|
|
end
|
2013-05-23 00:46:47 +00:00
|
|
|
}
|
2013-08-02 04:05:19 +00:00
|
|
|
|
|
|
|
|
|
|
|
|