From 008d6a92e171d9ef1d8a62fca1e4900ed5faa48f Mon Sep 17 00:00:00 2001 From: ruki Date: Sat, 18 May 2024 22:15:38 +0800 Subject: improve rpathdirs #5109 --- xmake/modules/core/tools/gcc.lua | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua index f51a088bf..e1d77f1a4 100644 --- a/xmake/modules/core/tools/gcc.lua +++ b/xmake/modules/core/tools/gcc.lua @@ -385,13 +385,24 @@ function nf_linkdir(self, dir) end -- make the rpathdir flag -function nf_rpathdir(self, dir) +function nf_rpathdir(self, dir, opt) + opt = opt or {} dir = path.translate(dir) if self:has_flags("-Wl,-rpath=" .. dir, "ldflags") then local flags = {"-Wl,-rpath=" .. (dir:gsub("@[%w_]+", function (name) local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"} return maps[name] end))} + -- add_rpathdirs("...", {runpath = false}) + -- https://github.com/xmake-io/xmake/issues/5109 + local extra = opt.extra + if extra then + if extra.runpath == false and self:has_flags("-Wl,-rpath=" .. dir .. ",--disable-new-dtags", "ldflags") then + flags[1] = flags[1] .. ",--disable-new-dtags" + elseif extra.runpath == true and self:has_flags("-Wl,-rpath=" .. dir .. ",--enable-new-dtags", "ldflags") then + flags[1] = flags[1] .. ",--enable-new-dtags" + end + end if self:is_plat("bsd") then -- FreeBSD ld must have "-zorigin" with "-rpath". Otherwise, $ORIGIN is not translated and it is literal. table.insert(flags, 1, "-Wl,-zorigin") -- cgit v1.3.1