summaryrefslogtreecommitdiff
path: root/xmake/modules/utils/binary/rpath.lua
diff options
context:
space:
mode:
authorruki <[email protected]>2024-07-16 23:55:53 +0800
committerruki <[email protected]>2024-07-16 23:55:53 +0800
commit142e3da88a41ef9519e2482b9c198d8bfeeaec6e (patch)
tree9099ffb3bda80b45ce381c627d95783a6a7e0e5f /xmake/modules/utils/binary/rpath.lua
parent4cd523c8196f631cadda84f4a06747758e3e8fe9 (diff)
insert rpath for macho
Diffstat (limited to 'xmake/modules/utils/binary/rpath.lua')
-rw-r--r--xmake/modules/utils/binary/rpath.lua28
1 files changed, 28 insertions, 0 deletions
diff --git a/xmake/modules/utils/binary/rpath.lua b/xmake/modules/utils/binary/rpath.lua
index 55abad900..510b5efb5 100644
--- a/xmake/modules/utils/binary/rpath.lua
+++ b/xmake/modules/utils/binary/rpath.lua
@@ -151,6 +151,20 @@ function _get_rpath_list_by_otool(binaryfile, opt)
return list
end
+-- install_name_tool -add_rpath <rpath> binaryfile
+function _insert_rpath_by_install_name_tool(binaryfile, rpath, opt)
+ local plat = opt.plat or os.host()
+ local arch = opt.arch or os.arch()
+ if plat ~= "macosx" and plat ~= "iphoneos" and plat ~= "appletvos" and plat ~= "watchos" then
+ return false
+ end
+ local ok = try { function ()
+ os.vrunv("install_name_tool", {"-add_rpath", rpath, binaryfile})
+ return true
+ end }
+ return ok
+end
+
-- install_name_tool -delete_rpath <rpath> binaryfile
function _remove_rpath_by_install_name_tool(binaryfile, rpath, opt)
local plat = opt.plat or os.host()
@@ -183,6 +197,20 @@ function list(binaryfile, opt)
end
end
+-- insert rpath
+function insert(binaryfile, rpath, opt)
+ opt = opt or {}
+ local ops = {}
+ if is_host("macosx") then
+ table.insert(ops, 1, _insert_rpath_by_install_name_tool)
+ end
+ for _, op in ipairs(ops) do
+ if op(binaryfile, rpath, opt) then
+ break
+ end
+ end
+end
+
-- remove rpath
function remove(binaryfile, rpath, opt)
opt = opt or {}