summaryrefslogtreecommitdiff
path: root/xmake/modules/core
diff options
context:
space:
mode:
authorArthur LAURENT <[email protected]>2024-03-07 12:00:04 +0100
committerArthur LAURENT <[email protected]>2024-03-07 12:01:23 +0100
commitb4c3a3eb56fe7a00a49706c37121d0125d84d09f (patch)
treeea5214d2d867079882f4720aa849b65e26f756c2 /xmake/modules/core
parenta6b26e0f93bfaa55ec6033501437df73efca1934 (diff)
improve rpath for clang linux
Diffstat (limited to 'xmake/modules/core')
-rw-r--r--xmake/modules/core/tools/clang.lua14
1 files changed, 12 insertions, 2 deletions
diff --git a/xmake/modules/core/tools/clang.lua b/xmake/modules/core/tools/clang.lua
index 78806fe13..39f90025b 100644
--- a/xmake/modules/core/tools/clang.lua
+++ b/xmake/modules/core/tools/clang.lua
@@ -293,9 +293,19 @@ function nf_runtime(self, runtime, opt)
-- add rpath to avoid the user need to set LD_LIBRARY_PATH by hand
local rpath_flags
if self:has_flags("-Wl,-rpath=" .. libdir, "ldflags") then
- rpath_flags = {"-Wl,-rpath=" .. libdir}
+ rpath_flags = {"-Wl,-rpath=" .. (libdir:gsub("@[%w_]+", function (name)
+ local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
+ return maps[name]
+ end))}
if triple_libdir then
- table.join2(rpath_flags, "-Wl,-rpath=" .. triple_libdir)
+ table.join2(rpath_flags, "-Wl,-rpath=" .. (triple_libdir:gsub("@[%w_]+", function (name)
+ local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
+ return maps[name]
+ 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(rpath_flags, 1, "-Wl,-zorigin")
end
elseif self:has_flags("-Xlinker -rpath -Xlinker " .. libdir, "ldflags") then
rpath_flags = {"-Xlinker", "-rpath", "-Xlinker", (libdir:gsub("%$ORIGIN", "@loader_path"))}