Created
July 17, 2015 05:46
-
-
Save suzumura-ss/01d6e0f42234d3110ea1 to your computer and use it in GitHub Desktop.
shared libraryの参照パスを @executable_path/ 直下に再帰的に更新
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class ModifyPath | |
def initialize(exe) | |
@exe = exe | |
@dylibs = `otool -L #{exe}`.each_line.map{|line| | |
$1 if line=~%r{\t([^/@].+\.dylib) .*$} | |
}.compact.delete_if{|dy| | |
File.basename(dy)==File.basename(exe) or !File.exist?(File.basename(exe)) | |
} | |
end | |
def modify! | |
unless @dylibs.empty? | |
opt = @dylibs.map{|dy| "-change #{dy} @executable_path/#{File.basename(dy)}"}.join(' ') | |
system "install_name_tool #{opt} #{@exe} && otool -L #{@exe}" | |
end | |
end | |
def modify_recursive!(basedir = File.dirname(@exe)) | |
modify! | |
@dylibs.each{|dy| | |
path = File.join(basedir, File.basename(dy)) | |
ModifyPath.new(path).modify_recursive!(basedir) | |
} | |
end | |
end | |
# カレントディレクトリに実行ファイルと参照されるdylibを置いて | |
# ./dylib_patch.rb <実行ファイル又はdylib> | |
ModifyPath.new(ARGV[0]).modify_recursive! |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment