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 8e40183 commit 6a3c4a3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions brew-pkg.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ def elf_file?(file_path)
return stdout.strip == 'binary'
end

def patchelf(root_dir, prefix_path, binary)
def patchelf(root_dir, prefix_path, binary, format='@executable_path')
full_prefix_path = File.join(root_dir, prefix_path)

# Get the full binary path and check if it's a valid ELF
Expand Down Expand Up @@ -46,9 +46,10 @@ def patchelf(root_dir, prefix_path, binary)
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))
new_lib = File.join('@executable_path', 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)

# Debug information
Expand All @@ -58,7 +59,7 @@ def patchelf(root_dir, prefix_path, binary)
ohai "patchelf(#{root_dir}, #{prefix_path}, #{lib.delete_prefix(prefix_path)})"

# Recursively iterate through libraries
patchelf(root_dir, prefix_path, lib.delete_prefix(prefix_path))
patchelf(root_dir, prefix_path, lib.delete_prefix(prefix_path), '@rpath')
else
opoo "File 'File.realpath(File.join(#{root_dir}, #{lib})' not found"
end
Expand Down Expand Up @@ -209,7 +210,7 @@ def pkg
safe_system "mkdir", "-p", "#{staging_root}/Cellar/#{formula.name}/"
safe_system "rsync", "-a", "#{HOMEBREW_CELLAR}/#{formula.name}/#{dep_version}", "#{staging_root}/Cellar/#{formula.name}/"
safe_system "mkdir", "-p", "#{staging_root}/opt"
safe_system "ln", "-s", "../Cellar/#{formula.name}/#{dep_version}", "#{staging_root}/opt/#{formula.name}"
safe_system "ln", "-s", "#{staging_root}/Cellar/#{formula.name}/#{dep_version}", "#{staging_root}/opt/#{formula.name}"
end
end

Expand Down

0 comments on commit 6a3c4a3

Please sign in to comment.