forked from gustafsson/freq
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sandboxsonicawe.rb
39 lines (32 loc) · 1.5 KB
/
sandboxsonicawe.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
path = "sonicawe"
$command_line_width = 80
bindir="sandbox/Contents/MacOS"
system("cp #{path} #{bindir}/#{path}")
Dir.chdir(bindir)
libraries = `ls ../Frameworks`.split
# Setting install names
#puts " Fixing install names ".center($command_line_width, "=")
#puts "in binary: #{File.basename(path)}"
libraries.each do |library|
libname = "#{File.basename(library, ".*")}"
libpath = "../Frameworks"
newlibpath = "@executable_path/../Frameworks"
libfile = "#{libpath}/#{library}"
libtargetid = `otool -DX #{libfile}`.strip
targetid = `otool -L #{path} | grep "#{libname}\\\\." | sed s/\\(.*\\)//`.strip
newtargetid = "#{newlibpath}/#{library}"
if (libtargetid != newtargetid)
puts "updating library #{libtargetid} -> #{newtargetid}"
unless system("install_name_tool -id #{newtargetid} #{libfile}")
puts "Error: Could not set id #{newtargetid} in binary #{libfile}"
exit(1)
end
end
binary_uses_this_lib = !`otool -L #{path} | grep "#{targetid}"`.empty?
next unless binary_uses_this_lib && !targetid.empty? && targetid!=newtargetid
puts "Updating install name in #{path} for library #{library}"
unless system("install_name_tool -change #{targetid} #{newtargetid} #{path}")
puts "Error: Could not change install name for #{libpath}/#{libname} from #{targetid} to #{newtargetid} in binary #{path}"
exit(1)
end
end