patch.lua 1.7 KB

123456789101112131415161718192021222324252627282930313233343536
  1. function _patch_for_llvm_rc(package, opt)
  2. if package:is_plat("mingw") and package:has_tool("mrc", "llvm_rc", "llvm-rc", "rc") then
  3. local cc = package:build_getenv("cc")
  4. local cflags = opt.buildenvs.CFLAGS
  5. local tmpfile = path.unix(os.tmpfile() .. ".c")
  6. io.writefile(tmpfile, "int main(void) { return 0; }\n")
  7. local compile_out, compile_err = try {function() return os.iorun(format("%s -v %s %s", cc, cflags, tmpfile)) end}
  8. os.tryrm(tmpfile)
  9. local include_dirs = {}
  10. local in_include_section = false
  11. for _, verbose_command in ipairs({compile_out, compile_err}) do
  12. if verbose_command then
  13. for line in verbose_command:gmatch("[^\r\n]+") do
  14. if line:find("#include.*search") then
  15. in_include_section = true
  16. elseif line:find("End.*search") then
  17. in_include_section = false
  18. elseif in_include_section and not line:find("#include.*search") then
  19. table.insert(include_dirs, line:match("^%s*(.-)%s*$"))
  20. end
  21. end
  22. end
  23. end
  24. local include_directive = ""
  25. for _, include_dir in ipairs(include_dirs) do
  26. include_directive = include_directive .. format([[ -I "%s"]], include_dir)
  27. end
  28. -- $(RC) $(RCFLAGS) -o $@ libcrypto.rc => $(RC) -I inc_dir -I inc_dir -FO $@ libcrypto.rc
  29. io.gsub("Makefile", [[%$%(RC%).-%$@%s+(%S+)]], format("$(RC) %s -FO $@ ", include_directive).."%1")
  30. io.gsub("Makefile", "(%S+).res.o", "%1.res")
  31. end
  32. end
  33. function main(package, opt)
  34. try {function() return _patch_for_llvm_rc(package, opt) end}
  35. end