From 409ef378247dff60f9c4fd1f25a260b66c6a7322 Mon Sep 17 00:00:00 2001 From: Chan Lee Date: Mon, 30 Dec 2024 17:03:56 +0800 Subject: [PATCH] openssl: add LLVM resource compiler support for MinGW --- packages/o/openssl/makefile/patch.lua | 35 +++++++++++++++++++++++++++ packages/o/openssl/xmake.lua | 10 +++++++- 2 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 packages/o/openssl/makefile/patch.lua diff --git a/packages/o/openssl/makefile/patch.lua b/packages/o/openssl/makefile/patch.lua new file mode 100644 index 00000000000..80974e9a9f0 --- /dev/null +++ b/packages/o/openssl/makefile/patch.lua @@ -0,0 +1,35 @@ +function _patch_for_llvm_rc(package, opt) + if package:is_plat("mingw") and package:has_tool("mrc", "llvm_rc", "llvm-rc", "rc") then + local cc = package:build_getenv("cc") + local cflags = opt.buildenvs.CFLAGS + local tmpfile = path.unix(os.tmpfile() .. ".c") + io.writefile(tmpfile, "int main(void) { return 0; }\n") + local compile_out, compile_err = try {function() return os.iorun(format("%s -v %s %s", cc, cflags, tmpfile)) end} + local include_dirs = {} + local in_include_section = false + for _, verbose_command in ipairs({compile_out, compile_err}) do + if verbose_command then + for line in verbose_command:gmatch("[^\r\n]+") do + if line:find("#include.*search") then + in_include_section = true + elseif line:find("End.*search") then + in_include_section = false + elseif in_include_section and not line:find("#include.*search") then + table.insert(include_dirs, line:match("^%s*(.-)%s*$")) + end + end + end + end + local include_directive = "" + for _, include_dir in ipairs(include_dirs) do + include_directive = include_directive .. format([[ -I "%s"]], include_dir) + end + -- $(RC) $(RCFLAGS) -o $@ libcrypto.rc => $(RC) -I inc_dir -I inc_dir -FO $@ libcrypto.rc + io.gsub("Makefile", [[%$%(RC%).-%$@%s+(%S+)]], format("$(RC) %s -FO $@ ", include_directive).."%1") + io.gsub("Makefile", "(%S+).res.o", "%1.res") + end +end + +function main(package, opt) + _patch_for_llvm_rc(package, opt) +end diff --git a/packages/o/openssl/xmake.lua b/packages/o/openssl/xmake.lua index 2f3772813d4..777cdbcc0ec 100644 --- a/packages/o/openssl/xmake.lua +++ b/packages/o/openssl/xmake.lua @@ -184,7 +184,14 @@ package("openssl") table.insert(configs, "--debug") end - local buildenvs = import("package.tools.autoconf").buildenvs(package) + local ldflags = {} + if package:is_plat("mingw") and package:has_tool("mrc", "llvm_rc", "llvm-rc", "rc") then + -- llvm-rc should be used with lld linker + if package:has_tool("cc", "clang") then + table.insert(ldflags, "-fuse-ld=lld") + end + end + local buildenvs = import("package.tools.autoconf").buildenvs(package, {ldflags = ldflags}) if is_host("windows") and package:is_plat("android") then buildenvs.CFLAGS = buildenvs.CFLAGS:gsub("\\", "/") buildenvs.CXXFLAGS = buildenvs.CXXFLAGS:gsub("\\", "/") @@ -213,6 +220,7 @@ package("openssl") os.vrunv("./config", configs, {shell = true, envs = buildenvs}) end + import("makefile.patch")(package, {buildenvs = buildenvs}) import("package.tools.make").build(package) import("package.tools.make").make(package, {"install_sw"}) if package:config("shared") then