summaryrefslogtreecommitdiff
path: root/xmake/modules/core/tools/gcc.lua
diff options
context:
space:
mode:
authorKkemChen <[email protected]>2024-09-17 10:27:47 +0800
committerKkemChen <[email protected]>2024-09-17 10:27:47 +0800
commit8704d6bc2902e9d41b3918bb06b3d9e4da411ec9 (patch)
tree8e5a6c7475b5f546d731eb6ac30b9f3d5cd3e85a /xmake/modules/core/tools/gcc.lua
parent971318d9d33ab5190745cb4a86b4c75e916e72e4 (diff)
add support for "as_needed"
Diffstat (limited to 'xmake/modules/core/tools/gcc.lua')
-rw-r--r--xmake/modules/core/tools/gcc.lua30
1 files changed, 20 insertions, 10 deletions
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index 569f13756..9376f3bc6 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -358,20 +358,30 @@ function nf_linkgroup(self, linkgroup, opt)
local flags = {}
local extra = opt.extra
if extra and not self:is_plat("macosx", "windows", "mingw") then
- local group = extra.group
+ local as_needed = extra.as_needed
local whole = extra.whole
- if group and whole then
- -- https://github.com/xmake-io/xmake/issues/4308
- table.join2(flags, "-Wl,--whole-archive", "-Wl,--start-group", linkflags, "-Wl,--end-group", "-Wl,--no-whole-archive")
- elseif group then
- table.join2(flags, "-Wl,--start-group", linkflags, "-Wl,--end-group")
- elseif whole then
- table.join2(flags, "-Wl,--whole-archive", linkflags, "-Wl,--no-whole-archive")
- end
+ local group = extra.group
local static = extra.static
+ local prefix_flags = {}
+ local suffix_flags = {}
if static then
- table.join2(flags, "-Wl,-Bstatic", linkflags, "-Wl,-Bdynamic")
+ table.insert(prefix_flags, "-Wl,-Bstatic")
+ table.insert(suffix_flags, 1, "-Wl,-Bdynamic")
+ end
+ if as_needed then
+ -- https://github.com/xmake-io/xmake/issues/5621
+ table.insert(prefix_flags, "-Wl,--as-needed")
+ table.insert(suffix_flags, 1, "-Wl,--no-as-needed")
+ end
+ if whole then
+ table.insert(prefix_flags, "-Wl,--whole-archive")
+ table.insert(suffix_flags, 1, "-Wl,--no-whole-archive")
+ end
+ if group then
+ table.insert(prefix_flags, "-Wl,--start-group")
+ table.insert(suffix_flags, 1, "-Wl,--end-group")
end
+ tabel.join2(flags, prefix_flags, linkflags, suffix_flags)
end
if #flags == 0 then
flags = linkflags