Skip to content

Commit

Permalink
Yeet.
Browse files Browse the repository at this point in the history
  • Loading branch information
viferga committed Sep 3, 2024
1 parent 9d5b2da commit e481f95
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions brew-pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,12 @@ def patchelf(root_dir, prefix_path, binary, format='@executable_path')
opoo "The link '#{File.join(root_dir, lib)}' refers to itself: '#{binary_path}'"

# Obtain the relative path from the library
relative_path = Pathname.new(lib).relative_path_from(Pathname.new(File.dirname(File.join(prefix_path, binary))))
relative_path = Pathname.new(lib).relative_path_from(Pathname.new(File.join(prefix_path, 'bin')))
new_lib = File.join('@executable_path', relative_path)

# Patch the library path name
ohai "install_name_tool -id #{new_lib} #{binary_path}"
system("install_name_tool", "-id", new_lib, binary_path)
else
# Recursively iterate through libraries
patchelf(root_dir, prefix_path, lib.delete_prefix(prefix_path), '@loader_path')
Expand All @@ -60,13 +65,12 @@ def patchelf(root_dir, prefix_path, binary, format='@executable_path')
lib_relative_path = lib_path.delete_prefix(full_prefix_path)
binary_relative_path = File.dirname(binary_path).delete_prefix(full_prefix_path)
relative_path = Pathname.new(lib_relative_path).relative_path_from(Pathname.new(binary_relative_path))
end
new_lib = File.join(format, relative_path)

new_lib = File.join(format, relative_path)

# Patch the library path relative to the binary path
ohai "install_name_tool -change #{lib} #{new_lib} #{binary_path}"
system("install_name_tool", "-change", lib, new_lib, binary_path)
# Patch the library path relative to the binary path
ohai "install_name_tool -change #{lib} #{new_lib} #{binary_path}"
system("install_name_tool", "-change", lib, new_lib, binary_path)
end

# Debug information
stdout, status = Open3.capture2("otool -L #{binary_path}")
Expand Down

0 comments on commit e481f95

Please sign in to comment.