Skip to content

Commit

Permalink
openssl: add LLVM resource compiler support for MinGW
Browse files Browse the repository at this point in the history
  • Loading branch information
Doekin committed Dec 30, 2024
1 parent a7144ca commit 409ef37
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 1 deletion.
35 changes: 35 additions & 0 deletions packages/o/openssl/makefile/patch.lua
Original file line number Diff line number Diff line change
@@ -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
10 changes: 9 additions & 1 deletion packages/o/openssl/xmake.lua
Original file line number Diff line number Diff line change
Expand Up @@ -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("\\", "/")
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 409ef37

Please sign in to comment.