aboutsummaryrefslogtreecommitdiffstats
path: root/Library/Homebrew/keg_fix_install_names.rb
diff options
context:
space:
mode:
authorElliot Saba2013-10-31 01:08:57 -0700
committerJack Nagel2013-11-13 18:49:16 -0600
commit9458df0a605b7793c7430d95d54893f7a935722f (patch)
tree29e8e2cf669df2ebed7873496e2be9a4e5feb8db /Library/Homebrew/keg_fix_install_names.rb
parent4b0ddec26aaddaa4fe68b41168e4b231c4b66e1f (diff)
downloadhomebrew-9458df0a605b7793c7430d95d54893f7a935722f.tar.bz2
Add support for relocating pkgconfig files for bottles
* Finds pkg-config files such as "lib/pkgconfig/libfoo.pc" and "bin/libfoo-config" * Does inreplace on paths in such files to allow for better bottle relocation ability Closes #23825. Signed-off-by: Jack Nagel <jacknagel@gmail.com>
Diffstat (limited to 'Library/Homebrew/keg_fix_install_names.rb')
-rw-r--r--Library/Homebrew/keg_fix_install_names.rb42
1 files changed, 42 insertions, 0 deletions
diff --git a/Library/Homebrew/keg_fix_install_names.rb b/Library/Homebrew/keg_fix_install_names.rb
index 9210e70e3..bff97842c 100644
--- a/Library/Homebrew/keg_fix_install_names.rb
+++ b/Library/Homebrew/keg_fix_install_names.rb
@@ -39,6 +39,28 @@ class Keg
end
end
end
+
+ # Search for pkgconfig .pc files and relocate references to the cellar
+ old_cellar = HOMEBREW_CELLAR if old_cellar == :any
+ old_prefix = HOMEBREW_PREFIX if old_prefix == :any
+
+ old_cellar = Regexp.escape(old_cellar)
+ old_prefix = Regexp.escape(old_prefix)
+
+ pkgconfig_files.each do |pcfile|
+ pcfile.ensure_writable do
+ pcfile.open('rb') do |f|
+ s = f.read
+ # These regexes match lines of the form: prefix=/usr/local/Cellar/foo/1.2.3/lib
+ # and (assuming new_cellar is "/tmp") transform them into: prefix="/tmp/foo/1.2.3/lib"
+ # If the original line did not have quotes, we add them in automatically
+ s.gsub!(%r[([\S]+)="?#{old_cellar}(.*?)"?$], "\\1=\"#{new_cellar}\\2\"")
+ s.gsub!(%r[([\S]+)="?#{old_prefix}(.*?)"?$], "\\1=\"#{new_prefix}\\2\"")
+ f.reopen(pcfile, 'wb')
+ f.write(s)
+ end
+ end
+ end
end
# Detects the C++ dynamic libraries in place, scanning the dynamic links
@@ -143,4 +165,24 @@ class Keg
mach_o_files
end
+
+ def pkgconfig_files
+ pkgconfig_files = []
+
+ # find .pc files, which are stored in lib/pkgconfig
+ pc_dir = self/'lib/pkgconfig'
+ if pc_dir.directory?
+ pc_dir.find do |pn|
+ next if pn.symlink? or pn.directory? or pn.extname.to_s != '.pc'
+ pkgconfig_files << pn
+ end
+ end
+
+ # find name-config scripts, which can be all over the keg
+ Pathname.new(self).find do |pn|
+ next if pn.symlink? or pn.directory?
+ pkgconfig_files << pn if pn.text_executable? and pn.basename.to_s.end_with? '-config'
+ end
+ pkgconfig_files
+ end
end