From e2eee64979c35ff8ad3efabc1f51bc21432ea833 Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 11 May 2024 21:08:01 +0800 Subject: improve to replace program --- xmake/modules/core/tools/gcc_ar.lua | 17 +++++++++++++++-- 1 file 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 -- cgit v1.3.1