summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorruki <[email protected]>2017-08-18 22:19:25 +0800
committerruki <[email protected]>2017-08-18 22:19:25 +0800
commitc049bcb7fc2e2e032ebc69897e5170c214bf8df2 (patch)
treeaa45fac7634774f4be0916ea265e51c9cff37708
parentb068f28c48cb6cd7246dcfeaff648327decb3101 (diff)
improve rpath
-rw-r--r--xmake/core/tool/builder.lua4
-rw-r--r--xmake/modules/core/tools/gcc.lua14
2 files changed, 11 insertions, 7 deletions
diff --git a/xmake/core/tool/builder.lua b/xmake/core/tool/builder.lua
index 7d02930f0..1a4450a4c 100644
--- a/xmake/core/tool/builder.lua
+++ b/xmake/core/tool/builder.lua
@@ -159,8 +159,8 @@ function builder:_inherit_from_targetdeps(results, target, flagname)
elseif flagname == "rpathdirs" and targetkind == "binary" then
- -- add dependent rpathdirs (need absolute path)
- table.insert(results, path.directory(path.absolute(dep:targetfile(), os.projectdir())))
+ -- add dependent rpathdirs
+ table.insert(results, "@loader_path")
elseif flagname == "includedirs" then
diff --git a/xmake/modules/core/tools/gcc.lua b/xmake/modules/core/tools/gcc.lua
index ddfc264cc..1139bed0b 100644
--- a/xmake/modules/core/tools/gcc.lua
+++ b/xmake/modules/core/tools/gcc.lua
@@ -234,12 +234,16 @@ end
-- make the rpathdir flag
function nf_rpathdir(self, dir)
- local flag_elf = "-Wl,-rpath=" .. dir
- local flag_macho = "-Xlinker -rpath -Xlinker " .. dir
if self:has_flags(flag_elf) then
- return flag_elf
- elseif self:has_flags(flag_macho) then
- return flag_macho
+ return "-Wl,-rpath=" .. (dir:gsub("@[%w_]+", function (name)
+ local maps = {["@loader_path"] = "$ORIGIN", ["@executable_path"] = "$ORIGIN"}
+ return maps[name]
+ end))
+ elseif self:has_flags("-Xlinker -rpath -Xlinker " .. dir) then
+ return "-Xlinker -rpath -Xlinker " .. (dir:gsub("%$[%w_]+", function (name)
+ local maps = {["$ORIGIN"] = "@loader_path"}
+ return maps[name]
+ end))
end
end