diff --git a/Library/Homebrew/keg_fix_install_names.rb b/Library/Homebrew/keg_fix_install_names.rb index 4fc4a7f499..99726166c7 100644 --- a/Library/Homebrew/keg_fix_install_names.rb +++ b/Library/Homebrew/keg_fix_install_names.rb @@ -40,13 +40,13 @@ class Keg end end - pkgconfig_files.each do |pcfile| - pcfile.ensure_writable do - pcfile.open('rb') do |f| + (pkgconfig_files | libtool_files).each do |file| + file.ensure_writable do + file.open('rb') do |f| s = f.read - replace_pkgconfig_file_path(s, old_cellar, new_cellar) - replace_pkgconfig_file_path(s, old_prefix, new_prefix) - f.reopen(pcfile, 'wb') + s.gsub!(old_cellar, new_cellar) + s.gsub!(old_prefix, new_prefix) + f.reopen(file, 'wb') f.write(s) end end @@ -61,17 +61,6 @@ class Keg install_name_tool("-change", old, new, file) end - # Given old == "/usr/local/Cellar" and new == "/opt/homebrew/Cellar", - # then update lines of the form - # some_variable=/usr/local/Cellar/foo/1.0/lib - # to - # some_variable="/opt/homebrew/Cellar/foo/1.0/lib" - # and add quotes to protect against paths containing spaces. - def replace_pkgconfig_file_path(s, old, new) - return if old == new - s.gsub!(%r[([\S]+)="?#{Regexp.escape(old)}(.*?)"?$], "\\1=\"#{new}\\2\"") - end - # Detects the C++ dynamic libraries in place, scanning the dynamic links # of the files within the keg. This searches only libs contained within # lib/, and ignores binaries and other mach-o objects @@ -198,4 +187,16 @@ class Keg end pkgconfig_files end + + def libtool_files + libtool_files = [] + + # find .la files, which are stored in lib/ + la_dir = self/'lib' + la_dir.find do |pn| + next if pn.symlink? or pn.directory? or pn.extname.to_s != '.la' + libtool_files << pn + end + libtool_files + end end