update_inline_sys.lua 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. local function lsdir(path, files, shortname)
  2. local exe = io.popen("dir /b " .. (shortname and " " or " /s ") .. path)
  3. if exe then
  4. for line in exe:lines() do
  5. table.insert(files, line)
  6. end
  7. exe:close()
  8. end
  9. end
  10. local function oscall(cmd, quite, cwd)
  11. if cwd and Base_CWD then
  12. lfs.chdir(cwd)
  13. end
  14. if tool_debug then
  15. log.info("cmd", cmd)
  16. end
  17. local exe = io.popen(cmd)
  18. if exe then
  19. for line in exe:lines() do
  20. if not quite then
  21. log.info("cmd", line)
  22. end
  23. end
  24. exe:close()
  25. end
  26. if cwd and Base_CWD then
  27. lfs.chdir(Base_CWD)
  28. end
  29. end
  30. function TLD(buff, T, D)
  31. buff:pack("bb", T, D:len())
  32. buff:write(D)
  33. end
  34. local files = {}
  35. lsdir("lib", files, true)
  36. oscall("mkdir tmp")
  37. local buff = zbuff.create(256*1024)
  38. -- local magic = string.char(0x5A, 0xA5, 0X5A, 0xA5)
  39. -- -- 先写入magic
  40. -- --buff:pack("bbbbbb", 0x01, 0x04, 0XA5, 0x5A, 0xA5, 0x5A)
  41. -- TLD(buff, 0x01, magic)
  42. -- -- 然后是版本号
  43. -- --buff:write(string.char(0x02, 0x02, 0x00, 0x02))
  44. -- TLD(buff, 0x02, string.char(0x00, 0x02))
  45. -- -- head长度
  46. -- buff:write(string.char(0x03, 0x04))
  47. -- buff:pack("I", 0x12)
  48. -- -- 文件数量
  49. -- buff:write(string.char(0x04, 0x02))
  50. -- buff:pack("H", #files)
  51. -- -- CRC值
  52. -- buff:write(string.char(0xFE, 0x02))
  53. -- buff:pack("H", 0xFFFF)
  54. for _, value in ipairs(files) do
  55. -- TLD(buff, 0x01, magic)
  56. -- TLD(buff, 0x02, value .. "c")
  57. oscall("..\\air640w\\tools\\luac_536_32bits.exe -s -o tmp\\".. value .. "c lib\\" .. value)
  58. -- TLD(buff, 0x03, pack.pack("I", io.fileSize("tmp\\" .. value .. "c")))
  59. -- TLD(buff, 0xFE, string.char(0xFF, 0xFF))
  60. buff:write(io.readFile("tmp\\" .. value .. "c"))
  61. end
  62. local data = buff:toStr(0, buff:seek(0, zbuff.SEEK_CUR))
  63. log.info("target", #data)
  64. local f = io.open("..\\..\\luat\\vfs\\luat_inline_sys.c", "wb")
  65. if f then
  66. f:write([[#include "luat_base.h"]])
  67. f:write("\n\nconst uint32_t luat_inline_sys_size = " .. tostring(#data) ..";\n")
  68. f:write("const char luat_inline_sys[] = {\n")
  69. local index = 0
  70. local max = #data
  71. while index < max do
  72. if index % 8 == 0 then
  73. f:write("\n")
  74. end
  75. f:write(string.format("0x%02X, ", buff[index]))
  76. index = index + 1
  77. end
  78. f:write("};\n")
  79. f:close()
  80. end
  81. os.exit(0)