From c19eb9cdad616568851a9e9f9e31832938cae8ed Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 30 Sep 2023 15:12:57 +0800 Subject: improve linkgroups --- tests/projects/c++/linkorders/xmake.lua | 2 +- xmake/modules/core/tools/gcc.lua | 18 +++++++++++------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/tests/projects/c++/linkorders/xmake.lua b/tests/projects/c++/linkorders/xmake.lua index 8a5f1d18c..755e75f51 100644 --- a/tests/projects/c++/linkorders/xmake.lua +++ b/tests/projects/c++/linkorders/xmake.lua @@ -24,6 +24,6 @@ target("demo") end add_linkorders("framework::Foundation", "png16", "foo") add_linkorders("dl", "linkgroup::syslib") - add_linkgroups("m", "pthread", {name = "syslib"}) + add_linkgroups("m", "pthread", {name = "syslib", group = true}) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index 7cff1d48d..0c13552e9 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -306,20 +306,24 @@ end -- make the link group flag function nf_linkgroup(self, linkgroup, target) - local flags = {} + local linkflags = {} for _, lib in ipairs(linkgroup) do - table.insert(flags, nf_link(self, lib)) + table.insert(linkflags, nf_link(self, lib)) end + local flags = {} if not target:is_plat("macosx", "windows", "mingw") then + local group = target:extraconf("linkgroups", linkgroup, "group") + if group then + table.join2(flags, "-Wl,--start-group", linkflags, "-Wl,--end-group") + end local whole = target:extraconf("linkgroups", linkgroup, "whole") if whole then - table.insert(flags, 1, "-Wl,--whole-archive") - table.insert(flags, "-Wl,--no-whole-archive") - else - table.insert(flags, 1, "-Wl,--start-group") - table.insert(flags, "-Wl,--end-group") + table.join2(flags, "-Wl,--whole-archive", linkflags, "-Wl,--no-whole-archive") end end + if #flags == 0 then + flags = linkflags + end return flags end -- cgit v1.3.1