diff options
| author | ruki <[email protected]> | 2024-07-16 23:55:27 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2024-07-16 23:55:27 +0800 |
| commit | 4cd523c8196f631cadda84f4a06747758e3e8fe9 (patch) | |
| tree | 2738e834f0de407f6681e3bc7e8d4983e185a38a /xmake/modules/utils/binary/rpath.lua | |
| parent | 702a14f8db2bc2c215952398384192e599e71cf4 (diff) | |
remove rpath on macosx
Diffstat (limited to 'xmake/modules/utils/binary/rpath.lua')
| -rw-r--r-- | xmake/modules/utils/binary/rpath.lua | 47 |
1 files changed, 41 insertions, 6 deletions
diff --git a/xmake/modules/utils/binary/rpath.lua b/xmake/modules/utils/binary/rpath.lua index 2730b30bf..55abad900 100644 --- a/xmake/modules/utils/binary/rpath.lua +++ b/xmake/modules/utils/binary/rpath.lua @@ -151,20 +151,55 @@ function _get_rpath_list_by_otool(binaryfile, opt) return list 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() + 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", {"-delete_rpath", rpath, binaryfile}) + return true + end } + return ok +end + -- get rpath list function list(binaryfile, opt) opt = opt or {} - local dumpers = { + local ops = { _get_rpath_list_by_objdump, _get_rpath_list_by_readelf } if is_host("macosx") then - table.insert(dumpers, 1, _get_rpath_list_by_otool) + table.insert(ops, 1, _get_rpath_list_by_otool) end - for _, dump in ipairs(dumpers) do - local list = dump(binaryfile, opt) - if list then - return list + for _, op in ipairs(ops) do + local result = op(binaryfile, opt) + if result then + return result end end end + +-- remove rpath +function remove(binaryfile, rpath, opt) + opt = opt or {} + local ops = {} + if is_host("macosx") then + table.insert(ops, 1, _remove_rpath_by_install_name_tool) + end + for _, op in ipairs(ops) do + if op(binaryfile, rpath, opt) then + break + end + end +end + +-- remove all rpath +function remove_all(binaryfile, opt) + for _, rpath in ipairs(list(binaryfile, opt)) do + remove(binaryfile, rpath, opt) + end +end |
