fix: 解决掉sqlite3的全部编译警告
[LuatOS.git] / script / update_inline_libs.lua
blob6f780be136bd0927fc635054a496a5ea1596632b
2 --[[
3 本文件用于生成内嵌到固件里的脚本
5 默认是corelib目录里的全部.lua文件
7 如需新增或更新, 把.lua文件放入corelib目录, 在当前目录下执行:
8 luatos_32bit.exe update_inline_libs.lua
10 相关exe文件可以在 https://gitee.com/openLuat/LuatOS/attach_files 下载
13 -- 主要配置项, lua分需要区分两种编译环境:
14 -- lua_Integer的大小, 受 LUA_32BITS控制, 默认是启用
15 -- size_t 大小, 与平台相关, MCU上通常为32bit
16 -- 虽然可以两两组成, 但实际情况只有2种,当前:
18 -- local bittype = "64bit_size32"
19 local bittype = "32bit"
20 -- local bittype = "source"
23 local typename = bittype
24 if bittype == "32bit" then
25 typename = ""
26 else
27 typename = "_" .. bittype
28 end
30 local function lsdir(path, files, shortname)
31 local cmd = "dir /b " .. (shortname and " " or " /s ") .. path
32 log.info("cmd", cmd)
33 local exe = io.popen(cmd)
34 if exe then
35 for line in exe:lines() do
36 if string.endsWith(line, ".lua") then
37 log.info("found", line)
38 table.insert(files, line)
39 end
40 end
41 exe:close()
42 end
43 end
46 local function oscall(cmd, quite, cwd)
47 if cwd and Base_CWD then
48 lfs.chdir(cwd)
49 end
50 if tool_debug then
51 log.info("cmd", cmd)
52 end
53 local exe = io.popen(cmd)
54 if exe then
55 for line in exe:lines() do
56 if not quite then
57 log.info("cmd", line)
58 end
59 end
60 exe:close()
61 end
62 if cwd and Base_CWD then
63 lfs.chdir(Base_CWD)
64 end
65 end
67 function TLD(buff, T, D)
68 buff:pack("bb", T, D:len())
69 buff:write(D)
70 end
72 local files = {}
73 lsdir("corelib", files, true)
74 oscall("mkdir tmp")
76 local path = "..\\luat\\vfs\\luat_inline_libs".. typename .. ".c"
77 local f = io.open(path, "wb")
79 if not f then
80 log.info("can't write", path)
81 os.exit(-1)
82 end
84 f:write([[#include "luat_base.h"]])
85 f:write("\r\n")
86 f:write([[#include "luat_fs.h"]])
87 f:write("\r\n")
88 f:write([[#include "luat_luadb.h"]])
89 f:write("\r\n\r\n")
92 kvs = {}
93 for _, value in ipairs(files) do
94 local data = nil
95 if bittype == "source" then
96 data = io.readFile("corelib\\" .. value)
97 else
98 local lf = loadfile("corelib\\" .. value)
99 data = string.dump(lf, true)
101 -- local cmd =
102 -- io.popen("luac_" .. bittype .. ".exe -s -o tmp.luac " .. "core\\" .. value):read("*a")
103 -- local data = io.readFile("tmp.luac")
104 local buff = zbuff.create(256*1024)
105 -- local data = io.readFile("tmp\\" .. value .. "c")
106 buff:write(data)
107 f:write("//------- " .. value .. "\r\n")
109 local k = "luat_inline2_" .. value:sub(1, value:len() - 4) .. typename
110 print(value, #data, k)
111 table.insert(kvs, {size=#data,ptr=k, name=value})
113 f:write("const char ".. k .."[] = {\r\n")
114 local index = 0
115 local max = #data
116 while index < max do
117 if index % 8 == 0 then
118 f:write("\r\n")
120 f:write(string.format("0x%02X, ", buff[index]))
121 index = index + 1
123 f:write("};\r\n\r\n")
126 f:write("const luadb_file_t luat_inline2_libs".. typename .. "[] = {\r\n")
127 for _, value in ipairs(kvs) do
128 f:write(" {.name=\"" .. value.name .. "\",.size=" .. tostring(value.size) .. ", .ptr=" .. value.ptr .. "},\r\n")
130 f:write(" {.name=\"\",.size=0,.ptr=NULL}\r\n")
131 f:write("};\r\n\r\n")
132 f:close()
134 log.info("all done")
135 os.exit(0)