summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2024-05-11 21:08:01 +0800
committerruki <[email protected]>2024-05-11 21:08:01 +0800
commite2eee64979c35ff8ad3efabc1f51bc21432ea833 (patch)
tree0f4b6ccd970991d538d04361a071759862d08056
parenteb1e30aeffb3b8cce42f591da449c9f2ebfb90ad (diff)
improve to replace program
-rw-r--r--xmake/modules/core/tools/gcc_ar.lua17
1 files changed, 15 insertions, 2 deletions
diff --git a/xmake/modules/core/tools/gcc_ar.lua b/xmake/modules/core/tools/gcc_ar.lua
index d7731a115..b2131d9e8 100644
--- a/xmake/modules/core/tools/gcc_ar.lua
+++ b/xmake/modules/core/tools/gcc_ar.lua
@@ -21,11 +21,24 @@
inherit("ar")
import("lib.detect.find_file")
+-- replace gcc-ar
+function _replace_gcc_ar(program, name)
+ local dir = path.directory(program)
+ local filename = path.filename(program)
+ filename = filename:gsub("gcc%-ar", name)
+ if dir and dir ~= "." then
+ program = path.join(dir, filename)
+ else
+ program = filename
+ end
+ return program
+end
+
-- get liblto_plugin.so path for gcc
function _get_gcc_liblto_plugin_path(self, program)
local plugin_path = _g.LTO_PLUGIN_PATH
if plugin_path == nil then
- local gcc = program:gsub("gcc%-ar", "gcc")
+ local gcc = _replace_gcc_ar(program, "gcc")
local outdata = try { function() return os.iorunv(gcc, {"-print-prog-name=lto-wrapper"}) end }
if outdata then
local lto_plugindir = path.directory(outdata:trim())
@@ -67,7 +80,7 @@ function link(self, objectfiles, targetkind, targetfile, flags, opt)
if plugin_path then
argv = winos.cmdargv(table.join({"--plugin", plugin_path}, rawargv), {escape = true})
end
- program = program:gsub("gcc%-ar", "ar")
+ program = _replace_gcc_ar(program, "ar")
end
-- link it